diff --git a/src/fr/neatmonster/nocheatplus/NoCheatPlus.java b/src/fr/neatmonster/nocheatplus/NoCheatPlus.java index 9168a436..ed626fb8 100644 --- a/src/fr/neatmonster/nocheatplus/NoCheatPlus.java +++ b/src/fr/neatmonster/nocheatplus/NoCheatPlus.java @@ -39,6 +39,7 @@ import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; import fr.neatmonster.nocheatplus.config.DefaultConfig; +import fr.neatmonster.nocheatplus.event.IHaveMethodOrder; import fr.neatmonster.nocheatplus.event.ListenerManager; import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; import fr.neatmonster.nocheatplus.metrics.Metrics; @@ -177,15 +178,14 @@ public class NoCheatPlus extends JavaPlugin implements Listener, NoCheatPlusAPI protected List changedCommands = null; - protected final ListenerManager listenerManager = new ListenerManager(this, false); - + private final ListenerManager listenerManager = new ListenerManager(this, false); + + private boolean manageListeners = true; + @Override public void addComponent(final Object obj) { if (obj instanceof Listener) { - final Listener listener = (Listener) obj; -// Bukkit.getPluginManager().registerEvents(listener, this); - listenerManager.registerAllEventHandlers(listener, "NoCheatPlus"); - listeners.add(listener); + addListener((Listener) obj); } if (obj instanceof INotifyReload) { notifyReload.add((INotifyReload) obj); @@ -196,6 +196,29 @@ public class NoCheatPlus extends JavaPlugin implements Listener, NoCheatPlusAPI dataMan.addComponent(obj); } + private void addListener(final Listener listener) { + if (manageListeners){ + listenerManager.registerAllEventHandlers(listener, "NoCheatPlus"); + listeners.add(listener); + } + else{ + Bukkit.getPluginManager().registerEvents(listener, this); + if (listener instanceof IHaveMethodOrder){ + // TODO: Might log the order too, might prevent registration ? + // TODO: Alternative: queue listeners and register after startup (!) + CheckUtils.logWarning("[NoCheatPlus] Listener demands registration order, but listeners are not managed: " + listener.getClass().getName()); + } + } + } + + /** + * Test if NCP uses the ListenerManager at all. + * @return If so. + */ + public boolean doesManageListeners(){ + return manageListeners; + } + @Override public void removeComponent(final Object obj) { if (obj instanceof Listener){ @@ -292,11 +315,18 @@ public class NoCheatPlus extends JavaPlugin implements Listener, NoCheatPlusAPI BlockProperties.applyConfig(config, ConfPaths.COMPATIBILITY_BLOCKS); // Temp probably, - // List the events listeners and register. -// Bukkit.getPluginManager().registerEvents(this, this); - listenerManager.setRegisterDirectly(true); - listenerManager.registerAllWithBukkit(); - listenerManager.registerAllEventHandlers(this, "NoCheatPlus"); + // List the events listeners and register. + manageListeners = config.getBoolean(ConfPaths.MISCELLANEOUS_MANAGELISTENERS); + if (manageListeners) { + listenerManager.setRegisterDirectly(true); + listenerManager.registerAllWithBukkit(); + } + else{ + // Just for safety. + listenerManager.setRegisterDirectly(false); + listenerManager.clear(); + } + addListener(this); for (final Object obj : new Object[]{ NCPExemptionManager.getListener(), dataMan, diff --git a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java index 6a9e3889..9994d10a 100644 --- a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -42,17 +42,18 @@ public abstract class ConfPaths { * d8b Y8b Y8b 888 Y88D Y888 , 888 , 888 888 ,ee 888 888 888 888 , Y888 888P Y888 888P Y88D * d888b Y8b Y8b 888 d,dP "88,e8' "YeeP" 888 888 "88 888 888 888 "YeeP" "88 88" "88 88" d,dP */ - @GlobalConfig - private static final String MISCELLANEOUS = "miscellaneous."; - public static final String MISCELLANEOUS_ALLOWCLIENTMODS = MISCELLANEOUS + "allowclientmods"; - public static final String MISCELLANEOUS_OPINCONSOLEONLY = MISCELLANEOUS + "opinconsoleonly"; - public static final String MISCELLANEOUS_PROTECTPLUGINS = MISCELLANEOUS + "protectplugins"; - public static final String MISCELLANEOUS_CHECKFORUPDATES = MISCELLANEOUS + "checkforupdates"; - public static final String MISCELLANEOUS_UPDATETIMEOUT = MISCELLANEOUS + "updatetimeout"; - public static final String MISCELLANEOUS_REPORTTOMETRICS = MISCELLANEOUS + "reporttometrics"; - private static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY = MISCELLANEOUS + "nomovedtooquickly."; - public static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY_ENABLED = MISCELLANEOUS_NOMOVEDTOOQUICKLY + "enabled"; - public static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY_USEPROXY = MISCELLANEOUS_NOMOVEDTOOQUICKLY + "useproxy"; + @GlobalConfig + private static final String MISCELLANEOUS = "miscellaneous."; + public static final String MISCELLANEOUS_ALLOWCLIENTMODS = MISCELLANEOUS + "allowclientmods"; + public static final String MISCELLANEOUS_OPINCONSOLEONLY = MISCELLANEOUS + "opinconsoleonly"; + public static final String MISCELLANEOUS_PROTECTPLUGINS = MISCELLANEOUS + "protectplugins"; + public static final String MISCELLANEOUS_CHECKFORUPDATES = MISCELLANEOUS + "checkforupdates"; + public static final String MISCELLANEOUS_UPDATETIMEOUT = MISCELLANEOUS + "updatetimeout"; + public static final String MISCELLANEOUS_REPORTTOMETRICS = MISCELLANEOUS + "reporttometrics"; + public static final String MISCELLANEOUS_MANAGELISTENERS = MISCELLANEOUS + "managelisteners"; + private static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY = MISCELLANEOUS + "nomovedtooquickly."; + public static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY_ENABLED = MISCELLANEOUS_NOMOVEDTOOQUICKLY + "enabled"; + public static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY_USEPROXY = MISCELLANEOUS_NOMOVEDTOOQUICKLY + "useproxy"; @GlobalConfig private static final String DATA = "data."; diff --git a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 6246b5c7..1fad8e16 100644 --- a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -60,6 +60,7 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.MISCELLANEOUS_ALLOWCLIENTMODS, false); set(ConfPaths.MISCELLANEOUS_OPINCONSOLEONLY, false); set(ConfPaths.MISCELLANEOUS_PROTECTPLUGINS, true); + set(ConfPaths.MISCELLANEOUS_MANAGELISTENERS, true); // set(ConfPaths.MISCELLANEOUS_CHECKFORUPDATES, true); set(ConfPaths.MISCELLANEOUS_REPORTTOMETRICS, true);