mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +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);
|
return registry.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearAll() {
|
||||||
|
registry.clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,8 @@ public class ChatReloadCommand extends BaseCommand {
|
|||||||
public void baseCommand(CommandSender sender) {
|
public void baseCommand(CommandSender sender) {
|
||||||
carbonChat.reloadConfig();
|
carbonChat.reloadConfig();
|
||||||
|
|
||||||
|
carbonChat.getChannelManager().reload();
|
||||||
|
|
||||||
Component message = carbonChat.getAdventureManager().processMessage(carbonChat.getConfig().getString("language.reloaded"),
|
Component message = carbonChat.getAdventureManager().processMessage(carbonChat.getConfig().getString("language.reloaded"),
|
||||||
"br", "\n");
|
"br", "\n");
|
||||||
|
|
||||||
|
|||||||
@@ -21,17 +21,7 @@ public class ChannelManager {
|
|||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
this.registry = new ChannelRegistry(carbonChat);
|
this.registry = new ChannelRegistry(carbonChat);
|
||||||
|
|
||||||
for (String key : carbonChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
|
reload();
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatChannel loadChannel(String key, ConfigurationSection section) {
|
public ChatChannel loadChannel(String key, ConfigurationSection section) {
|
||||||
@@ -89,4 +79,20 @@ public class ChannelManager {
|
|||||||
return channel;
|
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
|
@Nullable
|
||||||
T get(String key);
|
T get(String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all registered entries from the registry
|
||||||
|
*/
|
||||||
|
void clearAll();
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user