Refactor config reload and server name handling.

Replaced inconsistent `ReloadConfig` usage with `reloadConfig` across the codebase for better naming consistency. Introduced `ServerName` utility to standardize server name retrieval and improve maintainability. Added logging enhancements for better debugging of muted users and blocked messages.
This commit is contained in:
2025-03-21 22:55:57 +01:00
parent f1b8af6136
commit 5212954946
10 changed files with 87 additions and 33 deletions
@@ -12,13 +12,16 @@ import com.alttd.chat.objects.channels.Channel;
import com.alttd.chat.objects.channels.CustomChannel;
import com.alttd.chat.objects.chat_log.ChatLogHandler;
import com.alttd.chat.util.ALogger;
import com.alttd.chat.util.ServerName;
import com.alttd.chat.util.Utility;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.List;
public class ChatPlugin extends JavaPlugin {
@@ -38,7 +41,7 @@ public class ChatPlugin extends JavaPlugin {
chatAPI = new ChatImplementation();
chatHandler = new ChatHandler();
DatabaseConnection.initialize();
serverConfig = new ServerConfig(Bukkit.getServer().getName());
serverConfig = new ServerConfig(ServerName.getServerName());
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true);
registerListener(new PlayerListener(serverConfig), new ChatListener(chatLogHandler), new BookListener(), new ShutdownListener(chatLogHandler, this));
if(serverConfig.GLOBALCHAT) {
@@ -57,8 +60,10 @@ public class ChatPlugin extends JavaPlugin {
registerCommand("p", new PartyChat());
registerCommand("emotes", new Emotes());
for (Channel channel : Channel.getChannels()) {
if (!(channel instanceof CustomChannel customChannel)) continue;
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(customChannel));
if (!(channel instanceof CustomChannel customChannel)) {
continue;
}
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(customChannel));
}
messageChannel = Config.MESSAGECHANNEL;
@@ -116,10 +121,10 @@ public class ChatPlugin extends JavaPlugin {
serverConfig.MUTED = !serverConfig.MUTED;
}
public void ReloadConfig() {
chatAPI.ReloadConfig();
chatAPI.ReloadChatFilters();
serverConfig = new ServerConfig(Bukkit.getServer().getName());
public void reloadConfig() {
chatAPI.reloadConfig();
chatAPI.reloadChatFilters();
serverConfig = new ServerConfig(ServerName.getServerName());
Bukkit.broadcast(Utility.parseMiniMessage("Reloaded ChatPlugin Config."), "command.chat.reloadchat");
ALogger.info("Reloaded ChatPlugin config.");
}