From 2913baa6c718d8355e78d2e64231e3a3fac4ae49 Mon Sep 17 00:00:00 2001 From: asofold Date: Thu, 18 Jul 2013 00:21:42 +0200 Subject: [PATCH] [Bleeding] Change to lazy ActionFactory setting. Allows to set a new ActionFactoryFactory without the ConfigManager.init already trying to parse actions, thus implementing special actions should be easier. Still three calls might be necessary to be on the safe side: 1. ConfigManager.setActionFactoryFactory(new factory) 2. ConfigManaher.setAllActionFactories() 3. DataManager.clearConfigs() Not entirely convinced if concurrency issues might arise with reload or even on startup (chat). --- .../nocheatplus/config/ConfigFile.java | 2 +- .../config/ConfigFileWithActions.java | 36 +++++++++++++++---- .../nocheatplus/config/ConfigManager.java | 24 ++++++++++--- .../nocheatplus/config/DefaultConfig.java | 4 +-- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigFile.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigFile.java index 4af1c27b..42c1f852 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigFile.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigFile.java @@ -21,7 +21,7 @@ import fr.neatmonster.nocheatplus.checks.ViolationData; public class ConfigFile extends ConfigFileWithActions { @Override - public void regenerateActionLists() { + public void setActionFactory() { factory = ConfigManager.getActionFactory(((MemorySection) this.get(ConfPaths.STRINGS)).getValues(false)); } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigFileWithActions.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigFileWithActions.java index 8d2a8b32..c904dbe3 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigFileWithActions.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigFileWithActions.java @@ -7,15 +7,31 @@ import fr.neatmonster.nocheatplus.actions.ActionData; public abstract class ConfigFileWithActions> extends RawConfigFile { - /** - * Do this after reading new data.
- * TODO: Specify what this actually does. - */ - public abstract void regenerateActionLists(); - - /** The factory. */ protected AbstractActionFactory factory = null; + +// /** +// * @deprecated Use resetActionFactory. +// */ +// public void regenerateActionLists(){ +// resetActionFactory(); +// } + + /** + * This should set (override if necessary) a default ActionFactory. NCP will use ConfigManager.getActionsFactoryFactory.
+ * Do this after reading new data or changing the AbstractActionFactory instance.
+ * This must set or override the internal factory field to enable/update ActionList getting.
+ * If factory is null on getting an ActionList, this will be called internally. + */ + public abstract void setActionFactory(); + + /** + * Explicitly set the ActionFactory, also allow setting to null for lazy reset/get. + * @param factory + */ + public void setActionFactory(final AbstractActionFactory factory){ + this.factory = factory; + } /** * A convenience method to get an optimized action list from the configuration. @@ -28,6 +44,9 @@ public abstract class ConfigFileWithActions + * To Hook into NCP for setting the factories, you should register a INotifyReload instance + * with the NoCheatPlusAPI using the annotation SetupOrder with a higher negative value (-1000). * @param factory */ public static void setActionFactoryFactory(ActionFactoryFactory factory){ @@ -85,9 +91,10 @@ public class ConfigManager { return new ActionFactory(library); } }; - } + } + // Use lazy resetting. for (final ConfigFile config : worldsMap.values()){ - config.regenerateActionLists(); + config.setActionFactory(null); } } @@ -95,6 +102,15 @@ public class ConfigManager { return actionFactoryFactory; } + /** + * Force setting up all configs action factories. + */ + public static void setAllActionFactories(){ + for (final ConfigFile config : worldsMap.values()){ + config.setActionFactory(); + } + } + /** * Get the WorldConfigProvider in use. * @return @@ -209,7 +225,7 @@ public class ConfigManager { LogUtil.logSevere(e); } } - globalConfig.regenerateActionLists(); +// globalConfig.setActionFactory(); worldsMap.put(null, globalConfig); @@ -249,7 +265,7 @@ public class ConfigManager { } worldConfig.setDefaults(globalConfig); worldConfig.options().copyDefaults(true); - worldConfig.regenerateActionLists(); +// worldConfig.setActionFactory(); } } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 195432ef..1c5256d8 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -561,7 +561,7 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.COMPATIBILITY_BLOCKS + ConfPaths.SUB_ALLOWINSTANTBREAK, new LinkedList()); set(ConfPaths.COMPATIBILITY_BLOCKS + ConfPaths.SUB_OVERRIDEFLAGS + ".snow", "default"); - // Update internal factory based on all the new entries to the "actions" section. - regenerateActionLists(); +// // Update internal factory based on all the new entries to the "actions" section. +// setActionFactory(); } }