From 4dcebd11c7ab80ddbd808f55d23f37a5264de11e Mon Sep 17 00:00:00 2001 From: asofold Date: Thu, 6 Nov 2014 01:23:24 +0100 Subject: [PATCH] Spaces. --- .../actions/AbstractActionList.java | 115 ++++++++-------- .../nocheatplus/actions/types/LogAction.java | 128 +++++++++--------- .../config/ConfigFileWithActions.java | 120 ++++++++-------- 3 files changed, 186 insertions(+), 177 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/AbstractActionList.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/AbstractActionList.java index 959c57f6..2da04a94 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/AbstractActionList.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/AbstractActionList.java @@ -10,14 +10,14 @@ import java.util.Map.Entry; import fr.neatmonster.nocheatplus.config.ConfigFileWithActions; public abstract class AbstractActionList>{ - - - public static interface ActionListFactory>{ - public L getNewActionList(String permissionSilent); - } - - /** Something to return if nothing is set. */ - protected static final Action[] emptyArray = new Action[0]; + + + public static interface ActionListFactory>{ + public L getNewActionList(String permissionSilent); + } + + /** Something to return if nothing is set. */ + protected static final Action[] emptyArray = new Action[0]; /** This is a very bad design decision, but it's also really convenient to define this here. */ public final String permissionSilent; @@ -28,7 +28,7 @@ public abstract class AbstractActionList thresholds = new ArrayList(); - protected final ActionListFactory listFactory; + protected final ActionListFactory listFactory; /** * Instantiates a new action list. @@ -37,7 +37,7 @@ public abstract class AbstractActionList listFactory) { - this.listFactory = listFactory; + this.listFactory = listFactory; this.permissionSilent = permissionSilent + ".silent"; } @@ -49,7 +49,7 @@ public abstract class AbstractActionList[] getActions(final double violationLevel) { + public Action[] getActions(final double violationLevel) { Integer result = null; for (final Integer threshold : thresholds) @@ -87,47 +87,56 @@ public abstract class AbstractActionList config) { - final L newList = listFactory.getNewActionList(permissionSilent); - for (final Entry[]> entry : actions.entrySet()){ - final Integer t = entry.getKey(); - final Action[] a = getOptimizedCopy(config, t, entry.getValue()); - if (a != null && a.length > 0){ - newList.setActions(t, a); - } - } - - return newList; - } - /** - * Get an optimized copy of the Actions array, given the config in use. - * @param config - * @param threshold - * @param actions - * @return Copy with optimized entries, null or empty arrays are possible. Contained Actions might be identical to the given ones, just changed actions must be new instances to preserve consistency, Action instances are not to be altered. - */ - public Action[] getOptimizedCopy(final ConfigFileWithActions config, final Integer threshold, final Action[] actions) - { - if (actions == null || actions.length == 0) return null; - final ArrayList> optimized = new ArrayList>(); - for (final Action action : actions){ - final Action optAction = action.getOptimizedCopy(config, threshold); - if (optAction != null) optimized.add(optAction); - } - if (optimized.isEmpty()) return null; - @SuppressWarnings("unchecked") - final Action[] optActions = (Action[]) new Action[optimized.size()]; - optimized.toArray(optActions); - return optActions; - } + /** + * Return a copy of this list, but optimize it, i.e. remove entries that are + * never called, possibly do other optimizations which based on the specific + * configuration. + * + * @param config + * Configuration to adapt to. + * @return Optimized AbstractActionList, individual Actions can be identical + * instances, altered Action instances must always be new instances, + * arrays are always new arrays. + */ + public L getOptimizedCopy(final ConfigFileWithActions config) { + final L newList = listFactory.getNewActionList(permissionSilent); + for (final Entry[]> entry : actions.entrySet()){ + final Integer t = entry.getKey(); + final Action[] a = getOptimizedCopy(config, t, entry.getValue()); + if (a != null && a.length > 0){ + newList.setActions(t, a); + } + } + + return newList; + } + + /** + * Get an optimized copy of the Actions array, given the config in use. + * @param config + * @param threshold + * @param actions + * @return Copy with optimized entries, null or empty arrays are possible. Contained Actions might be identical to the given ones, just changed actions must be new instances to preserve consistency, Action instances are not to be altered. + */ + public Action[] getOptimizedCopy(final ConfigFileWithActions config, final Integer threshold, final Action[] actions) + { + if (actions == null || actions.length == 0) { + return null; + } + final ArrayList> optimized = new ArrayList>(); + for (final Action action : actions){ + final Action optAction = action.getOptimizedCopy(config, threshold); + if (optAction != null) { + optimized.add(optAction); + } + } + if (optimized.isEmpty()) { + return null; + } + @SuppressWarnings("unchecked") + final Action[] optActions = (Action[]) new Action[optimized.size()]; + optimized.toArray(optActions); + return optActions; + } } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/LogAction.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/LogAction.java index 8897a9d4..3fefaa21 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/LogAction.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/LogAction.java @@ -16,13 +16,13 @@ import fr.neatmonster.nocheatplus.utilities.ColorUtil; * Print a log message to various locations. */ public class LogAction extends ActionWithParameters { - - private static final String PREFIX_CHAT = ChatColor.RED + "NCP: "+ ChatColor.WHITE ; - private static final String PREFIX_CONSOLE= "[NoCheatPlus] "; - private static final String PREFIX_FILE = ""; - - // TODO: pull down to providers for (console), !chat!, (file) - then move to NCPCompat. - + + private static final String PREFIX_CHAT = ChatColor.RED + "NCP: "+ ChatColor.WHITE ; + private static final String PREFIX_CONSOLE= "[NoCheatPlus] "; + private static final String PREFIX_FILE = ""; + + // TODO: pull down to providers for (console), !chat!, (file) - then move to NCPCompat. + // Some flags to decide where the log message should show up, based on the configuration file. /** Log to chat? */ public final boolean toChat; @@ -32,7 +32,7 @@ public class LogAction extends ActionWithParameters { /** Log to file? */ public final boolean toFile; - + /** Message prefixes. */ public final String prefixChat, prefixConsole, prefixFile; @@ -65,7 +65,7 @@ public class LogAction extends ActionWithParameters { prefixConsole = PREFIX_CONSOLE; prefixFile = PREFIX_FILE; } - + /** * Constructor for optimized actions. * @param name @@ -86,31 +86,31 @@ public class LogAction extends ActionWithParameters { toConsole = prefixConsole != null; toFile = prefixFile != null; } - - /* - * (non-Javadoc) - * - * @see - * fr.neatmonster.nocheatplus.actions.Action#execute(fr.neatmonster.nocheatplus - * .checks.ViolationData) - */ - @Override - public boolean execute(final ViolationData violationData) { - if (!violationData.player.hasPermission(violationData.getPermissionSilent())) { - final String message = super.getMessage(violationData); - if (toChat) { - NCPAPIProvider.getNoCheatPlusAPI().sendAdminNotifyMessage(ColorUtil.replaceColors(prefixChat + message)); - } - if (toConsole) { - LogUtil.logInfo(ColorUtil.removeColors(prefixConsole + message)); - } - if (toFile) { - StaticLogFile.fileLogger.info(ColorUtil.removeColors(prefixFile + message)); - } - } - return false; - } + + /* + * (non-Javadoc) + * + * @see + * fr.neatmonster.nocheatplus.actions.Action#execute(fr.neatmonster.nocheatplus + * .checks.ViolationData) + */ + @Override + public boolean execute(final ViolationData violationData) { + if (!violationData.player.hasPermission(violationData.getPermissionSilent())) { + final String message = super.getMessage(violationData); + if (toChat) { + NCPAPIProvider.getNoCheatPlusAPI().sendAdminNotifyMessage(ColorUtil.replaceColors(prefixChat + message)); + } + if (toConsole) { + LogUtil.logInfo(ColorUtil.removeColors(prefixConsole + message)); + } + if (toFile) { + StaticLogFile.fileLogger.info(ColorUtil.removeColors(prefixFile + message)); + } + } + return false; + } /** * Create the string that's used to define the action in the logfile. @@ -123,35 +123,35 @@ public class LogAction extends ActionWithParameters { + (toFile ? "f" : ""); } - @Override - public Action getOptimizedCopy(final ConfigFileWithActions config, final Integer threshold) { - if (!config.getBoolean(ConfPaths.LOGGING_ACTIVE)) { - return null; - } - final String prefixChat = filterPrefix(config, ConfPaths.LOGGING_BACKEND_INGAMECHAT_PREFIX, PREFIX_CHAT, this.toChat && config.getBoolean(ConfPaths.LOGGING_BACKEND_INGAMECHAT_ACTIVE)); - final String prefixConsole = filterPrefix(config, ConfPaths.LOGGING_BACKEND_CONSOLE_PREFIX, PREFIX_CONSOLE, this.toConsole && config.getBoolean(ConfPaths.LOGGING_BACKEND_CONSOLE_ACTIVE)); - final String prefixFile = filterPrefix(config, ConfPaths.LOGGING_BACKEND_FILE_PREFIX, PREFIX_FILE, this.toFile && config.getBoolean(ConfPaths.LOGGING_BACKEND_FILE_ACTIVE)); - if (allNull(prefixChat, prefixConsole, prefixFile)) { - return null; - } - return new LogAction(name, delay, repeat, prefixChat, prefixConsole, prefixFile, message); - } - - private static boolean allNull(Object... objects) { - for (int i = 0; i < objects.length; i++) { - if (objects[i] != null) { - return false; - } - } - return true; - } - - private static final String filterPrefix(final ConfigFileWithActions config, final String path, final String defaultValue, final boolean use) { - if (!use) { - return null; - } - final String prefix = config.getString(path); - return prefix == null ? defaultValue : prefix; - } - + @Override + public Action getOptimizedCopy(final ConfigFileWithActions config, final Integer threshold) { + if (!config.getBoolean(ConfPaths.LOGGING_ACTIVE)) { + return null; + } + final String prefixChat = filterPrefix(config, ConfPaths.LOGGING_BACKEND_INGAMECHAT_PREFIX, PREFIX_CHAT, this.toChat && config.getBoolean(ConfPaths.LOGGING_BACKEND_INGAMECHAT_ACTIVE)); + final String prefixConsole = filterPrefix(config, ConfPaths.LOGGING_BACKEND_CONSOLE_PREFIX, PREFIX_CONSOLE, this.toConsole && config.getBoolean(ConfPaths.LOGGING_BACKEND_CONSOLE_ACTIVE)); + final String prefixFile = filterPrefix(config, ConfPaths.LOGGING_BACKEND_FILE_PREFIX, PREFIX_FILE, this.toFile && config.getBoolean(ConfPaths.LOGGING_BACKEND_FILE_ACTIVE)); + if (allNull(prefixChat, prefixConsole, prefixFile)) { + return null; + } + return new LogAction(name, delay, repeat, prefixChat, prefixConsole, prefixFile, message); + } + + private static boolean allNull(Object... objects) { + for (int i = 0; i < objects.length; i++) { + if (objects[i] != null) { + return false; + } + } + return true; + } + + private static final String filterPrefix(final ConfigFileWithActions config, final String path, final String defaultValue, final boolean use) { + if (!use) { + return null; + } + final String prefix = config.getString(path); + return prefix == null ? defaultValue : prefix; + } + } 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 c904dbe3..8b1ce922 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigFileWithActions.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigFileWithActions.java @@ -6,69 +6,69 @@ import fr.neatmonster.nocheatplus.actions.Action; import fr.neatmonster.nocheatplus.actions.ActionData; public abstract class ConfigFileWithActions> extends RawConfigFile { - + /** 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. - * - * @param path - * the path - * @param permission - * the permission - * @return the action list - */ - public L getOptimizedActionList(final String path, final String permission) - { - if (factory == null){ - setActionFactory(); - } - final String value = this.getString(path); - return factory.createActionList(value, permission).getOptimizedCopy(this); - } + // /** + // * @deprecated Use resetActionFactory. + // */ + // public void regenerateActionLists(){ + // resetActionFactory(); + // } - /** - * A convenience method to get default action lists from the configuration, without - * applying any optimization. - * - * @param path - * the path - * @param permission - * the permission - * @return the action list - */ - public L getDefaultActionList(final String path, final String permission) - { - if (factory == null){ - setActionFactory(); - } - final String value = this.getString(path); - return factory.createActionList(value, permission); - } + /** + * 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. + * + * @param path + * the path + * @param permission + * the permission + * @return the action list + */ + public L getOptimizedActionList(final String path, final String permission) + { + if (factory == null){ + setActionFactory(); + } + final String value = this.getString(path); + return factory.createActionList(value, permission).getOptimizedCopy(this); + } + + /** + * A convenience method to get default action lists from the configuration, without + * applying any optimization. + * + * @param path + * the path + * @param permission + * the permission + * @return the action list + */ + public L getDefaultActionList(final String path, final String permission) + { + if (factory == null){ + setActionFactory(); + } + final String value = this.getString(path); + return factory.createActionList(value, permission); + } /** @@ -91,5 +91,5 @@ public abstract class ConfigFileWithActions