Fix some reloading issues.

This commit is contained in:
asofold 2012-09-04 06:48:21 +02:00
parent 47f78f8b02
commit da420ec877
6 changed files with 95 additions and 25 deletions

View File

@ -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;
@ -55,12 +57,27 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
/** The event listeners. */
private final List<Listener> listeners = new ArrayList<Listener>();
/** Components that need notification on reloading.
* (Kept here, for if during runtime some might get added.)*/
private final List<INotifyReload> notifyReload = new LinkedList<INotifyReload>();
/** 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,15 +95,18 @@ 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);
}
}

View File

@ -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,9 +48,15 @@ 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();
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);
}
@ -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();
}
}

View File

@ -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();
}
/**
@ -52,6 +51,14 @@ public class GlobalChat extends Check{
}
}
@Override
public void onReload() {
// Set some things from the global config.
ConfigFile config = ConfigManager.getConfigFile();
engine = new LetterEngine(config);
}
/**
* Check without further synchronization.
* @param player

View File

@ -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<INotifyReload> 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),
}){

View File

@ -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();
}

View File

@ -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;
@ -18,8 +20,12 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class ReloadCommand extends NCPCommand {
public ReloadCommand(NoCheatPlus plugin) {
/** Components that need to be notified on reload */
private final Collection<INotifyReload> notifyReload;
public ReloadCommand(NoCheatPlus plugin, Collection<INotifyReload> notifyReload) {
super(plugin, "reload", Permissions.ADMINISTRATION_RELOAD);
this.notifyReload = notifyReload;
}
@Override
@ -51,6 +57,11 @@ public class ReloadCommand extends NCPCommand {
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());