From a0024d0737adbfc4967359667ddae8c123844266 Mon Sep 17 00:00:00 2001 From: Evenprime Date: Fri, 14 Oct 2011 18:44:56 +0200 Subject: [PATCH] Refactoring, code cleanup, moved executionHistories to "data" --- .../co/evenprime/bukkit/nocheat/NoCheat.java | 11 +++- ...ActionExecutor.java => ActionManager.java} | 39 +++++-------- .../nocheat/actions/types/LogAction.java | 4 +- .../checks/blockbreak/BlockBreakCheck.java | 6 +- .../checks/blockbreak/DirectionCheck.java | 15 ++--- .../nocheat/checks/blockbreak/ReachCheck.java | 7 +-- .../checks/blockplace/BlockPlaceCheck.java | 6 +- .../checks/blockplace/OnLiquidCheck.java | 7 +-- .../nocheat/checks/blockplace/ReachCheck.java | 7 +-- .../bukkit/nocheat/checks/chat/ChatCheck.java | 7 +-- .../nocheat/checks/fight/FightCheck.java | 12 ++-- .../nocheat/checks/moving/FlyingCheck.java | 9 +-- .../checks/moving/MorePacketsCheck.java | 12 ++-- .../checks/moving/MovingEventHelper.java | 20 +++---- .../nocheat/checks/moving/NoFallCheck.java | 55 ++++++++++--------- .../nocheat/checks/moving/RunningCheck.java | 15 ++--- .../bukkit/nocheat/config/Configuration.java | 7 +-- .../nocheat/config/ConfigurationManager.java | 1 + .../nocheat/config/DefaultConfiguration.java | 3 +- .../bukkit/nocheat/config/Explainations.java | 2 + .../bukkit/nocheat/config/FlatFileAction.java | 1 + .../nocheat/config/FlatFileConfiguration.java | 4 +- .../nocheat/config/cache/CCBlockBreak.java | 2 +- .../nocheat/config/cache/CCBlockPlace.java | 2 +- .../bukkit/nocheat/config/cache/CCChat.java | 2 +- .../bukkit/nocheat/config/cache/CCFight.java | 2 +- .../bukkit/nocheat/config/cache/CCMoving.java | 2 +- .../{actions => config/util}/ActionList.java | 12 ++-- .../config/{ => util}/ActionMapper.java | 2 +- .../nocheat/config/{ => util}/OptionNode.java | 2 +- .../ActionData.java} | 20 ++++--- .../bukkit/nocheat/data/BaseData.java | 35 ++++++------ .../bukkit/nocheat/data/BlockBreakData.java | 8 ++- .../bukkit/nocheat/data/BlockPlaceData.java | 6 +- .../bukkit/nocheat/data/ChatData.java | 6 +- .../evenprime/bukkit/nocheat/data/Data.java | 6 +- .../bukkit/nocheat/data/FightData.java | 8 +-- .../bukkit/nocheat/data/LogData.java | 4 +- .../bukkit/nocheat/data/MovingData.java | 41 +++++++------- 39 files changed, 199 insertions(+), 211 deletions(-) rename src/cc/co/evenprime/bukkit/nocheat/actions/{ActionExecutor.java => ActionManager.java} (58%) rename src/cc/co/evenprime/bukkit/nocheat/{actions => config/util}/ActionList.java (80%) rename src/cc/co/evenprime/bukkit/nocheat/config/{ => util}/ActionMapper.java (89%) rename src/cc/co/evenprime/bukkit/nocheat/config/{ => util}/OptionNode.java (92%) rename src/cc/co/evenprime/bukkit/nocheat/{actions/history/ActionHistory.java => data/ActionData.java} (91%) diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java index e6c5cf27..c9760fce 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java @@ -12,6 +12,7 @@ import org.bukkit.permissions.Permission; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; +import cc.co.evenprime.bukkit.nocheat.actions.ActionManager; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationManager; import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; @@ -46,6 +47,7 @@ public class NoCheat extends JavaPlugin { private LogManager log; private DataManager data; private PerformanceManager performance; + private ActionManager action; private final List eventManagers = new LinkedList(); @@ -89,6 +91,9 @@ public class NoCheat extends JavaPlugin { // Then set up the performance counters this.performance = new PerformanceManager(); + // Then set up the Action Manager + this.action = new ActionManager(this); + // Then set up the event listeners eventManagers.add(new PlayerMoveEventManager(this)); eventManagers.add(new PlayerTeleportEventManager(this)); @@ -114,7 +119,7 @@ public class NoCheat extends JavaPlugin { lastIngamesecondDuration = 1000; lastIngamesecondTime = time; ingameseconds++; - + // Check if some data is outdated now and let it be removed getDataManager().cleanDataMap(); } @@ -144,6 +149,10 @@ public class NoCheat extends JavaPlugin { return performance; } + public ActionManager getActionManager() { + return action; + } + public int getIngameSeconds() { return ingameseconds; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/ActionExecutor.java b/src/cc/co/evenprime/bukkit/nocheat/actions/ActionManager.java similarity index 58% rename from src/cc/co/evenprime/bukkit/nocheat/actions/ActionExecutor.java rename to src/cc/co/evenprime/bukkit/nocheat/actions/ActionManager.java index 34f7fc31..a59ac62d 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/ActionExecutor.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/ActionManager.java @@ -1,17 +1,15 @@ package cc.co.evenprime.bukkit.nocheat.actions; -import java.util.HashMap; -import java.util.Map; - import org.bukkit.entity.Player; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.actions.history.ActionHistory; import cc.co.evenprime.bukkit.nocheat.actions.types.Action; import cc.co.evenprime.bukkit.nocheat.actions.types.ConsolecommandAction; import cc.co.evenprime.bukkit.nocheat.actions.types.LogAction; import cc.co.evenprime.bukkit.nocheat.actions.types.SpecialAction; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; +import cc.co.evenprime.bukkit.nocheat.data.ActionData; import cc.co.evenprime.bukkit.nocheat.data.LogData; /** @@ -21,34 +19,32 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData; * @author Evenprime * */ -public class ActionExecutor { +public class ActionManager { - private final Map actionHistory = new HashMap(); - private final NoCheat plugin; + private final NoCheat plugin; - public ActionExecutor(NoCheat plugin) { + public ActionManager(NoCheat plugin) { this.plugin = plugin; } - public boolean executeActions(Player player, ActionList actions, int violationLevel, LogData data, ConfigurationCache cc) { + public boolean executeActions(Player player, ActionList actions, int violationLevel, LogData data, ActionData history, ConfigurationCache cc) { boolean special = false; // Always set this here "by hand" data.violationLevel = violationLevel; - long time = System.currentTimeMillis() / 1000; + final long time = System.currentTimeMillis() / 1000; for(Action ac : actions.getActions(violationLevel)) { - if(getHistory(player).executeAction(ac, time)) { + if(history.executeAction(ac, time)) { if(ac instanceof LogAction) { - LogAction l = (LogAction) ac; - plugin.getLogManager().log(l.level, l.getMessage(data), cc); + executeLogAction((LogAction) ac, data, cc); } else if(ac instanceof SpecialAction) { special = true; } else if(ac instanceof ConsolecommandAction) { - executeConsoleCommand(((ConsolecommandAction) ac).getCommand(data)); + executeConsoleCommand((ConsolecommandAction) ac, data); } } } @@ -56,19 +52,12 @@ public class ActionExecutor { return special; } - private ActionHistory getHistory(Player player) { - - ActionHistory history = actionHistory.get(player); - - if(history == null) { - history = new ActionHistory(); - actionHistory.put(player, history); - } - - return history; + private void executeLogAction(LogAction l, LogData data, ConfigurationCache cc) { + plugin.getLogManager().log(l.level, l.getMessage(data), cc); } - private void executeConsoleCommand(String command) { + private void executeConsoleCommand(ConsolecommandAction action, LogData data) { + String command = action.getCommand(data); try { plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command); } catch(Exception e) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java b/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java index f3e0fd3a..9710efdf 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java @@ -12,13 +12,13 @@ import cc.co.evenprime.bukkit.nocheat.log.LogLevel; public class LogAction extends ActionWithParameters { public final LogLevel level; - + public LogAction(String name, int delay, int repeat, LogLevel level, String message) { super(name, delay, repeat, message); this.level = level; } - + public String getMessage(LogData ldata) { return super.getMessage(ldata); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheck.java index 5355e97b..8d2d8a59 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheck.java @@ -11,9 +11,9 @@ import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData; /** - * The main Check class for blockbreak event checking. It will decide which checks - * need to be executed and in which order. It will also precalculate some values - * that are needed by multiple checks. + * The main Check class for blockbreak event checking. It will decide which + * checks need to be executed and in which order. It will also precalculate + * some values that are needed by multiple checks. * * @author Evenprime * diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/DirectionCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/DirectionCheck.java index 9500cc4f..e97d6cd8 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/DirectionCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/DirectionCheck.java @@ -1,11 +1,10 @@ package cc.co.evenprime.bukkit.nocheat.checks.blockbreak; -import org.bukkit.block.Block; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData; import cc.co.evenprime.bukkit.nocheat.data.LogData; @@ -19,12 +18,10 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData; */ public class DirectionCheck { - private final ActionExecutor action; - private final NoCheat plugin; + private final NoCheat plugin; public DirectionCheck(NoCheat plugin) { this.plugin = plugin; - this.action = new ActionExecutor(plugin); } public boolean check(Player player, double factor, double x1, double y1, double z1, Block brokenBlock, BlockBreakData data, ConfigurationCache cc) { @@ -33,9 +30,9 @@ public class DirectionCheck { if(!cc.blockbreak.checkinstabreakblocks && brokenBlock.getLocation().equals(data.instaBrokeBlockLocation)) { return false; } - + boolean cancel = false; - + Vector direction = player.getEyeLocation().getDirection(); final double x2 = x1 + 2; final double y2 = y1 + 2; @@ -50,10 +47,10 @@ public class DirectionCheck { data.directionViolationLevel += 1; // Prepare some event-specific values for logging and custom actions - LogData ldata = plugin.getDataManager().getData( player).log; + LogData ldata = plugin.getDataManager().getData(player).log; ldata.check = "blockbreak.direction"; - cancel = action.executeActions(player, cc.blockbreak.directionActions, (int) data.directionViolationLevel, ldata, cc); + cancel = plugin.getActionManager().executeActions(player, cc.blockbreak.directionActions, (int) data.directionViolationLevel, ldata, data.history, cc); } return cancel; diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/ReachCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/ReachCheck.java index 1f205fa1..69c3eb31 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/ReachCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/ReachCheck.java @@ -4,7 +4,6 @@ import org.bukkit.GameMode; import org.bukkit.entity.Player; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData; import cc.co.evenprime.bukkit.nocheat.data.LogData; @@ -18,12 +17,10 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData; */ public class ReachCheck { - private final NoCheat plugin; - private final ActionExecutor action; + private final NoCheat plugin; public ReachCheck(NoCheat plugin) { this.plugin = plugin; - this.action = new ActionExecutor(plugin); } public boolean check(Player player, double distance, BlockBreakData data, ConfigurationCache cc) { @@ -41,7 +38,7 @@ public class ReachCheck { ldata.check = "blockbreak.reach"; ldata.reachdistance = distance; - cancel = action.executeActions(player, cc.blockbreak.reachActions, (int) data.reachViolationLevel, ldata, cc); + cancel = plugin.getActionManager().executeActions(player, cc.blockbreak.reachActions, (int) data.reachViolationLevel, ldata, data.history, cc); } else { data.reachViolationLevel *= 0.9D; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheck.java index 9bc40486..5ea6daad 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheck.java @@ -15,11 +15,11 @@ import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData; */ public class BlockPlaceCheck { - private final ReachCheck reachCheck; + private final ReachCheck reachCheck; private final OnLiquidCheck onLiquidCheck; public BlockPlaceCheck(NoCheat plugin) { - + reachCheck = new ReachCheck(plugin); onLiquidCheck = new OnLiquidCheck(plugin); } @@ -35,7 +35,7 @@ public class BlockPlaceCheck { if(!cancel && reach) { cancel = reachCheck.check(player, blockPlaced, blockPlacedAgainst, data, cc); } - + if(!cancel && onliquid) { cancel = onLiquidCheck.check(player, blockPlaced, blockPlacedAgainst, data, cc); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/OnLiquidCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/OnLiquidCheck.java index 725eb9c8..516e20df 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/OnLiquidCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/OnLiquidCheck.java @@ -6,7 +6,6 @@ import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData; import cc.co.evenprime.bukkit.nocheat.data.LogData; @@ -18,12 +17,10 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData; */ public class OnLiquidCheck { - private final NoCheat plugin; - private final ActionExecutor action; + private final NoCheat plugin; public OnLiquidCheck(NoCheat plugin) { this.plugin = plugin; - action = new ActionExecutor(plugin); } public boolean check(Player player, Block blockPlaced, Block blockPlacedAgainst, BlockPlaceData data, ConfigurationCache cc) { @@ -43,7 +40,7 @@ public class OnLiquidCheck { ldata.placed = blockPlaced; ldata.placedAgainst = blockPlacedAgainst; - cancel = action.executeActions(player, cc.blockplace.onliquidActions, (int) data.onliquidViolationLevel, ldata, cc); + cancel = plugin.getActionManager().executeActions(player, cc.blockplace.onliquidActions, (int) data.onliquidViolationLevel, ldata, data.history, cc); } data.onliquidViolationLevel *= 0.95D; // Reduce level over time diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/ReachCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/ReachCheck.java index aead2118..ebc46f4e 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/ReachCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/ReachCheck.java @@ -6,7 +6,6 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData; import cc.co.evenprime.bukkit.nocheat.data.LogData; @@ -20,12 +19,10 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData; */ public class ReachCheck { - private final NoCheat plugin; - private final ActionExecutor action; + private final NoCheat plugin; public ReachCheck(NoCheat plugin) { this.plugin = plugin; - this.action = new ActionExecutor(plugin); } public boolean check(Player player, Block blockPlaced, Block placedAgainstBlock, BlockPlaceData data, ConfigurationCache cc) { @@ -51,7 +48,7 @@ public class ReachCheck { ldata.check = "blockplace.reach"; ldata.reachdistance = distance; - cancel = action.executeActions(player, cc.blockplace.reachActions, (int) data.reachViolationLevel, ldata, cc); + cancel = plugin.getActionManager().executeActions(player, cc.blockplace.reachActions, (int) data.reachViolationLevel, ldata, data.history, cc); } else { data.reachViolationLevel *= 0.9D; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheck.java index 5f24be03..ba1620fe 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheck.java @@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.chat; import org.bukkit.entity.Player; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor; import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.ChatData; @@ -16,13 +15,11 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData; */ public class ChatCheck { - private final ActionExecutor action; - private final NoCheat plugin; + private final NoCheat plugin; public ChatCheck(NoCheat plugin) { this.plugin = plugin; - action = new ActionExecutor(plugin); } public boolean check(Player player, String message, ChatData data, ConfigurationCache cc) { @@ -51,7 +48,7 @@ public class ChatCheck { ldata.check = "chat.spam"; ldata.text = message; - cancel = action.executeActions(player, cc.chat.spamActions, data.messageCount - cc.chat.spamLimit, ldata, cc); + cancel = plugin.getActionManager().executeActions(player, cc.chat.spamActions, data.messageCount - cc.chat.spamLimit, ldata, data.history, cc); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheck.java index 6d2a50b0..99509213 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheck.java @@ -7,7 +7,6 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor; import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.FightData; @@ -19,13 +18,11 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData; */ public class FightCheck { - private final ActionExecutor action; - private final NoCheat plugin; + private final NoCheat plugin; public FightCheck(NoCheat plugin) { this.plugin = plugin; - action = new ActionExecutor(plugin); } public boolean check(Player player, Entity damagee, FightData data, ConfigurationCache cc) { @@ -35,7 +32,7 @@ public class FightCheck { boolean directionCheck = cc.fight.directionCheck && !player.hasPermission(Permissions.FIGHT_DIRECTION); long time = System.currentTimeMillis(); - + if(directionCheck) { Location eyes = player.getEyeLocation(); @@ -50,7 +47,8 @@ public class FightCheck { final double p = width / 2 + cc.fight.directionPrecision; final double h = height / 2 + cc.fight.directionPrecision; - // TODO: Move this into a seperate class to recycle it throughout NoCheat + // TODO: Move this into a seperate class to recycle it throughout + // NoCheat final double x1 = ((double) damagee.getLocation().getX()) - eyes.getX() - p; final double y1 = ((double) damagee.getLocation().getY()) - eyes.getY() - cc.fight.directionPrecision; final double z1 = ((double) damagee.getLocation().getZ()) - eyes.getZ() - p; @@ -77,7 +75,7 @@ public class FightCheck { LogData ldata = plugin.getDataManager().getData(player).log; ldata.check = "fight.direction"; - cancel = action.executeActions(player, cc.fight.directionActions, (int) data.violationLevel, ldata, cc); + cancel = plugin.getActionManager().executeActions(player, cc.fight.directionActions, (int) data.violationLevel, ldata, data.history, cc); if(cancel) { // Needed to calculate penalty times diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/FlyingCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/FlyingCheck.java index 9007346c..fec570b1 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/FlyingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/FlyingCheck.java @@ -6,7 +6,6 @@ import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.LogData; import cc.co.evenprime.bukkit.nocheat.data.MovingData; @@ -21,14 +20,12 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData; */ public class FlyingCheck { - private final NoCheat plugin; - private final ActionExecutor action; + private final NoCheat plugin; - private static final double creativeSpeed = 0.60D; + private static final double creativeSpeed = 0.60D; public FlyingCheck(NoCheat plugin) { this.plugin = plugin; - this.action = new ActionExecutor(plugin); } public Location check(Player player, Location from, Location to, ConfigurationCache cc, MovingData data) { @@ -88,7 +85,7 @@ public class FlyingCheck { ldata.toLocation = to; ldata.check = "flying/toofast"; - boolean cancel = action.executeActions(player, cc.moving.flyingActions, (int) data.runflyViolationLevel, ldata, cc); + boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.flyingActions, (int) data.runflyViolationLevel, ldata, data.history, cc); // Was one of the actions a cancel? Then really do it if(cancel) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java index 4c99b0d6..b544130d 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java @@ -4,7 +4,6 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.LogData; import cc.co.evenprime.bukkit.nocheat.data.MovingData; @@ -23,14 +22,11 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData; */ public class MorePacketsCheck { - private final ActionExecutor action; - - private final static int packetsPerTimeframe = 22; - private final static int bufferLimit = 30; - private final NoCheat plugin; + private final static int packetsPerTimeframe = 22; + private final static int bufferLimit = 30; + private final NoCheat plugin; public MorePacketsCheck(NoCheat plugin) { - this.action = new ActionExecutor(plugin); this.plugin = plugin; } @@ -128,7 +124,7 @@ public class MorePacketsCheck { ldata.check = "moving/morepackets"; boolean cancel = false; - cancel = action.executeActions(player, cc.moving.morePacketsActions, (int) data.morePacketsViolationLevel, ldata, cc); + cancel = plugin.getActionManager().executeActions(player, cc.moving.morePacketsActions, (int) data.morePacketsViolationLevel, ldata, data.history, cc); // Only do the cancel if the player didn't change worlds // inbetween diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingEventHelper.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingEventHelper.java index 6765d7ca..c29d2d05 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingEventHelper.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingEventHelper.java @@ -15,20 +15,20 @@ import org.bukkit.World; */ public class MovingEventHelper { - private final static double magic = 0.45D; - private final static double magic2 = 0.55D; + private final static double magic = 0.45D; + private final static double magic2 = 0.55D; // Block types that may need to be treated specially - private static final int NONSOLID = 1; // 0x00000001 - private static final int SOLID = 2; // 0x00000010 - private static final int LIQUID = 4 | NONSOLID; // 0x00000101 - private static final int LADDER = 8 | NONSOLID | SOLID; // 0x00001011 - private static final int FENCE = 16 | SOLID; // 0x00010000 - private static final int INGROUND = 128; - private static final int ONGROUND = 256; + private static final int NONSOLID = 1; // 0x00000001 + private static final int SOLID = 2; // 0x00000010 + private static final int LIQUID = 4 | NONSOLID; // 0x00000101 + private static final int LADDER = 8 | NONSOLID | SOLID; // 0x00001011 + private static final int FENCE = 16 | SOLID; // 0x00010000 + private static final int INGROUND = 128; + private static final int ONGROUND = 256; // Until I can think of a better way to determine if a block is solid or // not, this is what I'll do - public final int types[] = new int[256]; + public final int types[] = new int[256]; public MovingEventHelper() { // Find and define properties of all blocks diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/NoFallCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/NoFallCheck.java index e3728647..a5ce90a6 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/NoFallCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/NoFallCheck.java @@ -4,7 +4,6 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.LogData; import cc.co.evenprime.bukkit.nocheat.data.MovingData; @@ -18,12 +17,10 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData; */ public class NoFallCheck { - private final ActionExecutor action; - private final NoCheat plugin; + private final NoCheat plugin; public NoFallCheck(NoCheat plugin) { this.plugin = plugin; - this.action = new ActionExecutor(plugin); } /** @@ -41,59 +38,63 @@ public class NoFallCheck { data.fallDistance = 0F; } - // If we increased fall height before for no good reason, reduce now by the same amount + // If we increased fall height before for no good reason, reduce now by + // the same amount if(player.getFallDistance() > data.lastAddedFallDistance) { player.setFallDistance(player.getFallDistance() - data.lastAddedFallDistance); } - + data.lastAddedFallDistance = 0; - + // We want to know if the fallDistance recorded by the game is smaller - // than the fall distance recorded by the plugin + // than the fall distance recorded by the plugin float difference = data.fallDistance - player.getFallDistance(); - + if(difference > 1.0F && toOnOrInGround && data.fallDistance > 2.0F) { data.nofallViolationLevel += difference; - - // Prepare some event-specific values for logging and custom actions + + // Prepare some event-specific values for logging and custom actions LogData ldata = plugin.getDataManager().getData(player).log; ldata.falldistance = data.fallDistance; - ldata.check = "moving/nofall"; + ldata.check = "moving/nofall"; - boolean cancel = action.executeActions(player, cc.moving.nofallActions, (int) data.nofallViolationLevel, ldata, cc); - - // If "cancelled", the fall damage gets dealt in a way that's visible to other plugins - if(cancel) { + boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.nofallActions, (int) data.nofallViolationLevel, ldata, data.history, cc); + + // If "cancelled", the fall damage gets dealt in a way that's + // visible to other plugins + if(cancel) { // Increase the fall distance a bit :) float totalDistance = data.fallDistance + difference * (cc.moving.nofallMultiplier - 1.0F); - + player.setFallDistance(totalDistance); } data.fallDistance = 0F; } - // Increase the fall distance that is recorded by the plugin, AND set the fall distance of the player - // to whatever he would get with this move event. This modifies Minecrafts fall damage calculation - // slightly, but that's still better than ignoring players that try to use "teleports" or "stepdown" - // to avoid falldamage. It is only added for big height differences anyway, as to avoid to much deviation + // Increase the fall distance that is recorded by the plugin, AND set + // the fall distance of the player + // to whatever he would get with this move event. This modifies + // Minecrafts fall damage calculation + // slightly, but that's still better than ignoring players that try to + // use "teleports" or "stepdown" + // to avoid falldamage. It is only added for big height differences + // anyway, as to avoid to much deviation // from the original Minecraft feeling. if(oldY > newY) { float dist = (float) (oldY - newY); data.fallDistance += dist; - + if(dist > 1.0F) { data.lastAddedFallDistance = dist; player.setFallDistance(player.getFallDistance() + dist); - } - else { + } else { data.lastAddedFallDistance = 0.0F; } - } - else { + } else { data.lastAddedFallDistance = 0.0F; } - + // Reduce falldamage violation level data.nofallViolationLevel *= 0.99D; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunningCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunningCheck.java index a7a7fc84..b932a1ca 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunningCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunningCheck.java @@ -1,11 +1,10 @@ package cc.co.evenprime.bukkit.nocheat.checks.moving; - + import org.bukkit.Location; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor; import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.LogData; @@ -22,20 +21,18 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData; */ public class RunningCheck { - private final static double maxBonus = 1D; + private final static double maxBonus = 1D; // How many move events can a player have in air before he is expected to // lose altitude (or eventually land somewhere) - private final static int jumpingLimit = 6; + private final static int jumpingLimit = 6; - private final ActionExecutor action; - private final NoCheat plugin; + private final NoCheat plugin; - private final NoFallCheck noFallCheck; + private final NoFallCheck noFallCheck; public RunningCheck(NoCheat plugin, NoFallCheck noFallCheck) { this.plugin = plugin; - this.action = new ActionExecutor(plugin); this.noFallCheck = noFallCheck; } @@ -86,7 +83,7 @@ public class RunningCheck { else if(resultVert > 0) ldata.check = "runfly/vertical"; - boolean cancel = action.executeActions(player, cc.moving.actions, (int) data.runflyViolationLevel, ldata, cc); + boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.actions, (int) data.runflyViolationLevel, ldata, data.history, cc); // Was one of the actions a cancel? Then do it if(cancel) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java b/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java index 18aad0b2..cef2ce46 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java @@ -3,8 +3,9 @@ package cc.co.evenprime.bukkit.nocheat.config; import java.util.HashMap; import java.util.Map; -import cc.co.evenprime.bukkit.nocheat.actions.ActionList; -import cc.co.evenprime.bukkit.nocheat.config.OptionNode.DataType; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; +import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode; +import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode.DataType; import cc.co.evenprime.bukkit.nocheat.log.LogLevel; /** @@ -100,8 +101,6 @@ public abstract class Configuration { public static final OptionNode FIGHT_DIRECTION_PENALTYTIME = new OptionNode("penaltytime", FIGHT_DIRECTION, DataType.INTEGER); public final static OptionNode FIGHT_DIRECTION_ACTIONS = new OptionNode("actions", FIGHT_DIRECTION, DataType.ACTIONLIST); - - private final Map values; private final Configuration defaults; diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java b/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java index 8fac3a8c..ce6c9c46 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java @@ -16,6 +16,7 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper; /** * Central location for everything that's described in the configuration file(s) diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java index 19707f06..75624b4c 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java @@ -5,7 +5,8 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; -import cc.co.evenprime.bukkit.nocheat.actions.ActionList; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper; import cc.co.evenprime.bukkit.nocheat.log.LogLevel; /** diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java b/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java index 9bddd48e..8d566d9d 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java @@ -3,6 +3,8 @@ package cc.co.evenprime.bukkit.nocheat.config; import java.util.HashMap; import java.util.Map; +import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode; + /** * Textual explainations of options, will be displayed in the gui tool and the * descriptions.txt file. diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileAction.java b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileAction.java index 39b19bb9..9c7b8dc3 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileAction.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileAction.java @@ -12,6 +12,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action; import cc.co.evenprime.bukkit.nocheat.actions.types.ConsolecommandAction; import cc.co.evenprime.bukkit.nocheat.actions.types.LogAction; import cc.co.evenprime.bukkit.nocheat.actions.types.SpecialAction; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper; import cc.co.evenprime.bukkit.nocheat.log.LogLevel; public class FlatFileAction { diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java index 08e046dc..8f059f85 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java @@ -8,8 +8,10 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; -import cc.co.evenprime.bukkit.nocheat.actions.ActionList; import cc.co.evenprime.bukkit.nocheat.actions.types.Action; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper; +import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode; import cc.co.evenprime.bukkit.nocheat.log.LogLevel; public class FlatFileConfiguration extends Configuration { diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockBreak.java b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockBreak.java index f2308f28..8dcfd4d6 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockBreak.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockBreak.java @@ -1,7 +1,7 @@ package cc.co.evenprime.bukkit.nocheat.config.cache; -import cc.co.evenprime.bukkit.nocheat.actions.ActionList; import cc.co.evenprime.bukkit.nocheat.config.Configuration; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; /** * Configurations specific for the "BlockBreak" checks diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockPlace.java b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockPlace.java index 3261a014..d9382543 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockPlace.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockPlace.java @@ -1,7 +1,7 @@ package cc.co.evenprime.bukkit.nocheat.config.cache; -import cc.co.evenprime.bukkit.nocheat.actions.ActionList; import cc.co.evenprime.bukkit.nocheat.config.Configuration; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; /** * diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCChat.java b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCChat.java index d9684613..19608c6b 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCChat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCChat.java @@ -1,7 +1,7 @@ package cc.co.evenprime.bukkit.nocheat.config.cache; -import cc.co.evenprime.bukkit.nocheat.actions.ActionList; import cc.co.evenprime.bukkit.nocheat.config.Configuration; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; public class CCChat { diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCFight.java b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCFight.java index f20f9d80..14b9202f 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCFight.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCFight.java @@ -1,7 +1,7 @@ package cc.co.evenprime.bukkit.nocheat.config.cache; -import cc.co.evenprime.bukkit.nocheat.actions.ActionList; import cc.co.evenprime.bukkit.nocheat.config.Configuration; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; public class CCFight { diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCMoving.java b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCMoving.java index 273b0852..6c2bb220 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCMoving.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCMoving.java @@ -1,7 +1,7 @@ package cc.co.evenprime.bukkit.nocheat.config.cache; -import cc.co.evenprime.bukkit.nocheat.actions.ActionList; import cc.co.evenprime.bukkit.nocheat.config.Configuration; +import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; /** * Configurations specific for the Move Checks. Every world gets one of these diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/ActionList.java b/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionList.java similarity index 80% rename from src/cc/co/evenprime/bukkit/nocheat/actions/ActionList.java rename to src/cc/co/evenprime/bukkit/nocheat/config/util/ActionList.java index 3d253a48..b403f75b 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/ActionList.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionList.java @@ -1,4 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.actions; +package cc.co.evenprime.bukkit.nocheat.config.util; import java.util.ArrayList; import java.util.Collections; @@ -18,11 +18,11 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action; public class ActionList { public ActionList() {} - - private final static Action[] emptyArray = new Action[0]; - private final Map actions = new HashMap(); - private final List tresholds = new ArrayList(); + private final static Action[] emptyArray = new Action[0]; + + private final Map actions = new HashMap(); + private final List tresholds = new ArrayList(); /** * Add an entry to this actionList. The list will be sorted by tresholds @@ -52,7 +52,7 @@ public class ActionList { public Action[] getActions(Integer vl) { Integer result = null; - + for(Integer treshold : tresholds) { if(treshold <= vl) { result = treshold; diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/ActionMapper.java b/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionMapper.java similarity index 89% rename from src/cc/co/evenprime/bukkit/nocheat/config/ActionMapper.java rename to src/cc/co/evenprime/bukkit/nocheat/config/util/ActionMapper.java index 8c405b74..fc6288d2 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/ActionMapper.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionMapper.java @@ -1,4 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.config; +package cc.co.evenprime.bukkit.nocheat.config.util; import java.util.HashMap; import java.util.Map; diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/OptionNode.java b/src/cc/co/evenprime/bukkit/nocheat/config/util/OptionNode.java similarity index 92% rename from src/cc/co/evenprime/bukkit/nocheat/config/OptionNode.java rename to src/cc/co/evenprime/bukkit/nocheat/config/util/OptionNode.java index 5ba47ce3..8f996195 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/OptionNode.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/util/OptionNode.java @@ -1,4 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.config; +package cc.co.evenprime.bukkit.nocheat.config.util; import java.util.LinkedList; import java.util.List; diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/history/ActionHistory.java b/src/cc/co/evenprime/bukkit/nocheat/data/ActionData.java similarity index 91% rename from src/cc/co/evenprime/bukkit/nocheat/actions/history/ActionHistory.java rename to src/cc/co/evenprime/bukkit/nocheat/data/ActionData.java index c22d954e..ba69b26d 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/history/ActionHistory.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/ActionData.java @@ -1,4 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.actions.history; +package cc.co.evenprime.bukkit.nocheat.data; import java.util.HashMap; import java.util.Map; @@ -11,7 +11,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action; * @author Evenprime * */ -public class ActionHistory { +public class ActionData { private static class ExecutionHistoryEntry { @@ -34,7 +34,7 @@ public class ActionHistory { clearTimes(lastClearedTime + 1, time - lastClearedTime); lastClearedTime = time + 1; } - + executionTimes[(int) (time % executionTimes.length)]++; totalEntries++; } @@ -60,11 +60,11 @@ public class ActionHistory { if(j == executionTimes.length) { j = 0; } - + totalEntries -= executionTimes[j]; executionTimes[j] = 0; - j++; + j++; } } @@ -83,9 +83,11 @@ public class ActionHistory { // Store data between Events // time + action + action-counter - private final Map executionHistory = new HashMap(); + private final Map executionHistory; - public ActionHistory() {} + public ActionData() { + executionHistory = new HashMap(); + } /** * Returns true, if the action should be executed, because all time @@ -111,8 +113,8 @@ public class ActionHistory { entry.addCounter(time); if(entry.getCounter() > action.delay) { - // Execute action? - if(entry.getLastExecution() <= time - action.repeat) { + // Execute action? + if(entry.getLastExecution() <= time - action.repeat) { // Execute action! entry.setLastExecution(time); return true; diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/BaseData.java b/src/cc/co/evenprime/bukkit/nocheat/data/BaseData.java index 15ca32ba..cd239d1a 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/BaseData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/BaseData.java @@ -2,21 +2,19 @@ package cc.co.evenprime.bukkit.nocheat.data; import org.bukkit.entity.Player; - -public class BaseData { +public class BaseData extends Data { public final BlockBreakData blockbreak; public final BlockPlaceData blockplace; - public final ChatData chat; - public final LogData log; - public final MovingData moving; - public final FightData fight; - - private final Data[] data; - - private long removalTime; + public final ChatData chat; + public final LogData log; + public final MovingData moving; + public final FightData fight; + + private final Data[] data; + + private long removalTime; - public BaseData() { this.blockbreak = new BlockBreakData(); this.blockplace = new BlockPlaceData(); @@ -24,10 +22,11 @@ public class BaseData { this.log = new LogData(); this.moving = new MovingData(); this.fight = new FightData(); - + this.removalTime = 0; - - data = new Data[] { this.blockbreak, this.blockplace, this.chat, this.log, this.moving, this.fight }; + + data = new Data[] {this.blockbreak, this.blockplace, this.chat, + this.log, this.moving, this.fight}; } public void clearCriticalData() { @@ -41,17 +40,17 @@ public class BaseData { d.initialize(player); } } - + public void markForRemoval(boolean removal) { if(removal) { // 1 minute in the future this.removalTime = System.currentTimeMillis() + 60000; - } - else { + } else { this.removalTime = 0; } } - public boolean shouldBeRemoved() { + + public boolean shouldBeRemoved() { return removalTime != 0 && removalTime < System.currentTimeMillis(); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/BlockBreakData.java b/src/cc/co/evenprime/bukkit/nocheat/data/BlockBreakData.java index f7a490c8..6df6df3c 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/BlockBreakData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/BlockBreakData.java @@ -2,6 +2,7 @@ package cc.co.evenprime.bukkit.nocheat.data; import org.bukkit.Location; + /** * Playerspecific data for the blockbreak check group * @@ -10,9 +11,10 @@ import org.bukkit.Location; */ public class BlockBreakData extends Data { - public double reachViolationLevel = 0.0D; - public double directionViolationLevel = 0.0D; + public double reachViolationLevel = 0.0D; + public double directionViolationLevel = 0.0D; - public Location instaBrokeBlockLocation = null; + public Location instaBrokeBlockLocation = null; + public final ActionData history = new ActionData(); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/BlockPlaceData.java b/src/cc/co/evenprime/bukkit/nocheat/data/BlockPlaceData.java index 959a2758..7a386717 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/BlockPlaceData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/BlockPlaceData.java @@ -1,5 +1,6 @@ package cc.co.evenprime.bukkit.nocheat.data; + /** * * @author Evenprime @@ -7,6 +8,7 @@ package cc.co.evenprime.bukkit.nocheat.data; */ public class BlockPlaceData extends Data { - public double onliquidViolationLevel = 0.0D; - public double reachViolationLevel = 0.0D; + public double onliquidViolationLevel = 0.0D; + public double reachViolationLevel = 0.0D; + public final ActionData history = new ActionData(); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java b/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java index f5fad896..5c8dc499 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java @@ -1,5 +1,6 @@ package cc.co.evenprime.bukkit.nocheat.data; + /** * * @author Evenprime @@ -7,7 +8,8 @@ package cc.co.evenprime.bukkit.nocheat.data; */ public class ChatData extends Data { - public int messageCount = 0; - public int spamLasttime = 0; + public int messageCount = 0; + public int spamLasttime = 0; + public final ActionData history = new ActionData(); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/Data.java b/src/cc/co/evenprime/bukkit/nocheat/data/Data.java index 8461cff2..92cbf552 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/Data.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/Data.java @@ -7,15 +7,15 @@ import org.bukkit.entity.Player; * Every class that is extending this has to implement an empty Constructor() * * @author Evenprime - * + * */ public abstract class Data { public void initialize(Player player) { - + } public void clearCriticalData() { - + } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/FightData.java b/src/cc/co/evenprime/bukkit/nocheat/data/FightData.java index 844a6202..ecd764fe 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/FightData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/FightData.java @@ -1,9 +1,9 @@ package cc.co.evenprime.bukkit.nocheat.data; - public class FightData extends Data { - public double violationLevel = 0; - public long directionLastViolationTime = 0; - + public double violationLevel = 0; + public long directionLastViolationTime = 0; + public final ActionData history = new ActionData(); + } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/LogData.java b/src/cc/co/evenprime/bukkit/nocheat/data/LogData.java index ebf25fde..6ab1c1c0 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/LogData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/LogData.java @@ -22,7 +22,7 @@ public class LogData extends Data { public void initialize(Player player) { this.player = player; - check = ""; - toLocation = player.getLocation(); + this.check = ""; + this.toLocation = player.getLocation(); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/MovingData.java b/src/cc/co/evenprime/bukkit/nocheat/data/MovingData.java index 9a296fe5..8ae37ee8 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/MovingData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/MovingData.java @@ -3,38 +3,41 @@ package cc.co.evenprime.bukkit.nocheat.data; import org.bukkit.Location; import org.bukkit.entity.Player; + /** * Player specific data for the moving check group */ public class MovingData extends Data { - public int jumpPhase; + public int jumpPhase; - public Location runflySetBackPoint; + public Location runflySetBackPoint; - public double runflyViolationLevel; + public double runflyViolationLevel; - public double vertFreedom; - public double vertVelocity; - public int vertVelocityCounter; - public double horizFreedom; - public int horizVelocityCounter; + public double vertFreedom; + public double vertVelocity; + public int vertVelocityCounter; + public double horizFreedom; + public int horizVelocityCounter; - public double nofallViolationLevel; - public float fallDistance; - public float lastAddedFallDistance; + public double nofallViolationLevel; + public float fallDistance; + public float lastAddedFallDistance; - public double horizontalBuffer; - public int bunnyhopdelay; + public double horizontalBuffer; + public int bunnyhopdelay; - public int morePacketsCounter; - public int morePacketsBuffer; - public Location morePacketsSetbackPoint; - public double morePacketsViolationLevel; + public int morePacketsCounter; + public int morePacketsBuffer; + public Location morePacketsSetbackPoint; + public double morePacketsViolationLevel; - public Location teleportTo; + public Location teleportTo; - public int lastElapsedIngameSeconds; + public int lastElapsedIngameSeconds; + + public final ActionData history = new ActionData(); @Override public void initialize(Player player) {