diff --git a/src/fr/neatmonster/nocheatplus/NoCheatPlus.java b/src/fr/neatmonster/nocheatplus/NoCheatPlus.java index edad7a23..2e4dd17f 100644 --- a/src/fr/neatmonster/nocheatplus/NoCheatPlus.java +++ b/src/fr/neatmonster/nocheatplus/NoCheatPlus.java @@ -5,6 +5,7 @@ import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import org.bukkit.Bukkit; @@ -28,6 +29,7 @@ import fr.neatmonster.nocheatplus.checks.fight.FightListener; import fr.neatmonster.nocheatplus.checks.inventory.InventoryListener; import fr.neatmonster.nocheatplus.checks.moving.MovingListener; import fr.neatmonster.nocheatplus.command.CommandHandler; +import fr.neatmonster.nocheatplus.command.INotifyReload; import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; @@ -54,13 +56,28 @@ public class NoCheatPlus extends JavaPlugin implements Listener { /** The event listeners. */ private final List listeners = new ArrayList(); + + /** Components that need notification on reloading. + * (Kept here, for if during runtime some might get added.)*/ + private final List notifyReload = new LinkedList(); /** Is the configuration outdated? */ private boolean configOutdated = false; /** Is a new update available? */ private boolean updateAvailable = false; - + + /** + * Convenience method to add to listeners and notifyReload lists. + * @param listener + */ + private void addListener(final Listener listener){ + listeners.add(listener); + if (listener instanceof INotifyReload){ + notifyReload.add((INotifyReload) listener); + } + } + /* (non-Javadoc) * @see org.bukkit.plugin.java.JavaPlugin#onDisable() */ @@ -78,14 +95,17 @@ public class NoCheatPlus extends JavaPlugin implements Listener { // Stop the lag measuring task. LagMeasureTask.cancel(); + // Remove listeners. + listeners.clear(); + + // Remove config listeners. + notifyReload.clear(); + // Cleanup the configuration manager. ConfigManager.cleanup(); // Just to be sure nothing gets left out. getServer().getScheduler().cancelTasks(this); - - // Remove listeners. - listeners.clear(); // Tell the server administrator the we finished unloading NoCheatPlus. System.out.println("[NoCheatPlus] Version " + pdfFile.getVersion() + " is disabled."); @@ -108,14 +128,18 @@ public class NoCheatPlus extends JavaPlugin implements Listener { // List the events listeners. listeners.clear(); - listeners.add(new BlockBreakListener()); - listeners.add(new BlockInteractListener()); - listeners.add(new BlockPlaceListener()); - listeners.add(new ChatListener()); - listeners.add(new FightListener()); - listeners.add(new InventoryListener()); - listeners.add(new MovingListener()); - listeners.add(new Workarounds()); + for (final Listener listener : new Listener[]{ + new BlockBreakListener(), + new BlockInteractListener(), + new BlockPlaceListener(), + new ChatListener(), + new FightListener(), + new InventoryListener(), + new MovingListener(), + new Workarounds(), + }){ + addListener(listener); + } // Set up a task to monitor server lag. LagMeasureTask.start(this); @@ -126,7 +150,7 @@ public class NoCheatPlus extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(this, this); // Register the commands handler. - getCommand("nocheatplus").setExecutor(new CommandHandler(this)); + getCommand("nocheatplus").setExecutor(new CommandHandler(this, notifyReload)); ConfigFile config = ConfigManager.getConfigFile(); @@ -337,4 +361,5 @@ public class NoCheatPlus extends JavaPlugin implements Listener { if (!message.equals("")) player.sendMessage(message); } + } diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java b/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java index f8f21daf..990cae0f 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java @@ -12,6 +12,7 @@ import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerMoveEvent; import fr.neatmonster.nocheatplus.checks.chat.analysis.ds.SimpleCharPrefixTree; +import fr.neatmonster.nocheatplus.command.INotifyReload; import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; @@ -31,7 +32,7 @@ import fr.neatmonster.nocheatplus.players.Permissions; * * @see ChatEvent */ -public class ChatListener implements Listener { +public class ChatListener implements Listener, INotifyReload { /** The color check. */ private final Color color = new Color(); @@ -47,11 +48,17 @@ public class ChatListener implements Listener { private final SimpleCharPrefixTree chatCommands = new SimpleCharPrefixTree(); public ChatListener(){ - // Read some things from the global config file. ConfigFile config = ConfigManager.getConfigFile(); - commandExclusions.feedAll(config.getStringList(ConfPaths.CHAT_NOPWNAGE_EXCLUSIONS), false, true); - chatCommands.feedAll(config.getStringList(ConfPaths.CHAT_GLOBALCHAT_COMMANDS), false, true); + initFilters(config); + // (globalChat inits in constructor.) } + + private void initFilters(ConfigFile config) { + commandExclusions.clear(); + commandExclusions.feedAll(config.getStringList(ConfPaths.CHAT_NOPWNAGE_EXCLUSIONS), false, true); + chatCommands.clear(); + chatCommands.feedAll(config.getStringList(ConfPaths.CHAT_GLOBALCHAT_COMMANDS), false, true); + } /** * We listen to PlayerChat events for obvious reasons. @@ -195,4 +202,13 @@ public class ChatListener implements Listener { */ ChatData.getData(event.getPlayer()).noPwnageLastMovedTime = System.currentTimeMillis(); } + + @Override + public void onReload() { + // Read some things from the global config file. + ConfigFile config = ConfigManager.getConfigFile(); + initFilters(config); + globalChat.onReload(); + } + } diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/GlobalChat.java b/src/fr/neatmonster/nocheatplus/checks/chat/GlobalChat.java index 60543d29..bf482b0c 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/GlobalChat.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/GlobalChat.java @@ -7,6 +7,7 @@ import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.chat.analysis.MessageLetterCount; import fr.neatmonster.nocheatplus.checks.chat.analysis.WordLetterCount; import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.LetterEngine; +import fr.neatmonster.nocheatplus.command.INotifyReload; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; @@ -16,15 +17,13 @@ import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; * @author mc_dev * */ -public class GlobalChat extends Check{ +public class GlobalChat extends Check implements INotifyReload{ - private final LetterEngine engine; + private LetterEngine engine; public GlobalChat() { super(CheckType.CHAT_GLOBALCHAT); - // Set some things from the global config. - ConfigFile config = ConfigManager.getConfigFile(); - engine = new LetterEngine(config); + onReload(); } /** @@ -51,6 +50,14 @@ public class GlobalChat extends Check{ return unsafeCheck(player, message, captcha, cc, data, isMainThread); } } + + + @Override + public void onReload() { + // Set some things from the global config. + ConfigFile config = ConfigManager.getConfigFile(); + engine = new LetterEngine(config); + } /** * Check without further synchronization. diff --git a/src/fr/neatmonster/nocheatplus/command/CommandHandler.java b/src/fr/neatmonster/nocheatplus/command/CommandHandler.java index b6e869f8..a340601b 100644 --- a/src/fr/neatmonster/nocheatplus/command/CommandHandler.java +++ b/src/fr/neatmonster/nocheatplus/command/CommandHandler.java @@ -1,5 +1,6 @@ package fr.neatmonster.nocheatplus.command; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -74,13 +75,13 @@ public class CommandHandler implements CommandExecutor { * @param plugin * the instance of NoCheatPlus */ - public CommandHandler(final NoCheatPlus plugin) { + public CommandHandler(final NoCheatPlus plugin, final Collection notifyReload) { // Register sub commands: for (NCPCommand cmd : new NCPCommand[]{ new BanCommand(plugin), new InfoCommand(plugin), new KickCommand(plugin), - new ReloadCommand(plugin), + new ReloadCommand(plugin, notifyReload), new TellCommand(plugin), new DelayCommand(plugin), }){ diff --git a/src/fr/neatmonster/nocheatplus/command/INotifyReload.java b/src/fr/neatmonster/nocheatplus/command/INotifyReload.java new file mode 100644 index 00000000..0020e957 --- /dev/null +++ b/src/fr/neatmonster/nocheatplus/command/INotifyReload.java @@ -0,0 +1,10 @@ +package fr.neatmonster.nocheatplus.command; + +/** + * Interface for a component that needs to be notified about a reload. + * @author mc_dev + * + */ +public interface INotifyReload { + public void onReload(); +} diff --git a/src/fr/neatmonster/nocheatplus/command/ReloadCommand.java b/src/fr/neatmonster/nocheatplus/command/ReloadCommand.java index a51a923f..26266ab2 100644 --- a/src/fr/neatmonster/nocheatplus/command/ReloadCommand.java +++ b/src/fr/neatmonster/nocheatplus/command/ReloadCommand.java @@ -1,5 +1,7 @@ package fr.neatmonster.nocheatplus.command; +import java.util.Collection; + import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -17,9 +19,13 @@ import fr.neatmonster.nocheatplus.config.ConfigManager; import fr.neatmonster.nocheatplus.players.Permissions; public class ReloadCommand extends NCPCommand { + + /** Components that need to be notified on reload */ + private final Collection notifyReload; - public ReloadCommand(NoCheatPlus plugin) { + public ReloadCommand(NoCheatPlus plugin, Collection notifyReload) { super(plugin, "reload", Permissions.ADMINISTRATION_RELOAD); + this.notifyReload = notifyReload; } @Override @@ -50,6 +56,11 @@ public class ReloadCommand extends NCPCommand { FightConfig.clear(); InventoryConfig.clear(); MovingConfig.clear(); + + // Tell the plugin to adapt to new config. + for (INotifyReload component : notifyReload){ + component.onReload(); + } // Say to the other plugins that we've reloaded the configuration. Bukkit.getPluginManager().callEvent(new NCPReloadEvent());