mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Add channel reload functionality via ChatReloadCommand
This commit is contained in:
1 parent
f5f77aab67
commit
4897ed68fd
4 files changed
+29
-11
No files matched your search
@@ -52,4 +52,9 @@ public class ChannelRegistry implements Registry<ChatChannel> {
|
||||
return registry.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAll() {
|
||||
registry.clear();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,8 @@ public class ChatReloadCommand extends BaseCommand {
|
||||
public void baseCommand(CommandSender sender) {
|
||||
carbonChat.reloadConfig();
|
||||
|
||||
carbonChat.getChannelManager().reload();
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(carbonChat.getConfig().getString("language.reloaded"),
|
||||
"br", "\n");
|
||||
|
||||
|
||||
@@ -21,17 +21,7 @@ public class ChannelManager {
|
||||
this.carbonChat = carbonChat;
|
||||
this.registry = new ChannelRegistry(carbonChat);
|
||||
|
||||
for (String key : carbonChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
|
||||
ConfigurationSection section = carbonChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key);
|
||||
|
||||
ChatChannel channel = loadChannel(key, section);
|
||||
|
||||
if (channel != null) {
|
||||
if (registerChannel(channel)) {
|
||||
carbonChat.getLogger().info("Registering channel: " + channel.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
reload();
|
||||
}
|
||||
|
||||
public ChatChannel loadChannel(String key, ConfigurationSection section) {
|
||||
@@ -89,4 +79,20 @@ public class ChannelManager {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
registry.clearAll();
|
||||
|
||||
for (String key : carbonChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
|
||||
ConfigurationSection section = carbonChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key);
|
||||
|
||||
ChatChannel channel = loadChannel(key, section);
|
||||
|
||||
if (channel != null) {
|
||||
if (registerChannel(channel)) {
|
||||
carbonChat.getLogger().info("Registering channel: " + channel.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,4 +30,9 @@ public interface Registry<T> {
|
||||
@Nullable
|
||||
T get(String key);
|
||||
|
||||
/**
|
||||
* Clears all registered entries from the registry
|
||||
*/
|
||||
void clearAll();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user