From ade3a9276dc0a58673bc30ff7c7c4ede22d564d6 Mon Sep 17 00:00:00 2001 From: asofold Date: Thu, 9 Aug 2012 17:56:48 +0200 Subject: [PATCH] Refactoring stage 1 (RAW): Get rid of some reflection, synchronization questions. --- .../nocheatplus/actions/types/ActionList.java | 2 +- .../actions/types/ActionWithParameters.java | 9 +- .../actions/types/CommandAction.java | 13 ++- .../nocheatplus/actions/types/LogAction.java | 9 +- .../neatmonster/nocheatplus/checks/Check.java | 90 ++++++++++++++----- .../nocheatplus/checks/CheckConfig.java | 7 ++ .../checks/CheckConfigFactory.java | 9 ++ .../nocheatplus/checks/CheckData.java | 15 ++++ .../nocheatplus/checks/CheckDataFactory.java | 9 ++ .../nocheatplus/checks/CheckType.java | 81 ++++++++++------- .../checks/ExecuteActionsEvent.java | 13 ++- .../nocheatplus/checks/ViolationData.java | 27 ++++++ .../checks/blockbreak/BlockBreakConfig.java | 32 ++++++- .../checks/blockbreak/BlockBreakData.java | 14 ++- .../checks/blockbreak/Direction.java | 2 +- .../checks/blockbreak/FastBreak.java | 2 +- .../checks/blockbreak/NoSwing.java | 2 +- .../nocheatplus/checks/blockbreak/Reach.java | 9 +- .../blockinteract/BlockInteractConfig.java | 28 +++++- .../blockinteract/BlockInteractData.java | 20 +++-- .../checks/blockinteract/Direction.java | 2 +- .../checks/blockinteract/Reach.java | 9 +- .../checks/blockplace/BlockPlaceConfig.java | 34 ++++++- .../checks/blockplace/BlockPlaceData.java | 20 +++-- .../checks/blockplace/Direction.java | 2 +- .../checks/blockplace/FastPlace.java | 2 +- .../checks/blockplace/NoSwing.java | 2 +- .../nocheatplus/checks/blockplace/Reach.java | 9 +- .../nocheatplus/checks/blockplace/Speed.java | 2 +- .../nocheatplus/checks/chat/ChatConfig.java | 30 ++++++- .../nocheatplus/checks/chat/ChatData.java | 24 +++-- .../nocheatplus/checks/chat/ChatListener.java | 8 +- .../nocheatplus/checks/chat/Color.java | 21 ++--- .../nocheatplus/checks/chat/NoPwnage.java | 70 ++++++--------- .../nocheatplus/checks/fight/Angle.java | 4 +- .../nocheatplus/checks/fight/Critical.java | 2 +- .../nocheatplus/checks/fight/Direction.java | 2 +- .../nocheatplus/checks/fight/FightConfig.java | 42 ++++++++- .../nocheatplus/checks/fight/FightData.java | 20 +++-- .../nocheatplus/checks/fight/GodMode.java | 2 +- .../nocheatplus/checks/fight/InstantHeal.java | 2 +- .../nocheatplus/checks/fight/Knockback.java | 2 +- .../nocheatplus/checks/fight/NoSwing.java | 2 +- .../nocheatplus/checks/fight/Reach.java | 2 +- .../nocheatplus/checks/fight/Speed.java | 9 +- .../nocheatplus/checks/inventory/Drop.java | 2 +- .../checks/inventory/InstantBow.java | 2 +- .../checks/inventory/InstantEat.java | 9 +- .../checks/inventory/InventoryConfig.java | 32 ++++++- .../checks/inventory/InventoryData.java | 20 +++-- .../checks/inventory/InventoryListener.java | 2 +- .../checks/moving/CreativeFly.java | 9 +- .../checks/moving/MorePackets.java | 9 +- .../checks/moving/MorePacketsVehicle.java | 9 +- .../checks/moving/MovingConfig.java | 34 ++++++- .../nocheatplus/checks/moving/MovingData.java | 24 +++-- .../checks/moving/MovingListener.java | 24 ++--- .../nocheatplus/checks/moving/NoFall.java | 11 +-- .../checks/moving/SurvivalFly.java | 11 +-- .../nocheatplus/config/ConfigFile.java | 2 +- .../nocheatplus/config/ConfigManager.java | 2 +- .../nocheatplus/config/DefaultConfig.java | 2 +- .../nocheatplus/players/ExecutionHistory.java | 2 +- 63 files changed, 649 insertions(+), 274 deletions(-) create mode 100644 src/fr/neatmonster/nocheatplus/checks/CheckConfig.java create mode 100644 src/fr/neatmonster/nocheatplus/checks/CheckConfigFactory.java create mode 100644 src/fr/neatmonster/nocheatplus/checks/CheckData.java create mode 100644 src/fr/neatmonster/nocheatplus/checks/CheckDataFactory.java create mode 100644 src/fr/neatmonster/nocheatplus/checks/ViolationData.java diff --git a/src/fr/neatmonster/nocheatplus/actions/types/ActionList.java b/src/fr/neatmonster/nocheatplus/actions/types/ActionList.java index 045e36b4..5da7f372 100644 --- a/src/fr/neatmonster/nocheatplus/actions/types/ActionList.java +++ b/src/fr/neatmonster/nocheatplus/actions/types/ActionList.java @@ -48,7 +48,7 @@ public class ActionList { /** * Get a list of actions that match the violation level. The only method that has to be called by a check. * - * @param violationLevel + * @param VL * The violation level that should be matched. * @return The array of actions whose threshold was closest to the violation level but not bigger. */ diff --git a/src/fr/neatmonster/nocheatplus/actions/types/ActionWithParameters.java b/src/fr/neatmonster/nocheatplus/actions/types/ActionWithParameters.java index 642bad3c..8bbdf91d 100644 --- a/src/fr/neatmonster/nocheatplus/actions/types/ActionWithParameters.java +++ b/src/fr/neatmonster/nocheatplus/actions/types/ActionWithParameters.java @@ -2,11 +2,10 @@ package fr.neatmonster.nocheatplus.actions.types; import java.util.ArrayList; -import org.bukkit.entity.Player; - import fr.neatmonster.nocheatplus.actions.Action; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; +import fr.neatmonster.nocheatplus.checks.ViolationData; /* * MMP"""""""MM dP oo M""MMM""MMM""M oo dP dP @@ -53,7 +52,7 @@ public abstract class ActionWithParameters extends Action { } /** - * Get a string with all the wildcards replaced with data from LogData. + * Get a string with all the wildcards replaced with dataFactory from LogData. * * @param player * the player @@ -61,7 +60,7 @@ public abstract class ActionWithParameters extends Action { * the check * @return the message */ - protected String getMessage(final Player player, final Check check) { + protected String getMessage(final Check check, final ViolationData violationData) { // Should be big enough most of the time. final StringBuilder log = new StringBuilder(100); @@ -69,7 +68,7 @@ public abstract class ActionWithParameters extends Action { if (part instanceof String) log.append((String) part); else - log.append(check.getParameter((ParameterName) part, player)); + log.append(check.getParameter((ParameterName) part, violationData)); return log.toString(); } diff --git a/src/fr/neatmonster/nocheatplus/actions/types/CommandAction.java b/src/fr/neatmonster/nocheatplus/actions/types/CommandAction.java index bbc54021..d2baf59c 100644 --- a/src/fr/neatmonster/nocheatplus/actions/types/CommandAction.java +++ b/src/fr/neatmonster/nocheatplus/actions/types/CommandAction.java @@ -1,8 +1,7 @@ package fr.neatmonster.nocheatplus.actions.types; -import org.bukkit.entity.Player; - import fr.neatmonster.nocheatplus.checks.Check; +import fr.neatmonster.nocheatplus.checks.ViolationData; /* * MM'""""'YMM dP @@ -48,17 +47,17 @@ public class CommandAction extends ActionWithParameters { * that can be directly used as a command in the console. * * @param player - * The player that is used to fill in missing data. + * The player that is used to fill in missing dataFactory. * @param check - * The check that is used to fill in missing data. + * The check that is used to fill in missing dataFactory. * @return The complete, ready to use, command. */ - public String getCommand(final Player player, final Check check) { - return super.getMessage(player, check); + public String getCommand(final Check check, final ViolationData violationData) { + return super.getMessage(check, violationData); } /** - * Convert the commands data into a string that can be used in the configuration files. + * Convert the commands dataFactory into a string that can be used in the configuration files. * * @return the string */ diff --git a/src/fr/neatmonster/nocheatplus/actions/types/LogAction.java b/src/fr/neatmonster/nocheatplus/actions/types/LogAction.java index 36d6a2c5..1edf2aa0 100644 --- a/src/fr/neatmonster/nocheatplus/actions/types/LogAction.java +++ b/src/fr/neatmonster/nocheatplus/actions/types/LogAction.java @@ -1,8 +1,7 @@ package fr.neatmonster.nocheatplus.actions.types; -import org.bukkit.entity.Player; - import fr.neatmonster.nocheatplus.checks.Check; +import fr.neatmonster.nocheatplus.checks.ViolationData; /* * M""MMMMMMMM MMP"""""""MM dP oo @@ -55,7 +54,7 @@ public class LogAction extends ActionWithParameters { } /** - * Parse the final log message out of various data from the player and check that triggered the action. + * Parse the final log message out of various dataFactory from the player and check that triggered the action. * * @param player * The player that is used as a source for the log message. @@ -63,8 +62,8 @@ public class LogAction extends ActionWithParameters { * The check that is used as a source for the log message. * @return the log message */ - public String getLogMessage(final Player player, final Check check) { - return super.getMessage(player, check); + public String getLogMessage(final Check check, final ViolationData violationData) { + return super.getMessage(check, violationData); } /** diff --git a/src/fr/neatmonster/nocheatplus/checks/Check.java b/src/fr/neatmonster/nocheatplus/checks/Check.java index e1f0c882..27d1f56d 100644 --- a/src/fr/neatmonster/nocheatplus/checks/Check.java +++ b/src/fr/neatmonster/nocheatplus/checks/Check.java @@ -101,6 +101,49 @@ public abstract class Check { public Check(final CheckType type) { this.type = type; } + + /** + * Execute actions in a thread safe manner if isMainThread is set to false.
+ * @param player + * @param VL + * @param actions + * @param isMainThread + * @return + */ + public boolean executeActionsThreadSafe(final Player player, final double VL, final ActionList actions, final boolean isMainThread){ + if (isMainThread){ + // Just execute. + return executeActions(player, VL, actions); + } + else { + return executeActionsThreadSafe(player, VL, actions); + } + } + + /** + * Execute actions in a thread safe manner.
+ * @param player + * @param VL + * @param actions + * @return + */ + public boolean executeActionsThreadSafe(final Player player, final double VL, final ActionList actions){ + // Sync it into the main thread by using an event. + final ExecuteActionsEvent event = new ExecuteActionsEvent(new ViolationData(this, player, VL, actions)); + Bukkit.getPluginManager().callEvent(event); + return event.getCancel(); + } + + /** + * Convenience method. + * @param player + * @param VL + * @param actions + * @return + */ + protected boolean executeActions(final Player player, final double VL, final ActionList actions){ + return executeActions(new ViolationData(this, player, VL, actions)); + } /** * Execute some actions for the specified player. @@ -109,18 +152,21 @@ public abstract class Check { * the player * @return true, if successful */ - protected boolean executeActions(final Player player) { + protected boolean executeActions(final ViolationData violationData) { try { boolean special = false; - - final Object config = type.getConfig().getDeclaredMethod("getConfig", Player.class).invoke(null, player); - final Object data = type.getData().getDeclaredMethod("getData", Player.class).invoke(null, player); - final ActionList actionList = (ActionList) type.getConfig().getDeclaredField(type.getName() + "Actions") - .get(config); - final double violationLevel = type.getData().getDeclaredField(type.getName() + "VL").getDouble(data); + final Player player = violationData.player; + +// final Object configFactory = type.getConfig().getDeclaredMethod("getConfig", Player.class).invoke(null, player); +// final Object dataFactory = type.getData().getDeclaredMethod("getData", Player.class).invoke(null, player); +// final ActionList actionList = (ActionList) type.getConfig().getDeclaredField(type.getName() + "Actions") +// .get(configFactory); + + final ActionList actionList = violationData.actions; + final double violationLevel = violationData.VL; // Dispatch the VL processing to the hook manager. - if (NCPHookManager.shouldCancelVLProcessing(type, player)) + if (NCPHookManager.shouldCancelVLProcessing(violationData.check.type, player)) // One of the hooks has decided to cancel the VL processing, return false. return false; @@ -130,15 +176,18 @@ public abstract class Check { final long time = System.currentTimeMillis() / 1000L; for (final Action ac : actions) - if (getHistory(player).executeAction(getClass().getName(), ac, time)) + if (getHistory(player).executeAction(violationData.check.type.getName(), ac, time)) // The execution history said it really is time to execute the action, find out what it is and do // what is needed. + + // TODO: Check design: maybe ac.execute(this) without the instance checks ? + if (ac instanceof LogAction && !player.hasPermission(actionList.permissionSilent)) - executeLogAction((LogAction) ac, this, player); + executeLogAction((LogAction) ac, violationData.check, violationData); else if (ac instanceof CancelAction) special = true; else if (ac instanceof CommandAction) - executeConsoleCommand((CommandAction) ac, this, player); + executeConsoleCommand((CommandAction) ac, violationData.check, violationData); else if (ac instanceof DummyAction) { // Do nothing, it's a dummy action after all. } @@ -160,8 +209,8 @@ public abstract class Check { * @param player * the player */ - private void executeConsoleCommand(final CommandAction action, final Check check, final Player player) { - final String command = action.getCommand(player, check); + private void executeConsoleCommand(final CommandAction action, final Check check, final ViolationData violationData) { + final String command = action.getCommand(check, violationData); try { Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); @@ -183,12 +232,12 @@ public abstract class Check { * @param player * the player */ - private void executeLogAction(final LogAction logAction, final Check check, final Player player) { + private void executeLogAction(final LogAction logAction, final Check check, final ViolationData violationData) { final ConfigFile configurationFile = ConfigManager.getConfigFile(); if (!configurationFile.getBoolean(ConfPaths.LOGGING_ACTIVE)) return; - final String message = logAction.getLogMessage(player, check); + final String message = logAction.getLogMessage(check, violationData); if (configurationFile.getBoolean(ConfPaths.LOGGING_LOGTOCONSOLE) && logAction.toConsole()) // Console logs are not colored. System.out.println("[NoCheatPlus] " + removeColors(message)); @@ -212,15 +261,14 @@ public abstract class Check { * the player * @return the parameter */ - public String getParameter(final ParameterName wildcard, final Player player) { + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { if (wildcard == ParameterName.CHECK) return getClass().getSimpleName(); else if (wildcard == ParameterName.PLAYER) - return player.getName(); + return violationData.player.getName(); else if (wildcard == ParameterName.VIOLATIONS) { try { - final Object data = type.getData().getDeclaredMethod("getData", Player.class).invoke(null, player); - return "" + Math.round(type.getData().getDeclaredField(type.getName() + "VL").getDouble(data)); + return "" + Math.round(violationData.VL); } catch (final Exception e) { Bukkit.broadcastMessage("getParameter " + type.getName()); e.printStackTrace(); @@ -239,9 +287,7 @@ public abstract class Check { */ public boolean isEnabled(final Player player) { try { - final Object config = type.getConfig().getDeclaredMethod("getConfig", Player.class).invoke(null, player); - return !player.hasPermission(type.getPermission()) - && type.getConfig().getDeclaredField(type.getName() + "Check").getBoolean(config); + return type.isEnabled(player) && !player.hasPermission(type.getPermission()); } catch (final Exception e) { e.printStackTrace(); } diff --git a/src/fr/neatmonster/nocheatplus/checks/CheckConfig.java b/src/fr/neatmonster/nocheatplus/checks/CheckConfig.java new file mode 100644 index 00000000..e7bec3da --- /dev/null +++ b/src/fr/neatmonster/nocheatplus/checks/CheckConfig.java @@ -0,0 +1,7 @@ +package fr.neatmonster.nocheatplus.checks; + +public interface CheckConfig { + + public boolean isEnabled(CheckType checkType); + +} diff --git a/src/fr/neatmonster/nocheatplus/checks/CheckConfigFactory.java b/src/fr/neatmonster/nocheatplus/checks/CheckConfigFactory.java new file mode 100644 index 00000000..aacf9d0f --- /dev/null +++ b/src/fr/neatmonster/nocheatplus/checks/CheckConfigFactory.java @@ -0,0 +1,9 @@ +package fr.neatmonster.nocheatplus.checks; + +import org.bukkit.entity.Player; + +public interface CheckConfigFactory { + + public CheckConfig getConfig(Player player); + +} diff --git a/src/fr/neatmonster/nocheatplus/checks/CheckData.java b/src/fr/neatmonster/nocheatplus/checks/CheckData.java new file mode 100644 index 00000000..04f21f0c --- /dev/null +++ b/src/fr/neatmonster/nocheatplus/checks/CheckData.java @@ -0,0 +1,15 @@ +package fr.neatmonster.nocheatplus.checks; + + +/** + * This is for future purposes. Might remove...
+ * Some checks in NoPwnage synchronize over data, so using this from exectueActions can deadlock (!).
+ * One might think of making this an interface not for the internally used data, but for copy of data for external use only. + * Then sync could go over other objects for async access. + * + * @author mc_dev + * + */ +public interface CheckData { + +} diff --git a/src/fr/neatmonster/nocheatplus/checks/CheckDataFactory.java b/src/fr/neatmonster/nocheatplus/checks/CheckDataFactory.java new file mode 100644 index 00000000..601c9db3 --- /dev/null +++ b/src/fr/neatmonster/nocheatplus/checks/CheckDataFactory.java @@ -0,0 +1,9 @@ +package fr.neatmonster.nocheatplus.checks; + +import org.bukkit.entity.Player; + +public interface CheckDataFactory { + + public CheckData getData(final Player player); + +} diff --git a/src/fr/neatmonster/nocheatplus/checks/CheckType.java b/src/fr/neatmonster/nocheatplus/checks/CheckType.java index f206d921..d9f4322d 100644 --- a/src/fr/neatmonster/nocheatplus/checks/CheckType.java +++ b/src/fr/neatmonster/nocheatplus/checks/CheckType.java @@ -1,5 +1,7 @@ package fr.neatmonster.nocheatplus.checks; +import org.bukkit.entity.Player; + import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakConfig; import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakData; import fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractConfig; @@ -27,33 +29,33 @@ import fr.neatmonster.nocheatplus.players.Permissions; * d8888P dP */ /** - * Type of checks (containing configuration and data classes, name and permission). + * Type of checks (containing configuration and dataFactory classes, name and permission). */ public enum CheckType { ALL, - BLOCKBREAK(BlockBreakConfig.class, BlockBreakData.class), + BLOCKBREAK(BlockBreakConfig.factory, BlockBreakData.factory), BLOCKBREAK_DIRECTION(BLOCKBREAK, "direction", Permissions.BLOCKBREAK_DIRECTION), BLOCKBREAK_FASTBREAK(BLOCKBREAK, "fastBreak", Permissions.BLOCKBREAK_FASTBREAK), BLOCKBREAK_NOSWING(BLOCKBREAK, "noSwing", Permissions.BLOCKBREAK_NOSWING), BLOCKBREAK_REACH(BLOCKBREAK, "reach", Permissions.BLOCKBREAK_REACH), - BLOCKINTERACT(BlockInteractConfig.class, BlockInteractData.class), + BLOCKINTERACT(BlockInteractConfig.factory, BlockInteractData.factory), BLOCKINTERACT_DIRECTION(BLOCKINTERACT, "direction", Permissions.BLOCKINTERACT_DIRECTION), BLOCKINTERACT_REACH(BLOCKINTERACT, "reach", Permissions.BLOCKINTERACT_REACH), - BLOCKPLACE(BlockPlaceConfig.class, BlockPlaceData.class), + BLOCKPLACE(BlockPlaceConfig.factory, BlockPlaceData.factory), BLOCKPLACE_DIRECTION(BLOCKPLACE, "direction", Permissions.BLOCKPLACE_DIRECTION), BLOCKPLACE_FASTPLACE(BLOCKPLACE, "fastPlace", Permissions.BLOCKPLACE_FASTPLACE), BLOCKPLACE_NOSWING(BLOCKPLACE, "noSwing", Permissions.BLOCKPLACE_NOSWING), BLOCKPLACE_REACH(BLOCKPLACE, "reach", Permissions.BLOCKBREAK_REACH), BLOCKPLACE_SPEED(BLOCKPLACE, "speed", Permissions.BLOCKPLACE_SPEED), - CHAT(ChatConfig.class, ChatData.class), + CHAT(ChatConfig.factory, ChatData.factory), CHAT_COLOR(CHAT, "color", Permissions.CHAT_COLOR), CHAT_NOPWNAGE(CHAT, "noPwnage", Permissions.CHAT_NOPWNAGE), - FIGHT(FightConfig.class, FightData.class), + FIGHT(FightConfig.factory, FightData.factory), FIGHT_ANGLE(FIGHT, "angle", Permissions.FIGHT_ANGLE), FIGHT_CRITICAL(FIGHT, "critical", Permissions.FIGHT_CRITICAL), FIGHT_DIRECTION(FIGHT, "direction", Permissions.FIGHT_DIRECTION), @@ -64,12 +66,12 @@ public enum CheckType { FIGHT_REACH(FIGHT, "reach", Permissions.FIGHT_REACH), FIGHT_SPEED(FIGHT, "speed", Permissions.FIGHT_SPEED), - INVENTORY(InventoryConfig.class, InventoryData.class), + INVENTORY(InventoryConfig.factory, InventoryData.factory), INVENTORY_DROP(INVENTORY, "drop", Permissions.INVENTORY_DROP), INVENTORY_INSTANTBOW(INVENTORY, "instantBow", Permissions.INVENTORY_INSTANTBOW), INVENTORY_INSTANTEAT(INVENTORY, "instantEat", Permissions.INVENTORY_INSTANTEAT), - MOVING(MovingConfig.class, MovingData.class), + MOVING(MovingConfig.factory, MovingData.factory), MOVING_CREATIVEFLY(MOVING, "creativeFly", Permissions.MOVING_CREATIVEFLY), MOVING_MOREPACKETS(MOVING, "morePackets", Permissions.MOVING_MOREPACKETS), MOVING_MOREPACKETSVEHICLE(MOVING, "morePacketsVehicle", Permissions.MOVING_MOREPACKETSVEHICLE), @@ -81,11 +83,11 @@ public enum CheckType { /** The group. */ public final CheckType group; - /** The config. */ - public final Class config; + /** The configFactory. */ + public final CheckConfigFactory configFactory; - /** The data. */ - public final Class data; + /** The dataFactory. */ + public final CheckDataFactory dataFactory; /** The name. */ public final String name; @@ -105,20 +107,20 @@ public enum CheckType { * * @param group * the group - * @param config - * the config class - * @param data - * the data class + * @param configFactory + * the configFactory class + * @param dataFactory + * the dataFactory class * @param name * the name * @param permission * the permission */ - private CheckType(final CheckType group, final Class config, final Class data, final String name, + private CheckType(final CheckType group, final CheckConfigFactory configFactory, CheckDataFactory dataFactory, final String name, final String permission) { this.group = group; - this.config = config; - this.data = data; + this.configFactory = configFactory; + this.dataFactory = dataFactory; this.name = name; this.permission = permission; } @@ -134,37 +136,37 @@ public enum CheckType { * the permission */ private CheckType(final CheckType group, final String name, final String permission) { - this(group, group.getConfig(), group.getData(), name, permission); + this(group, group.getConfigFactory(), group.getDataFactory(), name, permission); } /** * Instantiates a new check type. * - * @param config - * the config - * @param data - * the data + * @param configFactory + * the configFactory + * @param dataFactory + * the dataFactory */ - private CheckType(final Class config, final Class data) { - this(null, config, data, null, null); + private CheckType(final CheckConfigFactory configFactory, final CheckDataFactory dataFactory) { + this(null, configFactory, dataFactory, null, null); } /** - * Gets the config class. + * Gets the configFactory class. * - * @return the config class + * @return the configFactory class */ - public Class getConfig() { - return config; + public CheckConfigFactory getConfigFactory() { + return configFactory; } /** - * Gets the data class. + * Gets the dataFactory class. * - * @return the data class + * @return the dataFactory class */ - public Class getData() { - return data; + public CheckDataFactory getDataFactory() { + return dataFactory; } /** @@ -184,4 +186,15 @@ public enum CheckType { public String getPermission() { return permission; } + + /** + * Check if the check is enabled by configuration (no permission check). + * @param player + * @return + */ + public final boolean isEnabled(final Player player){ +// if (configFactory == null) return true; // TODO: maybe leave this out. + return configFactory.getConfig(player).isEnabled(this); + } + } \ No newline at end of file diff --git a/src/fr/neatmonster/nocheatplus/checks/ExecuteActionsEvent.java b/src/fr/neatmonster/nocheatplus/checks/ExecuteActionsEvent.java index 58830b8f..67ff1412 100644 --- a/src/fr/neatmonster/nocheatplus/checks/ExecuteActionsEvent.java +++ b/src/fr/neatmonster/nocheatplus/checks/ExecuteActionsEvent.java @@ -1,6 +1,5 @@ package fr.neatmonster.nocheatplus.checks; -import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -13,17 +12,15 @@ public class ExecuteActionsEvent extends Event { private static final HandlerList handlers = new HandlerList(); - private final Check check; - final Player player; + private final ViolationData violationData; /** * If the actions have been executed already. */ private boolean actionsExecuted = false; private boolean cancel = false; - - public ExecuteActionsEvent(final Check check, final Player player){ - this.check = check; - this.player = player; + + public ExecuteActionsEvent(final ViolationData violationData){ + this.violationData = violationData; } @Override @@ -41,7 +38,7 @@ public class ExecuteActionsEvent extends Event { public void executeActions(){ if (actionsExecuted) return; - cancel = check.executeActions(player); + cancel = violationData.check.executeActions(violationData); actionsExecuted = true; } diff --git a/src/fr/neatmonster/nocheatplus/checks/ViolationData.java b/src/fr/neatmonster/nocheatplus/checks/ViolationData.java new file mode 100644 index 00000000..d3db95ba --- /dev/null +++ b/src/fr/neatmonster/nocheatplus/checks/ViolationData.java @@ -0,0 +1,27 @@ +package fr.neatmonster.nocheatplus.checks; + +import org.bukkit.entity.Player; + +import fr.neatmonster.nocheatplus.actions.types.ActionList; + +/** + * Violation specific dataFactory, for executing actions.
+ * This is meant to capture a violation incident in a potentially thread safe way (!). + * @author mc_dev + * + */ +public class ViolationData { + + public final Check check; + public final Player player; + public final double VL; + public final ActionList actions; + + public ViolationData(final Check check, final Player player, final double VL, final ActionList actions){ + this.check = check; + this.player = player; + this.VL = VL; + this.actions = actions; + } + +} diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakConfig.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakConfig.java index b58d51d8..e41dff05 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakConfig.java @@ -6,6 +6,9 @@ import java.util.Map; import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.types.ActionList; +import fr.neatmonster.nocheatplus.checks.CheckConfig; +import fr.neatmonster.nocheatplus.checks.CheckConfigFactory; +import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; @@ -33,7 +36,14 @@ import fr.neatmonster.nocheatplus.players.Permissions; * Configurations specific for the block break checks. Every world gets one of these assigned to it, or if a world * doesn't get it's own, it will use the "global" version. */ -public class BlockBreakConfig { +public class BlockBreakConfig implements CheckConfig{ + + public static final CheckConfigFactory factory = new CheckConfigFactory(){ + @Override + public final CheckConfig getConfig(final Player player) { + return BlockBreakConfig.getConfig(player); + } + }; /** The map containing the configurations per world. */ private static Map worldsMap = new HashMap(); @@ -77,8 +87,8 @@ public class BlockBreakConfig { /** * Instantiates a new block break configuration. * - * @param data - * the data + * @param dataFactory + * the dataFactory */ public BlockBreakConfig(final ConfigFile data) { directionCheck = data.getBoolean(ConfPaths.BLOCKBREAK_DIRECTION_CHECK); @@ -96,4 +106,20 @@ public class BlockBreakConfig { reachCheck = data.getBoolean(ConfPaths.BLOCKBREAK_REACH_CHECK); reachActions = data.getActionList(ConfPaths.BLOCKBREAK_REACH_ACTIONS, Permissions.BLOCKBREAK_REACH); } + + @Override + public final boolean isEnabled(final CheckType checkType) { + switch(checkType){ + case BLOCKBREAK_DIRECTION: + return directionCheck; + case BLOCKBREAK_FASTBREAK: + return fastBreakCheck; + case BLOCKBREAK_NOSWING: + return noSwingCheck; + case BLOCKBREAK_REACH: + return reachCheck; + default: + return true; + } + } } diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakData.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakData.java index 2e057977..a73dd3fb 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakData.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakData.java @@ -5,6 +5,9 @@ import java.util.Map; import org.bukkit.entity.Player; +import fr.neatmonster.nocheatplus.checks.CheckData; +import fr.neatmonster.nocheatplus.checks.CheckDataFactory; + /* * M#"""""""'M dP dP M#"""""""'M dP * ## mmmm. `M 88 88 ## mmmm. `M 88 @@ -25,7 +28,14 @@ import org.bukkit.entity.Player; /** * Player specific data for the block break checks. */ -public class BlockBreakData { +public class BlockBreakData implements CheckData { + + public static final CheckDataFactory factory = new CheckDataFactory(){ + @Override + public final CheckData getData(final Player player) { + return BlockBreakData.getData(player); + } + }; /** The map containing the data per players. */ private static Map playersMap = new HashMap(); @@ -59,4 +69,6 @@ public class BlockBreakData { // Data of the reach check. public double reachDistance; + + } diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/Direction.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/Direction.java index 432825db..4391bdde 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/Direction.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/Direction.java @@ -59,7 +59,7 @@ public class Direction extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.directionVL, BlockBreakConfig.getConfig(player).directionActions); } else // Player did likely nothing wrong, reduce violation counter to reward him. data.directionVL *= 0.9D; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java index 3cdf1850..e9714d2c 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/FastBreak.java @@ -73,7 +73,7 @@ public class FastBreak extends Check { data.fastBreakVL += Math.max(timeLimit - elapsedTime, 0D); // Cancel the event if needed. - cancel = executeActions(player); + cancel = executeActions(player, data.fastBreakVL, cc.fastBreakActions); } else // Remove one from the buffer. data.fastBreakBuffer--; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/NoSwing.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/NoSwing.java index 9ee37257..9d4207ce 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/NoSwing.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/NoSwing.java @@ -51,7 +51,7 @@ public class NoSwing extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.noSwingVL, BlockBreakConfig.getConfig(player).noSwingActions); } return cancel; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/Reach.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/Reach.java index 2e16dfe3..325eddb3 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/Reach.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/Reach.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.utilities.CheckUtils; /* @@ -66,7 +67,7 @@ public class Reach extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.reachVL, BlockBreakConfig.getConfig(player).reachActions); } else // Player passed the check, reward him. data.reachVL *= 0.9D; @@ -78,10 +79,10 @@ public class Reach extends Check { * @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player) */ @Override - public String getParameter(final ParameterName wildcard, final Player player) { + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { if (wildcard == ParameterName.REACH_DISTANCE) - return String.valueOf(Math.round(BlockBreakData.getData(player).reachDistance)); + return String.valueOf(Math.round(BlockBreakData.getData(violationData.player).reachDistance)); else - return super.getParameter(wildcard, player); + return super.getParameter(wildcard, violationData); } } diff --git a/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractConfig.java b/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractConfig.java index dde5f2a7..5148622b 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractConfig.java @@ -6,6 +6,9 @@ import java.util.Map; import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.types.ActionList; +import fr.neatmonster.nocheatplus.checks.CheckConfig; +import fr.neatmonster.nocheatplus.checks.CheckConfigFactory; +import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; @@ -33,7 +36,14 @@ import fr.neatmonster.nocheatplus.players.Permissions; * Configurations specific for the block interact checks. Every world gets one of these assigned to it, or if a world * doesn't get it's own, it will use the "global" version. */ -public class BlockInteractConfig { +public class BlockInteractConfig implements CheckConfig { + + public static final CheckConfigFactory factory = new CheckConfigFactory(){ + @Override + public final CheckConfig getConfig(final Player player) { + return BlockInteractConfig.getConfig(player); + } + }; /** The map containing the configurations per world. */ private static Map worldsMap = new HashMap(); @@ -68,8 +78,8 @@ public class BlockInteractConfig { /** * Instantiates a new block interact configuration. * - * @param data - * the data + * @param dataFactory + * the dataFactory */ public BlockInteractConfig(final ConfigFile data) { directionCheck = data.getBoolean(ConfPaths.BLOCKINTERACT_DIRECTION_CHECK); @@ -79,4 +89,16 @@ public class BlockInteractConfig { reachCheck = data.getBoolean(ConfPaths.BLOCKINTERACT_REACH_CHECK); reachActions = data.getActionList(ConfPaths.BLOCKINTERACT_REACH_ACTIONS, Permissions.BLOCKINTERACT_REACH); } + + @Override + public final boolean isEnabled(final CheckType checkType) { + switch(checkType){ + case BLOCKINTERACT_DIRECTION: + return directionCheck; + case BLOCKINTERACT_REACH: + return reachCheck; + default: + return true; + } + } } diff --git a/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java b/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java index 654bfc78..efba0050 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java @@ -5,6 +5,9 @@ import java.util.Map; import org.bukkit.entity.Player; +import fr.neatmonster.nocheatplus.checks.CheckData; +import fr.neatmonster.nocheatplus.checks.CheckDataFactory; + /* * M#"""""""'M dP dP M""M dP dP * ## mmmm. `M 88 88 M M 88 88 @@ -23,19 +26,26 @@ import org.bukkit.entity.Player; * MMMMMMMMMMM */ /** - * Player specific data for the block interact checks. + * Player specific dataFactory for the block interact checks. */ -public class BlockInteractData { +public class BlockInteractData implements CheckData { + + public static final CheckDataFactory factory = new CheckDataFactory(){ + @Override + public final CheckData getData(final Player player) { + return BlockInteractData.getData(player); + } + }; - /** The map containing the data per players. */ + /** The map containing the dataFactory per players. */ private static Map playersMap = new HashMap(); /** - * Gets the data of a specified player. + * Gets the dataFactory of a specified player. * * @param player * the player - * @return the data + * @return the dataFactory */ public static BlockInteractData getData(final Player player) { if (!playersMap.containsKey(player.getName())) diff --git a/src/fr/neatmonster/nocheatplus/checks/blockinteract/Direction.java b/src/fr/neatmonster/nocheatplus/checks/blockinteract/Direction.java index 8324abde..9a097060 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockinteract/Direction.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockinteract/Direction.java @@ -59,7 +59,7 @@ public class Direction extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.directionVL, BlockInteractConfig.getConfig(player).directionActions); } else // Player did likely nothing wrong, reduce violation counter to reward him. data.directionVL *= 0.9D; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockinteract/Reach.java b/src/fr/neatmonster/nocheatplus/checks/blockinteract/Reach.java index 612ac313..6d319762 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockinteract/Reach.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockinteract/Reach.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.utilities.CheckUtils; /* @@ -66,7 +67,7 @@ public class Reach extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.reachVL, BlockInteractConfig.getConfig(player).reachActions); } else // Player passed the check, reward him. data.reachVL *= 0.9D; @@ -78,10 +79,10 @@ public class Reach extends Check { * @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player) */ @Override - public String getParameter(final ParameterName wildcard, final Player player) { + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { if (wildcard == ParameterName.REACH_DISTANCE) - return String.valueOf(Math.round(BlockInteractData.getData(player).reachDistance)); + return String.valueOf(Math.round(BlockInteractData.getData(violationData.player).reachDistance)); else - return super.getParameter(wildcard, player); + return super.getParameter(wildcard, violationData); } } diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java index e21896ad..1f48294e 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java @@ -6,6 +6,9 @@ import java.util.Map; import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.types.ActionList; +import fr.neatmonster.nocheatplus.checks.CheckConfig; +import fr.neatmonster.nocheatplus.checks.CheckConfigFactory; +import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; @@ -33,7 +36,14 @@ import fr.neatmonster.nocheatplus.players.Permissions; * Configurations specific for the block place checks. Every world gets one of these assigned to it, or if a world * doesn't get it's own, it will use the "global" version. */ -public class BlockPlaceConfig { +public class BlockPlaceConfig implements CheckConfig { + + public static final CheckConfigFactory factory = new CheckConfigFactory(){ + @Override + public final CheckConfig getConfig(final Player player) { + return BlockPlaceConfig.getConfig(player); + } + }; /** The map containing the configurations per world. */ private static Map worldsMap = new HashMap(); @@ -80,8 +90,8 @@ public class BlockPlaceConfig { /** * Instantiates a new block place configuration. * - * @param data - * the data + * @param dataFactory + * the dataFactory */ public BlockPlaceConfig(final ConfigFile data) { directionCheck = data.getBoolean(ConfPaths.BLOCKPLACE_DIRECTION_CHECK); @@ -102,4 +112,22 @@ public class BlockPlaceConfig { speedInterval = data.getLong(ConfPaths.BLOCKPLACE_SPEED_INTERVAL); speedActions = data.getActionList(ConfPaths.BLOCKPLACE_SPEED_ACTIONS, Permissions.BLOCKPLACE_SPEED); } + + @Override + public final boolean isEnabled(final CheckType checkType) { + switch(checkType){ + case BLOCKPLACE_DIRECTION: + return directionCheck; + case BLOCKPLACE_FASTPLACE: + return fastPlaceCheck; + case BLOCKPLACE_NOSWING: + return noSwingCheck; + case BLOCKPLACE_REACH: + return reachCheck; + case BLOCKPLACE_SPEED: + return speedCheck; + default: + return true; + } + } } diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java index b0aed8d9..91ee23f3 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java @@ -5,6 +5,9 @@ import java.util.Map; import org.bukkit.entity.Player; +import fr.neatmonster.nocheatplus.checks.CheckData; +import fr.neatmonster.nocheatplus.checks.CheckDataFactory; + /* * M#"""""""'M dP dP MM"""""""`YM dP * ## mmmm. `M 88 88 MM mmmmm M 88 @@ -23,19 +26,26 @@ import org.bukkit.entity.Player; * MMMMMMMMMMM */ /** - * Player specific data for the block place checks. + * Player specific dataFactory for the block place checks. */ -public class BlockPlaceData { +public class BlockPlaceData implements CheckData { + + public static final CheckDataFactory factory = new CheckDataFactory(){ + @Override + public final CheckData getData(final Player player) { + return BlockPlaceData.getData(player); + } + }; - /** The map containing the data per players. */ + /** The map containing the dataFactory per players. */ private static Map playersMap = new HashMap(); /** - * Gets the data of a specified player. + * Gets the dataFactory of a specified player. * * @param player * the player - * @return the data + * @return the dataFactory */ public static BlockPlaceData getData(final Player player) { if (!playersMap.containsKey(player.getName())) diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/Direction.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/Direction.java index d3405907..160284de 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/Direction.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/Direction.java @@ -82,7 +82,7 @@ public class Direction extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.directionVL, BlockPlaceConfig.getConfig(player).directionActions); } else // Player did likely nothing wrong, reduce violation counter to reward him. data.directionVL *= 0.9D; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/FastPlace.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/FastPlace.java index 4d0e6d27..b7447af8 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/FastPlace.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/FastPlace.java @@ -52,7 +52,7 @@ public class FastPlace extends Check { // Execute whatever actions are associated with this check and the violation level and find out if // we should cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.fastPlaceVL, cc.fastPlaceActions); } data.fastPlaceLastRefused = true; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/NoSwing.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/NoSwing.java index 3999b891..d35d327a 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/NoSwing.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/NoSwing.java @@ -51,7 +51,7 @@ public class NoSwing extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.noSwingVL, BlockPlaceConfig.getConfig(player).noSwingActions); } return cancel; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/Reach.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/Reach.java index bd569191..c0562184 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/Reach.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/Reach.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.utilities.CheckUtils; /* @@ -66,7 +67,7 @@ public class Reach extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.reachVL, BlockPlaceConfig.getConfig(player).reachActions); } else // Player passed the check, reward him. data.reachVL *= 0.9D; @@ -78,10 +79,10 @@ public class Reach extends Check { * @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player) */ @Override - public String getParameter(final ParameterName wildcard, final Player player) { + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { if (wildcard == ParameterName.REACH_DISTANCE) - return String.valueOf(Math.round(BlockPlaceData.getData(player).reachDistance)); + return String.valueOf(Math.round(BlockPlaceData.getData(violationData.player).reachDistance)); else - return super.getParameter(wildcard, player); + return super.getParameter(wildcard, violationData); } } diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/Speed.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/Speed.java index 591b3731..152edb57 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/Speed.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/Speed.java @@ -48,7 +48,7 @@ public class Speed extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we // should cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.speedVL, cc.speedActions); } data.speedLastRefused = true; diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java b/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java index 86fec486..b2aca1ac 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java @@ -6,6 +6,9 @@ import java.util.Map; import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.types.ActionList; +import fr.neatmonster.nocheatplus.checks.CheckConfig; +import fr.neatmonster.nocheatplus.checks.CheckConfigFactory; +import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; @@ -25,11 +28,18 @@ import fr.neatmonster.nocheatplus.players.Permissions; * Configurations specific for the "chat" checks. Every world gets one of these assigned to it, or if a world doesn't * get it's own, it will use the "global" version. */ -public class ChatConfig { +public class ChatConfig implements CheckConfig{ + + public static final CheckConfigFactory factory = new CheckConfigFactory(){ + @Override + public final CheckConfig getConfig(final Player player) { + return ChatConfig.getConfig(player); + } + }; /** The map containing the configurations per world. */ private static Map worldsMap = new HashMap(); - + /** * Clear all the configurations. */ @@ -117,8 +127,8 @@ public class ChatConfig { /** * Instantiates a new chat configuration. * - * @param data - * the data + * @param dataFactory + * the dataFactory */ public ChatConfig(final ConfigFile data) { colorCheck = data.getBoolean(ConfPaths.CHAT_COLOR_CHECK); @@ -180,4 +190,16 @@ public class ChatConfig { protectPlugins = data.getBoolean(ConfPaths.MISCELLANEOUS_PROTECTPLUGINS); } + + @Override + public boolean isEnabled(CheckType checkType) { + switch(checkType){ + case CHAT_COLOR: + return colorCheck; + case CHAT_NOPWNAGE: + return noPwnageCheck; + default: + return true; + } + } } diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/ChatData.java b/src/fr/neatmonster/nocheatplus/checks/chat/ChatData.java index 37610e7c..89306e85 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/ChatData.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/ChatData.java @@ -6,6 +6,9 @@ import java.util.Map; import org.bukkit.Location; import org.bukkit.entity.Player; +import fr.neatmonster.nocheatplus.checks.CheckData; +import fr.neatmonster.nocheatplus.checks.CheckDataFactory; + /* * MM'""""'YMM dP dP M""""""'YMM dP * M' .mmm. `M 88 88 M mmmm. `M 88 @@ -16,19 +19,26 @@ import org.bukkit.entity.Player; * MMMMMMMMMMM MMMMMMMMMMM */ /** - * Player specific data for the chat checks. + * Player specific dataFactory for the chat checks. */ -public class ChatData { +public class ChatData implements CheckData{ + + public static final CheckDataFactory factory = new CheckDataFactory(){ + @Override + public final CheckData getData(final Player player) { + return ChatData.getData(player); + } + }; - /** The map containing the data per players. */ + /** The map containing the dataFactory per players. */ private static Map playersMap = new HashMap(); /** - * Gets the data of a specified player. + * Gets the dataFactory of a specified player. * * @param player * the player - * @return the data + * @return the dataFactory */ public synchronized static ChatData getData(final Player player) { if (!playersMap.containsKey(player.getName())) @@ -56,12 +66,14 @@ public class ChatData { public long noPwnageReloginWarningTime; /** - * Clear the data of the no pwnage check. + * Clear the dataFactory of the no pwnage check. */ public synchronized void clearNoPwnageData() { + // TODO: re-think this sync [keep related to ChatData/NoPwnage/Color used lock.] noPwnageCaptchTries = noPwnageReloginWarnings = 0; noPwnageJoinTime = noPwnageLastMessageTime = noPwnageLastMovedTime = noPwnageLastWarningTime = noPwnageLeaveTime = noPwnageReloginWarningTime = 0L; noPwnageGeneratedCaptcha = noPwnageLastMessage = ""; noPwnageLastLocation = null; } + } diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java b/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java index e2439b10..188f8d06 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java @@ -53,8 +53,8 @@ public class ChatListener implements Listener { // First the color check. if (color.isEnabled(player)) - event.setMessage(color.check(player, event.getMessage())); - + event.setMessage(color.check(player, event.getMessage(), false)); + // Then the no pwnage check. if (noPwnage.check(player, event, false)) player.kickPlayer(Check.removeColors(ChatConfig.getConfig(player).noPwnageKickMessage)); @@ -107,7 +107,7 @@ public class ChatListener implements Listener { // First the color check. if (color.isEnabled(player)) - event.setMessage(color.check(player, event.getMessage())); + event.setMessage(color.check(player, event.getMessage(), true)); // Then the no pwnage check. if (noPwnage.check(player, event, true)) @@ -135,7 +135,7 @@ public class ChatListener implements Listener { final ChatConfig cc = ChatConfig.getConfig(player); // Execute the no pwnage check. - if (noPwnage.isEnabled(player) && noPwnage.check(player)) + if (noPwnage.isEnabled(player) && noPwnage.checkLogin(player)) event.disallow(Result.KICK_OTHER, cc.noPwnageReloginKickMessage); } } diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/Color.java b/src/fr/neatmonster/nocheatplus/checks/chat/Color.java index af03f717..ed373ef9 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/Color.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/Color.java @@ -35,18 +35,19 @@ public class Color extends Check { * the message * @return the string */ - public String check(final Player player, final String message) { + public String check(final Player player, final String message, final boolean isMainThread) { final ChatData data = ChatData.getData(player); + synchronized(data){ // [keep related to ChatData/NoPwnage/Color used lock.] + // If the message contains colors... + if (message.contains("\247")) { + // Increment the violation level of the player. + data.colorVL++; - // If the message contains colors... - if (message.contains("\247")) { - // Increment the violation level of the player. - data.colorVL++; - - // Find out if we need to remove the colors or not. - if (executeActions(player)) - // Remove color codes. - message.replaceAll("\302\247.", "").replaceAll("\247.", ""); + // Find out if we need to remove the colors or not. + if (executeActionsThreadSafe(player, data.colorVL, ChatConfig.getConfig(player).colorActions, isMainThread)) + // Remove color codes. + message.replaceAll("\302\247.", "").replaceAll("\247.", ""); + } } return message; diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/NoPwnage.java b/src/fr/neatmonster/nocheatplus/checks/chat/NoPwnage.java index 3c9c7c0f..a046053f 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/NoPwnage.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/NoPwnage.java @@ -9,9 +9,10 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerEvent; import fr.neatmonster.nocheatplus.actions.ParameterName; +import fr.neatmonster.nocheatplus.actions.types.ActionList; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; -import fr.neatmonster.nocheatplus.checks.ExecuteActionsEvent; +import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.utilities.CheckUtils; /* @@ -67,15 +68,15 @@ public class NoPwnage extends Check { * the player * @return true, if successful */ - public boolean check(final Player player) { + public boolean checkLogin(final Player player) { if (!isEnabled(player)) return false; final ChatConfig cc = ChatConfig.getConfig(player); final ChatData data = ChatData.getData(player); - synchronized(data){ - return unsafeCheck(player, cc, data); + synchronized(data){ // [keep related to ChatData/NoPwnage/Color used lock.] + return unsafeLoginCheck(player, cc, data); } } @@ -83,10 +84,10 @@ public class NoPwnage extends Check { * Check (Join), only call from synchronized code. * @param player * @param cc - * @param data + * @param dataFactory * @return */ - private boolean unsafeCheck(final Player player, final ChatConfig cc, final ChatData data) { + private boolean unsafeLoginCheck(final Player player, final ChatConfig cc, final ChatData data) { boolean cancel = false; final long now = System.currentTimeMillis(); @@ -103,10 +104,11 @@ public class NoPwnage extends Check { data.noPwnageReloginWarnings++; } else if (now - data.noPwnageReloginWarningTime < cc.noPwnageReloginWarningTimeout) // Find out if we need to ban the player or not. - cancel = executeActionsThreadSafe(player, true); + // TODO: extra actions / VL ? + cancel = executeActionsThreadSafe(player, data.noPwnageVL, cc.noPwnageActions, true); } - // Store his location and some other data. + // Store his location and some other dataFactory. data.noPwnageLastLocation = player.getLocation(); data.noPwnageJoinTime = now; @@ -129,7 +131,7 @@ public class NoPwnage extends Check { final ChatConfig cc = ChatConfig.getConfig(player); final ChatData data = ChatData.getData(player); - synchronized(data){ + synchronized(data){ // [keep related to ChatData/NoPwnage/Color used lock.] return unsafeCheck(player, event, isMainThread, cc, data); } } @@ -140,7 +142,7 @@ public class NoPwnage extends Check { * @param event * @param isMainThread * @param cc - * @param data + * @param dataFactory * @return */ private boolean unsafeCheck(final Player player, final PlayerEvent event, final boolean isMainThread, final ChatConfig cc, final ChatData data) { @@ -160,7 +162,7 @@ public class NoPwnage extends Check { if (cc.noPwnageCaptchaCheck && data.noPwnageHasStartedCaptcha) { // Correct answer to the captcha? if (message.equals(data.noPwnageGeneratedCaptcha)) { - // Yes, clear his data and do not worry anymore about him. + // Yes, clear his dataFactory and do not worry anymore about him. data.clearNoPwnageData(); data.noPwnageHasFilledCaptcha = true; player.sendMessage(replaceColors(cc.noPwnageCaptchaSuccess)); @@ -168,7 +170,8 @@ public class NoPwnage extends Check { // Does he failed too much times? if (data.noPwnageCaptchTries > cc.noPwnageCaptchaTries) // Find out if we need to ban the player or not. - cancel = executeActionsThreadSafe(player, isMainThread); + // TODO: Extra captcha actions / VL ? + cancel = executeActionsThreadSafe(player, data.noPwnageVL, cc.noPwnageActions, isMainThread); // Increment his tries number counter. data.noPwnageCaptchTries++; @@ -265,10 +268,10 @@ public class NoPwnage extends Check { ((PlayerCommandPreprocessEvent) event).setCancelled(true); // Find out if we need to ban the player or not. - cancel = executeActionsThreadSafe(player, isMainThread); + cancel = executeActionsThreadSafe(player, data.noPwnageVL, cc.noPwnageActions, isMainThread); } - // Store the message and some other data. + // Store the message and some other dataFactory. data.noPwnageLastMessage = message; data.noPwnageLastMessageTime = now; lastGlobalMessage = message; @@ -277,51 +280,30 @@ public class NoPwnage extends Check { return cancel; } - - @Override - public final boolean executeActions(final Player player){ - // To be called from synchronized code (ChatData). - // Late check of bypass permissions: - // (One might use a bypass flag, set if its already been checked and then reset.) - if (!isEnabled(player)) return false; - return super.executeActions(player); - } /** * Execute actions from another thread (not the main thread).
* This does not use extra synchronization. * @param player + * @param actions + * @param VL * @return */ - public final boolean executeActionsThreadSafe(final Player player, boolean isMainThread){ - if (isMainThread){ - // Just execute. - if (executeActions(player)){ - ChatData.getData(player).clearNoPwnageData(); - return true; - } - else - return false; - } - else { - // Sync it into the main thread by using an event. - final ExecuteActionsEvent event = new ExecuteActionsEvent(this, player); - Bukkit.getPluginManager().callEvent(event); - final boolean cancel = event.getCancel(); - if (cancel) ChatData.getData(player).clearNoPwnageData(); - return cancel; - } + public final boolean executeActionsThreadSafe(final Player player, double VL, ActionList actions, boolean isMainThread){ + final boolean cancel = super.executeActionsThreadSafe(player, VL, actions, isMainThread); + if (cancel) ChatData.getData(player).clearNoPwnageData(); + return cancel; } /* (non-Javadoc) * @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player) */ @Override - public String getParameter(final ParameterName wildcard, final Player player) { + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { if (wildcard == ParameterName.IP) - return player.getAddress().toString().substring(1).split(":")[0]; + return violationData.player.getAddress().toString().substring(1).split(":")[0]; else - return super.getParameter(wildcard, player); + return super.getParameter(wildcard, violationData); } } diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/Angle.java b/src/fr/neatmonster/nocheatplus/checks/fight/Angle.java index 89f72b1c..01937086 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/Angle.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/Angle.java @@ -54,7 +54,7 @@ public class Angle extends Check { // Add the new location to the map. data.angleHits.put(System.currentTimeMillis(), player.getLocation()); - // Not enough data to calculate deltas. + // Not enough dataFactory to calculate deltas. if (data.angleHits.size() < 2) return false; @@ -118,7 +118,7 @@ public class Angle extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.angleVL, cc.angleActions); } else // Reward the player by lowering his violation level. data.angleVL *= 0.98D; diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/Critical.java b/src/fr/neatmonster/nocheatplus/checks/fight/Critical.java index aa8dd094..157496a2 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/Critical.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/Critical.java @@ -67,7 +67,7 @@ public class Critical extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we // should cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.criticalVL, cc.criticalActions); } return cancel; diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/Direction.java b/src/fr/neatmonster/nocheatplus/checks/fight/Direction.java index ef13e555..43e90be6 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/Direction.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/Direction.java @@ -75,7 +75,7 @@ public class Direction extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.directionVL, cc.directionActions); if (cancel) // If we should cancel, remember the current time too. diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java b/src/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java index 51344a0a..9154b510 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java @@ -6,6 +6,9 @@ import java.util.Map; import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.types.ActionList; +import fr.neatmonster.nocheatplus.checks.CheckConfig; +import fr.neatmonster.nocheatplus.checks.CheckConfigFactory; +import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; @@ -25,7 +28,14 @@ import fr.neatmonster.nocheatplus.players.Permissions; * Configurations specific for the "fight" checks. Every world gets one of these assigned to it, or if a world doesn't * get it's own, it will use the "global" version. */ -public class FightConfig { +public class FightConfig implements CheckConfig { + + public static final CheckConfigFactory factory = new CheckConfigFactory(){ + @Override + public final CheckConfig getConfig(final Player player) { + return FightConfig.getConfig(player); + } + }; /** The map containing the configurations per world. */ private static Map worldsMap = new HashMap(); @@ -88,8 +98,8 @@ public class FightConfig { /** * Instantiates a new fight configuration. * - * @param data - * the data + * @param dataFactory + * the dataFactory */ public FightConfig(final ConfigFile data) { angleCheck = data.getBoolean(ConfPaths.FIGHT_ANGLE_CHECK); @@ -126,4 +136,30 @@ public class FightConfig { speedLimit = data.getInt(ConfPaths.FIGHT_SPEED_LIMIT); speedActions = data.getActionList(ConfPaths.FIGHT_SPEED_ACTIONS, Permissions.FIGHT_SPEED); } + + @Override + public final boolean isEnabled(final CheckType checkType) { + switch(checkType){ + case FIGHT_ANGLE: + return angleCheck; + case FIGHT_CRITICAL: + return criticalCheck; + case FIGHT_DIRECTION: + return directionCheck; + case FIGHT_GODMODE: + return godModeCheck; + case FIGHT_INSTANTHEAL: + return instantHealCheck; + case FIGHT_KNOCKBACK: + return knockbackCheck; + case FIGHT_NOSWING: + return noSwingCheck; + case FIGHT_REACH: + return reachCheck; + case FIGHT_SPEED: + return speedCheck; + default: + return true; + } + } } diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/FightData.java b/src/fr/neatmonster/nocheatplus/checks/fight/FightData.java index c5a68cae..cf94f1be 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/FightData.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/FightData.java @@ -7,6 +7,9 @@ import java.util.TreeMap; import org.bukkit.Location; import org.bukkit.entity.Player; +import fr.neatmonster.nocheatplus.checks.CheckData; +import fr.neatmonster.nocheatplus.checks.CheckDataFactory; + /* * MM""""""""`M oo dP dP M""""""'YMM dP * MM mmmmmmmM 88 88 M mmmm. `M 88 @@ -18,19 +21,26 @@ import org.bukkit.entity.Player; * d8888P */ /** - * Player specific data for the fight checks. + * Player specific dataFactory for the fight checks. */ -public class FightData { +public class FightData implements CheckData { + + public static final CheckDataFactory factory = new CheckDataFactory(){ + @Override + public final CheckData getData(final Player player) { + return FightData.getData(player); + } + }; - /** The map containing the data per players. */ + /** The map containing the dataFactory per players. */ private static Map playersMap = new HashMap(); /** - * Gets the data of a specified player. + * Gets the dataFactory of a specified player. * * @param player * the player - * @return the data + * @return the dataFactory */ public static FightData getData(final Player player) { if (!playersMap.containsKey(player.getName())) diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/GodMode.java b/src/fr/neatmonster/nocheatplus/checks/fight/GodMode.java index 3c73006d..c2928807 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/GodMode.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/GodMode.java @@ -63,7 +63,7 @@ public class GodMode extends Check { // Execute whatever actions are associated with this check and the violation level and find out if // we should cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.godModeVL, FightConfig.getConfig(player).godModeActions); } } else { // Give some new points, once a second. diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/InstantHeal.java b/src/fr/neatmonster/nocheatplus/checks/fight/InstantHeal.java index d5c0edbc..1a080a6e 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/InstantHeal.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/InstantHeal.java @@ -56,7 +56,7 @@ public class InstantHeal extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.instantHealVL, FightConfig.getConfig(player).instantHealActions); } else // Decrease the violation level. data.instantHealVL *= 0.9D; diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/Knockback.java b/src/fr/neatmonster/nocheatplus/checks/fight/Knockback.java index e8d31d37..d0b9688b 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/Knockback.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/Knockback.java @@ -56,7 +56,7 @@ public class Knockback extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.knockbackVL, cc.knockbackActions); } return cancel; diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/NoSwing.java b/src/fr/neatmonster/nocheatplus/checks/fight/NoSwing.java index 072a4c72..30e51c92 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/NoSwing.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/NoSwing.java @@ -50,7 +50,7 @@ public class NoSwing extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.noSwingVL, FightConfig.getConfig(player).noSwingActions); } return cancel; diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/Reach.java b/src/fr/neatmonster/nocheatplus/checks/fight/Reach.java index 50ebaaf6..2de0aab5 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/Reach.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/Reach.java @@ -67,7 +67,7 @@ public class Reach extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.reachVL, cc.reachActions); if (cancel) // If we should cancel, remember the current time too. diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/Speed.java b/src/fr/neatmonster/nocheatplus/checks/fight/Speed.java index a46c0d5e..ec4c74fb 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/Speed.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/Speed.java @@ -5,6 +5,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.utilities.LagMeasureTask; /* @@ -60,7 +61,7 @@ public class Speed extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.speedVL, cc.speedActions); } return cancel; @@ -70,10 +71,10 @@ public class Speed extends Check { * @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player) */ @Override - public String getParameter(final ParameterName wildcard, final Player player) { + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { if (wildcard == ParameterName.LIMIT) - return String.valueOf(Math.round(FightConfig.getConfig(player).speedLimit)); + return String.valueOf(Math.round(FightConfig.getConfig(violationData.player).speedLimit)); else - return super.getParameter(wildcard, player); + return super.getParameter(wildcard, violationData); } } diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/Drop.java b/src/fr/neatmonster/nocheatplus/checks/inventory/Drop.java index edeb1a6d..004755dc 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/Drop.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/Drop.java @@ -60,7 +60,7 @@ public class Drop extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.dropVL, cc.dropActions); } return cancel; diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java b/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java index 3ae9c92d..01f149a8 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java @@ -55,7 +55,7 @@ public class InstantBow extends Check { // Execute whatever actions are associated with this check and the // violation level and find out if we should cancel the event - cancel = executeActions(player); + cancel = executeActions(player, data.instantBowVL, InventoryConfig.getConfig(player).instantBowActions); } return cancel; diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/InstantEat.java b/src/fr/neatmonster/nocheatplus/checks/inventory/InstantEat.java index a55d9fea..1485861e 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/InstantEat.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/InstantEat.java @@ -5,6 +5,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.ViolationData; /* * M""M dP dP MM""""""""`M dP @@ -60,7 +61,7 @@ public class InstantEat extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - cancel = executeActions(player); + cancel = executeActions(player, data.instantEatVL, InventoryConfig.getConfig(player).instantEatActions); } return cancel; @@ -70,10 +71,10 @@ public class InstantEat extends Check { * @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player) */ @Override - public String getParameter(final ParameterName wildcard, final Player player) { + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { if (wildcard == ParameterName.FOOD) - return InventoryData.getData(player).instantEatFood.toString(); + return InventoryData.getData(violationData.player).instantEatFood.toString(); else - return super.getParameter(wildcard, player); + return super.getParameter(wildcard, violationData); } } diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryConfig.java b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryConfig.java index 9f606fa7..06d5c991 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryConfig.java @@ -6,6 +6,9 @@ import java.util.Map; import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.types.ActionList; +import fr.neatmonster.nocheatplus.checks.CheckConfig; +import fr.neatmonster.nocheatplus.checks.CheckConfigFactory; +import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; @@ -34,7 +37,14 @@ import fr.neatmonster.nocheatplus.players.Permissions; * Configurations specific for the "inventory" checks. Every world gets one of these assigned to it, or if a world * doesn't get it's own, it will use the "global" version. */ -public class InventoryConfig { +public class InventoryConfig implements CheckConfig { + + public static final CheckConfigFactory factory = new CheckConfigFactory(){ + @Override + public final CheckConfig getConfig(final Player player) { + return InventoryConfig.getConfig(player); + } + }; /** The map containing the configurations per world. */ private static Map worldsMap = new HashMap(); @@ -74,8 +84,8 @@ public class InventoryConfig { /** * Instantiates a new inventory configuration. * - * @param data - * the data + * @param dataFactory + * the dataFactory */ public InventoryConfig(final ConfigFile data) { dropCheck = data.getBoolean(ConfPaths.INVENTORY_DROP_CHECK); @@ -91,4 +101,20 @@ public class InventoryConfig { instantEatActions = data .getActionList(ConfPaths.INVENTORY_INSTANTEAT_ACTIONS, Permissions.INVENTORY_INSTANTEAT); } + + @Override + public final boolean isEnabled(final CheckType checkType) { + switch(checkType){ + case INVENTORY_DROP: + return dropCheck; + case INVENTORY_INSTANTBOW: + return instantBowCheck; + case INVENTORY_INSTANTEAT: + return instantEatCheck; + default: + return true; + } + } + + } diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java index 4a437b26..e33894bb 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java @@ -6,6 +6,9 @@ import java.util.Map; import org.bukkit.Material; import org.bukkit.entity.Player; +import fr.neatmonster.nocheatplus.checks.CheckData; +import fr.neatmonster.nocheatplus.checks.CheckDataFactory; + /* * M""M dP M""""""'YMM dP * M M 88 M mmmm. `M 88 @@ -17,19 +20,26 @@ import org.bukkit.entity.Player; * d8888P */ /** - * Player specific data for the inventory checks. + * Player specific dataFactory for the inventory checks. */ -public class InventoryData { +public class InventoryData implements CheckData { + + public static final CheckDataFactory factory = new CheckDataFactory(){ + @Override + public final CheckData getData(final Player player) { + return InventoryData.getData(player); + } + }; - /** The map containing the data per players. */ + /** The map containing the dataFactory per players. */ private static Map playersMap = new HashMap(); /** - * Gets the data of a specified player. + * Gets the dataFactory of a specified player. * * @param player * the player - * @return the data + * @return the dataFactory */ public static InventoryData getData(final Player player) { if (!playersMap.containsKey(player.getName())) diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java index c1ac8424..5bffb587 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java @@ -150,7 +150,7 @@ public class InventoryListener implements Listener { data.instantEatFood = event.getItem().getType(); data.instantEatLastTime = System.currentTimeMillis(); } else { - // Nothing that we are interested in, reset data. + // Nothing that we are interested in, reset dataFactory. data.instantBowLastTime = 0; data.instantEatLastTime = 0; data.instantEatFood = null; diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java b/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java index a9649dda..8f0b4c15 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java @@ -12,6 +12,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.utilities.PlayerLocation; /* @@ -133,7 +134,7 @@ public class CreativeFly extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we // should // cancel the event. - if (executeActions(player)) + if (executeActions(player, data.creativeFlyVL, cc.creativeFlyActions)) // Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" // to allow the player to look somewhere else despite getting pulled back by NoCheatPlus. return new Location(player.getWorld(), data.setBack.getX(), data.setBack.getY(), @@ -156,8 +157,8 @@ public class CreativeFly extends Check { * org.bukkit.entity.Player) */ @Override - public String getParameter(final ParameterName wildcard, final Player player) { - final MovingData data = MovingData.getData(player); + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { + final MovingData data = MovingData.getData(violationData.player); if (wildcard == ParameterName.LOCATION_FROM) return String.format(Locale.US, "%.2f, %.2f, %.2f", data.from.getX(), data.from.getY(), data.from.getZ()); else if (wildcard == ParameterName.LOCATION_TO) @@ -165,6 +166,6 @@ public class CreativeFly extends Check { else if (wildcard == ParameterName.DISTANCE) return String.format(Locale.US, "%.2f", data.to.subtract(data.from).lengthSquared()); else - return super.getParameter(wildcard, player); + return super.getParameter(wildcard, violationData); } } diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java b/src/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java index 9f423e01..d7bdf1f1 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.utilities.PlayerLocation; /* @@ -79,7 +80,7 @@ public class MorePackets extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - if (executeActions(player)) + if (executeActions(player, data.morePacketsVL, MovingConfig.getConfig(player).morePacketsActions)) newTo = data.teleported = data.morePacketsSetback; } @@ -121,10 +122,10 @@ public class MorePackets extends Check { * org.bukkit.entity.Player) */ @Override - public String getParameter(final ParameterName wildcard, final Player player) { + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { if (wildcard == ParameterName.PACKETS) - return String.valueOf(MovingData.getData(player).morePacketsPackets); + return String.valueOf(MovingData.getData(violationData.player).morePacketsPackets); else - return super.getParameter(wildcard, player); + return super.getParameter(wildcard, violationData); } } diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MorePacketsVehicle.java b/src/fr/neatmonster/nocheatplus/checks/moving/MorePacketsVehicle.java index de899ef7..89bf7f1b 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MorePacketsVehicle.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MorePacketsVehicle.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.ViolationData; /* * M"""""`'"""`YM MM"""""""`YM dP dP @@ -78,7 +79,7 @@ public class MorePacketsVehicle extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - if (executeActions(player)) + if (executeActions(player, data.morePacketsVehicleVL, MovingConfig.getConfig(player).morePacketsVehicleActions)) newTo = data.morePacketsVehicleSetback; } @@ -120,10 +121,10 @@ public class MorePacketsVehicle extends Check { * org.bukkit.entity.Player) */ @Override - public String getParameter(final ParameterName wildcard, final Player player) { + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { if (wildcard == ParameterName.PACKETS) - return String.valueOf(MovingData.getData(player).morePacketsVehiclePackets); + return String.valueOf(MovingData.getData(violationData.player).morePacketsVehiclePackets); else - return super.getParameter(wildcard, player); + return super.getParameter(wildcard, violationData); } } diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java index 0aa0b788..941d670a 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java @@ -6,6 +6,9 @@ import java.util.Map; import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.types.ActionList; +import fr.neatmonster.nocheatplus.checks.CheckConfig; +import fr.neatmonster.nocheatplus.checks.CheckConfigFactory; +import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; @@ -24,7 +27,14 @@ import fr.neatmonster.nocheatplus.players.Permissions; /** * Configurations specific for the moving checks. Every world gets one of these assigned to it. */ -public class MovingConfig { +public class MovingConfig implements CheckConfig { + + public static final CheckConfigFactory factory = new CheckConfigFactory(){ + @Override + public final CheckConfig getConfig(final Player player) { + return MovingConfig.getConfig(player); + } + }; /** The map containing the configurations per world. */ private static Map worldsMap = new HashMap(); @@ -81,8 +91,8 @@ public class MovingConfig { /** * Instantiates a new moving configuration. * - * @param data - * the data + * @param dataFactory + * the dataFactory */ public MovingConfig(final ConfigFile data) { creativeFlyCheck = data.getBoolean(ConfPaths.MOVING_CREATIVEFLY_CHECK); @@ -115,4 +125,22 @@ public class MovingConfig { survivalFlyWaterSpeed = data.getInt(ConfPaths.MOVING_SURVIVALFLY_WATERSPEED, 100); survivalFlyActions = data.getActionList(ConfPaths.MOVING_SURVIVALFLY_ACTIONS, Permissions.MOVING_SURVIVALFLY); } + + @Override + public final boolean isEnabled(final CheckType checkType) { + switch(checkType){ + case MOVING_NOFALL: + return noFallCheck; + case MOVING_SURVIVALFLY: + return survivalFlyCheck; + case MOVING_MOREPACKETS: + return morePacketsCheck; + case MOVING_MOREPACKETSVEHICLE: + return morePacketsVehicleCheck; + case MOVING_CREATIVEFLY: + return creativeFlyCheck; + default: + return true; + } + } } diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index 92132923..2c180f95 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -6,6 +6,9 @@ import java.util.Map; import org.bukkit.Location; import org.bukkit.entity.Player; +import fr.neatmonster.nocheatplus.checks.CheckData; +import fr.neatmonster.nocheatplus.checks.CheckDataFactory; + /* * M"""""`'"""`YM oo M""""""'YMM dP * M mm. mm. M M mmmm. `M 88 @@ -17,19 +20,26 @@ import org.bukkit.entity.Player; * d8888P */ /** - * Player specific data for the moving checks. + * Player specific dataFactory for the moving checks. */ -public class MovingData { +public class MovingData implements CheckData { + + public static final CheckDataFactory factory = new CheckDataFactory(){ + @Override + public final CheckData getData(final Player player) { + return MovingData.getData(player); + } + }; - /** The map containing the data per players. */ + /** The map containing the dataFactory per players. */ private static Map playersMap = new HashMap(); /** - * Gets the data of a specified player. + * Gets the dataFactory of a specified player. * * @param player * the player - * @return the data + * @return the dataFactory */ public static MovingData getData(final Player player) { if (!playersMap.containsKey(player.getName())) @@ -91,7 +101,7 @@ public class MovingData { public Location teleported; /** - * Clear the data of the fly checks. + * Clear the dataFactory of the fly checks. */ public void clearFlyData() { bunnyhopDelay = 0; @@ -102,7 +112,7 @@ public class MovingData { } /** - * Clear the data of the more packets checks. + * Clear the dataFactory of the more packets checks. */ public void clearMorePacketsData() { morePacketsSetback = null; diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index a1d985ea..16c7b92c 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -176,7 +176,7 @@ public class MovingListener implements Listener { } /** - * Just for security, if a player switches between worlds, reset the fly and more packets checks data, because it is + * Just for security, if a player switches between worlds, reset the fly and more packets checks dataFactory, because it is * definitely invalid now. * * @param event @@ -277,7 +277,7 @@ public class MovingListener implements Listener { final Player player = event.getPlayer(); // Don't care for movements that are very high distance, to another world (such that it is very likely the event - // data was modified by another plugin before we got it) or if the player is inside a vehicle. + // dataFactory was modified by another plugin before we got it) or if the player is inside a vehicle. if (!event.getFrom().getWorld().equals(event.getTo().getWorld()) || event.getFrom().distanceSquared(event.getTo()) > 400D || player.isInsideVehicle()) return; @@ -285,7 +285,7 @@ public class MovingListener implements Listener { final MovingData data = MovingData.getData(player); // Just try to estimate velocities over time. Not very precise, but works good enough most of the time. Do - // general data modifications one for each event. + // general dataFactory modifications one for each event. if (data.horizontalVelocityCounter > 0D) data.horizontalVelocityCounter--; else if (data.horizontalFreedom > 0.001D) @@ -323,14 +323,14 @@ public class MovingListener implements Listener { // If he is handled by the no fall check, execute it. noFall.check(player, from, to); } else - // He isn't handled by any fly check, clear his data. + // He isn't handled by any fly check, clear his dataFactory. data.clearFlyData(); if (newTo == null && morePackets.isEnabled(player)) // If he hasn't been stopped by any other check and is handled by the more packets check, execute it. newTo = morePackets.check(player, from, to); else - // Otherwise we need to clear his data. + // Otherwise we need to clear his dataFactory. data.clearMorePacketsData(); // Did one of the checks decide we need a new "to"-location? @@ -388,9 +388,9 @@ public class MovingListener implements Listener { /** * If a player gets teleported, it may have two reasons. Either it was NoCheat or another plugin. If it was - * NoCheatPlus, the target location should match the "data.teleportedTo" value. + * NoCheatPlus, the target location should match the "dataFactory.teleportedTo" value. * - * On teleports, reset some movement related data that gets invalid. + * On teleports, reset some movement related dataFactory that gets invalid. * * @param event * the event @@ -413,11 +413,11 @@ public class MovingListener implements Listener { if (data.teleported != null && data.teleported.equals(event.getTo())) event.setCancelled(false); else - // Only if it wasn't NoCheatPlus, drop data from more packets check. If it was NoCheatPlus, we don't want - // players to exploit the fly check teleporting to get rid of the "morepackets" data. + // Only if it wasn't NoCheatPlus, drop dataFactory from more packets check. If it was NoCheatPlus, we don't want + // players to exploit the fly check teleporting to get rid of the "morepackets" dataFactory. data.clearMorePacketsData(); - // Always drop data from fly checks, as it always loses its validity after teleports. Always! + // Always drop dataFactory from fly checks, as it always loses its validity after teleports. Always! data.teleported = null; data.clearFlyData(); } @@ -476,7 +476,7 @@ public class MovingListener implements Listener { * \_/ \___|_| |_|_|\___|_|\___| |_| |_|\___/ \_/ \___| */ // Don't care if a player isn't inside the vehicle, for movements that are very high distance or to another - // world (such that it is very likely the event data was modified by another plugin before we got it). + // world (such that it is very likely the event dataFactory was modified by another plugin before we got it). if (event.getVehicle().getPassenger() == null || !(event.getVehicle().getPassenger() instanceof Player) || !event.getFrom().getWorld().equals(event.getTo().getWorld()) || event.getFrom().distanceSquared(event.getTo()) > 400D) @@ -490,7 +490,7 @@ public class MovingListener implements Listener { // If the player is handled by the more packets vehicle check, execute it. newTo = morePacketsVehicle.check(player, event.getFrom(), event.getTo()); else - // Otherwise we need to clear his data. + // Otherwise we need to clear his dataFactory. MovingData.getData(player).clearMorePacketsData(); // Did one of the checks decide we need a new "to"-location? diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java b/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java index a4282f32..be08f978 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java @@ -9,6 +9,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.utilities.PlayerLocation; /* @@ -69,7 +70,7 @@ public class NoFall extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - if (executeActions(player)) + if (executeActions(player, data.noFallVL, cc.noFallActions)) // Deal fall damages to the player. ((CraftPlayer) player).getHandle().b(0D, true); data.noFallDistance = 0F; @@ -91,7 +92,7 @@ public class NoFall extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. If "cancelled", the fall damage gets dealt in a way that's visible to other plugins. - if (executeActions(player)) + if (executeActions(player, data.noFallVL, cc.noFallActions)) // Increase the fall distance a bit. :) player.setFallDistance(data.noFallDistance + difference); data.noFallDistance = 0F; @@ -126,10 +127,10 @@ public class NoFall extends Check { * org.bukkit.entity.Player) */ @Override - public String getParameter(final ParameterName wildcard, final Player player) { + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { if (wildcard == ParameterName.FALL_DISTANCE) - return String.format(Locale.US, "%.2f", MovingData.getData(player).noFallDistance); + return String.format(Locale.US, "%.2f", MovingData.getData(violationData.player).noFallDistance); else - return super.getParameter(wildcard, player); + return super.getParameter(wildcard, violationData); } } diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index ba3f1c09..2335b67f 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -12,6 +12,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.players.Permissions; import fr.neatmonster.nocheatplus.utilities.PlayerLocation; @@ -118,7 +119,7 @@ public class SurvivalFly extends Check { data.survivalFlyVL += 100D; // And return if we need to do something or not. - return executeActions(player); + return executeActions(player, data.survivalFlyVL, MovingConfig.getConfig(player).survivalFlyActions); } else // He has, everything is alright. data.survivalFlyWasInBed = false; @@ -326,7 +327,7 @@ public class SurvivalFly extends Check { // If the other plugins haven't decided to cancel the execution of the actions, then do it. If one of the // actions was a cancel, cancel it. - if (executeActions(player)) + if (executeActions(player, data.survivalFlyVL, MovingConfig.getConfig(player).survivalFlyActions)) // Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" to // allow the player to look somewhere else despite getting pulled back by NoCheatPlus. return new Location(player.getWorld(), data.setBack.getX(), data.setBack.getY(), data.setBack.getZ(), @@ -368,8 +369,8 @@ public class SurvivalFly extends Check { * org.bukkit.entity.Player) */ @Override - public String getParameter(final ParameterName wildcard, final Player player) { - final MovingData data = MovingData.getData(player); + public String getParameter(final ParameterName wildcard, final ViolationData violationData) { + final MovingData data = MovingData.getData(violationData.player); if (wildcard == ParameterName.LOCATION_FROM) return String.format(Locale.US, "%.2f, %.2f, %.2f", data.from.getX(), data.from.getY(), data.from.getZ()); else if (wildcard == ParameterName.LOCATION_TO) @@ -377,6 +378,6 @@ public class SurvivalFly extends Check { else if (wildcard == ParameterName.DISTANCE) return String.format(Locale.US, "%.2f", data.to.subtract(data.from).lengthSquared()); else - return super.getParameter(wildcard, player); + return super.getParameter(wildcard, violationData); } } diff --git a/src/fr/neatmonster/nocheatplus/config/ConfigFile.java b/src/fr/neatmonster/nocheatplus/config/ConfigFile.java index b0d6e344..a1378391 100644 --- a/src/fr/neatmonster/nocheatplus/config/ConfigFile.java +++ b/src/fr/neatmonster/nocheatplus/config/ConfigFile.java @@ -41,7 +41,7 @@ public class ConfigFile extends YamlConfiguration { } /** - * Do this after reading new data. + * Do this after reading new dataFactory. */ public void regenerateActionLists() { factory = new ActionFactory(((MemorySection) this.get(ConfPaths.STRINGS)).getValues(false)); diff --git a/src/fr/neatmonster/nocheatplus/config/ConfigManager.java b/src/fr/neatmonster/nocheatplus/config/ConfigManager.java index 3096ebd1..d17cd038 100644 --- a/src/fr/neatmonster/nocheatplus/config/ConfigManager.java +++ b/src/fr/neatmonster/nocheatplus/config/ConfigManager.java @@ -130,7 +130,7 @@ public class ConfigManager { public static void init(final NoCheatPlus plugin) { // First try to obtain and parse the global configuration file. final File folder = plugin.getDataFolder(); - final File globalFile = new File(folder, "config.yml"); + final File globalFile = new File(folder, "configFactory.yml"); final ConfigFile global = new ConfigFile(); global.setDefaults(new DefaultConfig()); diff --git a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 953d23d6..129e56f8 100644 --- a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -12,7 +12,7 @@ package fr.neatmonster.nocheatplus.config; */ /** * These are the default settings for NoCheatPlus. They will be used in addition to/in replacement of configurations - * given in the config.yml file. + * given in the configFactory.yml file. */ public class DefaultConfig extends ConfigFile { diff --git a/src/fr/neatmonster/nocheatplus/players/ExecutionHistory.java b/src/fr/neatmonster/nocheatplus/players/ExecutionHistory.java index d0244f52..4137ed41 100644 --- a/src/fr/neatmonster/nocheatplus/players/ExecutionHistory.java +++ b/src/fr/neatmonster/nocheatplus/players/ExecutionHistory.java @@ -130,7 +130,7 @@ public class ExecutionHistory { } } - /** Store data between events (time + action + action-counter). **/ + /** Store dataFactory between events (time + action + action-counter). **/ private final Map> executionHistories; /**