diff --git a/src/cc/co/evenprime/bukkit/nocheat/ConfigItem.java b/src/cc/co/evenprime/bukkit/nocheat/ConfigItem.java new file mode 100644 index 00000000..ca2ab2ae --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/ConfigItem.java @@ -0,0 +1,5 @@ +package cc.co.evenprime.bukkit.nocheat; + +public interface ConfigItem { + +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/Data.java b/src/cc/co/evenprime/bukkit/nocheat/DataItem.java similarity index 57% rename from src/cc/co/evenprime/bukkit/nocheat/data/Data.java rename to src/cc/co/evenprime/bukkit/nocheat/DataItem.java index 4cd486da..6d7cd0a4 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/Data.java +++ b/src/cc/co/evenprime/bukkit/nocheat/DataItem.java @@ -1,4 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.data; +package cc.co.evenprime.bukkit.nocheat; import java.util.Map; @@ -7,11 +7,9 @@ import java.util.Map; * Every class that is extending this has to implement an empty Constructor() * */ -public abstract class Data { +public interface DataItem { - public void clearCriticalData() { - - } + public void clearCriticalData(); public abstract void collectData(Map map); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/EventManager.java b/src/cc/co/evenprime/bukkit/nocheat/EventManager.java index 710ac2ef..001367ef 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/EventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/EventManager.java @@ -2,9 +2,9 @@ package cc.co.evenprime.bukkit.nocheat; import java.util.List; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; public interface EventManager { - public List getActiveChecks(ConfigurationCache cc); + public List getActiveChecks(ConfigurationCacheStore cc); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java index 800bd855..946fb97f 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java @@ -12,22 +12,22 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; +import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.BlockBreakEventManager; +import cc.co.evenprime.bukkit.nocheat.checks.blockplace.BlockPlaceEventManager; +import cc.co.evenprime.bukkit.nocheat.checks.chat.ChatEventManager; +import cc.co.evenprime.bukkit.nocheat.checks.fight.FightEventManager; +import cc.co.evenprime.bukkit.nocheat.checks.inventory.InventoryEventManager; +import cc.co.evenprime.bukkit.nocheat.checks.moving.MovingEventManager; import cc.co.evenprime.bukkit.nocheat.command.CommandHandler; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationManager; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.PlayerManager; import cc.co.evenprime.bukkit.nocheat.debug.ActiveCheckPrinter; import cc.co.evenprime.bukkit.nocheat.debug.LagMeasureTask; import cc.co.evenprime.bukkit.nocheat.debug.Performance; import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager; import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType; -import cc.co.evenprime.bukkit.nocheat.events.BlockBreakEventManager; -import cc.co.evenprime.bukkit.nocheat.events.BlockPlaceEventManager; -import cc.co.evenprime.bukkit.nocheat.events.ChatEventManager; import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl; -import cc.co.evenprime.bukkit.nocheat.events.FightEventManager; -import cc.co.evenprime.bukkit.nocheat.events.InventoryEventManager; -import cc.co.evenprime.bukkit.nocheat.events.MovingEventManager; import cc.co.evenprime.bukkit.nocheat.events.WorkaroundsEventManager; import cc.co.evenprime.bukkit.nocheat.log.LogLevel; import cc.co.evenprime.bukkit.nocheat.log.LogManager; @@ -59,7 +59,7 @@ public class NoCheat extends JavaPlugin { public void onDisable() { PluginDescriptionFile pdfFile = this.getDescription(); - + if(taskId != -1) { getServer().getScheduler().cancelTask(taskId); taskId = -1; @@ -118,15 +118,15 @@ public class NoCheat extends JavaPlugin { log.logToConsole(LogLevel.LOW, "[NoCheat] version [" + this.getDescription().getVersion() + "] is enabled."); } - public ConfigurationCache getConfig(Player player) { + public ConfigurationCacheStore getConfig(Player player) { return conf.getConfigurationCacheForWorld(player.getWorld().getName()); } - public ConfigurationCache getConfig(World world) { + public ConfigurationCacheStore getConfig(World world) { return conf.getConfigurationCacheForWorld(world.getName()); } - public void log(LogLevel level, String message, ConfigurationCache cc) { + public void log(LogLevel level, String message, ConfigurationCacheStore cc) { log.log(level, message, cc); } @@ -141,12 +141,12 @@ public class NoCheat extends JavaPlugin { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { boolean result = CommandHandler.handleCommand(this, sender, command, label, args); - + if(!result && sender instanceof Player) { sender.sendMessage("Unknown command. Type \"help\" for help."); return true; } - + return result; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlayer.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlayer.java index 21382d8f..e06dc3b7 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlayer.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlayer.java @@ -2,8 +2,8 @@ package cc.co.evenprime.bukkit.nocheat; import org.bukkit.entity.Player; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; -import cc.co.evenprime.bukkit.nocheat.data.BaseData; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; +import cc.co.evenprime.bukkit.nocheat.data.DataStore; public interface NoCheatPlayer { @@ -13,15 +13,15 @@ public interface NoCheatPlayer { public Player getPlayer(); - public BaseData getData(); + public DataStore getDataStore(); public boolean isDead(); - + public boolean isSprinting(); public int getTicksLived(); - public ConfigurationCache getConfiguration(); + public ConfigurationCacheStore getConfigurationStore(); public float getSpeedAmplifier(); diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/NoCheatCommandSender.java b/src/cc/co/evenprime/bukkit/nocheat/actions/NoCheatCommandSender.java new file mode 100644 index 00000000..627f9b9e --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/NoCheatCommandSender.java @@ -0,0 +1,30 @@ +package cc.co.evenprime.bukkit.nocheat.actions; + +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.command.CommandSender; +import org.bukkit.permissions.PermissibleBase; + +public class NoCheatCommandSender extends PermissibleBase implements CommandSender { + + public NoCheatCommandSender() { + super(null); + } + + @Override + public String getName() { + return "NoCheatCommandSender"; + } + + @Override + public void sendMessage(String message) { + // We don't want to receive messages, as we can't do anything with them + // anyway + } + + @Override + public Server getServer() { + return Bukkit.getServer(); + } + +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/ParameterName.java b/src/cc/co/evenprime/bukkit/nocheat/actions/ParameterName.java index ad2cff2c..52b08c6a 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/ParameterName.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/ParameterName.java @@ -18,4 +18,4 @@ public enum ParameterName { return null; } -} \ No newline at end of file +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/types/DummyAction.java b/src/cc/co/evenprime/bukkit/nocheat/actions/types/DummyAction.java index ea34e209..35c10ab5 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/types/DummyAction.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/types/DummyAction.java @@ -3,8 +3,9 @@ package cc.co.evenprime.bukkit.nocheat.actions.types; import cc.co.evenprime.bukkit.nocheat.actions.Action; /** - * This is only used to not lose config entries in case an action isn't defined correctly - * + * This is only used to not lose config entries in case an action isn't defined + * correctly + * */ public class DummyAction extends Action { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/BlockBreakCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/BlockBreakCheck.java deleted file mode 100644 index 93ff8181..00000000 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/BlockBreakCheck.java +++ /dev/null @@ -1,23 +0,0 @@ -package cc.co.evenprime.bukkit.nocheat.checks; - -import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak; -import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; - -public abstract class BlockBreakCheck extends Check { - - public BlockBreakCheck(NoCheat plugin, String name, String permission) { - super(plugin, name, permission); - } - - public abstract boolean check(NoCheatPlayer player, BlockBreakData data, CCBlockBreak cc); - - public abstract boolean isEnabled(CCBlockBreak cc); - - @Override - protected final ExecutionHistory getHistory(NoCheatPlayer player) { - return player.getData().blockbreak.history; - } -} diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/ChatCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/ChatCheck.java deleted file mode 100644 index 7b29d52d..00000000 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/ChatCheck.java +++ /dev/null @@ -1,33 +0,0 @@ -package cc.co.evenprime.bukkit.nocheat.checks; - -import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat; -import cc.co.evenprime.bukkit.nocheat.data.ChatData; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; - -public abstract class ChatCheck extends Check { - - public ChatCheck(NoCheat plugin, String name, String permission) { - super(plugin, name, permission); - } - - public abstract boolean check(NoCheatPlayer player, ChatData data, CCChat cc); - - public abstract boolean isEnabled(CCChat cc); - - @Override - protected final ExecutionHistory getHistory(NoCheatPlayer player) { - return player.getData().chat.history; - } - - @Override - public String getParameter(ParameterName wildcard, NoCheatPlayer player) { - - if(wildcard == ParameterName.TEXT) - return player.getData().chat.message; - else - return super.getParameter(wildcard, player); - } -} diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java b/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java index 661e7181..7acbea7b 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java @@ -9,12 +9,13 @@ import org.bukkit.command.CommandSender; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.Action; +import cc.co.evenprime.bukkit.nocheat.actions.NoCheatCommandSender; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.actions.types.ConsolecommandAction; import cc.co.evenprime.bukkit.nocheat.actions.types.DummyAction; 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.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; public abstract class Check { @@ -45,7 +46,7 @@ public abstract class Check { final long time = System.currentTimeMillis() / 1000; - final ConfigurationCache cc = player.getConfiguration(); + final ConfigurationCacheStore cc = player.getConfigurationStore(); for(Action ac : actions) { if(getHistory(player).executeAction(ac, time)) { @@ -66,18 +67,18 @@ public abstract class Check { protected abstract ExecutionHistory getHistory(NoCheatPlayer player); - private final void executeLogAction(LogAction l, Check check, NoCheatPlayer player, ConfigurationCache cc) { + private final void executeLogAction(LogAction l, Check check, NoCheatPlayer player, ConfigurationCacheStore cc) { plugin.log(l.level, cc.logging.prefix + l.getLogMessage(player, check), cc); } - private final void executeConsoleCommand(ConsolecommandAction action, Check check, NoCheatPlayer player, ConfigurationCache cc) { + private final void executeConsoleCommand(ConsolecommandAction action, Check check, NoCheatPlayer player, ConfigurationCacheStore cc) { String command = ""; - + try { command = action.getCommand(player, check); plugin.getServer().dispatchCommand(noCheatCommandSender, command); } catch(CommandException e) { - System.out.println("[NoCheat] failed to execute the command '" + command + "': "+e.getMessage()+", please check if everything is setup correct. "); + System.out.println("[NoCheat] failed to execute the command '" + command + "': " + e.getMessage() + ", please check if everything is setup correct. "); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/CheckUtil.java b/src/cc/co/evenprime/bukkit/nocheat/checks/CheckUtil.java index 7995f922..2bb3d1a1 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/CheckUtil.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/CheckUtil.java @@ -150,14 +150,16 @@ public class CheckUtil { // Player can stand on and "in" lilipads types[Material.WATER_LILY.getId()] = SOLID | NONSOLID; - /*for(int i = 0; i < 256; i++) { - if(Block.byId[i] != null) { - System.out.println(Material.getMaterial(i) + - (isSolid(types[i]) ? " solid " : "") + (isNonSolid(types[i]) - ? " nonsolid " : "") + (isLiquid(types[i]) ? " liquid " : - "")); - } - }*/ + /* + * for(int i = 0; i < 256; i++) { + * if(Block.byId[i] != null) { + * System.out.println(Material.getMaterial(i) + + * (isSolid(types[i]) ? " solid " : "") + (isNonSolid(types[i]) + * ? " nonsolid " : "") + (isLiquid(types[i]) ? " liquid " : + * "")); + * } + * } + */ } /** @@ -250,7 +252,7 @@ public class CheckUtil { return INGROUND; } } - + // Last simple case: Player touches liquid if(isLiquid(base) || isLiquid(top)) { return LIQUID | INGROUND; diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/FightCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/FightCheck.java deleted file mode 100644 index d633b6f1..00000000 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/FightCheck.java +++ /dev/null @@ -1,27 +0,0 @@ -package cc.co.evenprime.bukkit.nocheat.checks; - -import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; -import cc.co.evenprime.bukkit.nocheat.data.FightData; - -/** - * Check various things related to fighting players/entities - * - */ -public abstract class FightCheck extends Check { - - public FightCheck(NoCheat plugin, String name, String permission) { - super(plugin, name, permission); - } - - public abstract boolean check(NoCheatPlayer player, FightData data, CCFight cc); - - public abstract boolean isEnabled(CCFight cc); - - @Override - protected final ExecutionHistory getHistory(NoCheatPlayer player) { - return player.getData().fight.history; - } -} diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/InventoryCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/InventoryCheck.java deleted file mode 100644 index e85b6c69..00000000 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/InventoryCheck.java +++ /dev/null @@ -1,24 +0,0 @@ -package cc.co.evenprime.bukkit.nocheat.checks; - -import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCInventory; -import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; -import cc.co.evenprime.bukkit.nocheat.data.InventoryData; - - -public abstract class InventoryCheck extends Check { - - public InventoryCheck(NoCheat plugin, String name, String permission) { - super(plugin, name, permission); - } - - public abstract boolean check(NoCheatPlayer player, InventoryData data, CCInventory cc); - - public abstract boolean isEnabled(CCInventory cc); - - @Override - protected final ExecutionHistory getHistory(NoCheatPlayer player) { - return player.getData().inventory.history; - } -} diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/NoCheatCommandSender.java b/src/cc/co/evenprime/bukkit/nocheat/checks/NoCheatCommandSender.java deleted file mode 100644 index f6a052d0..00000000 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/NoCheatCommandSender.java +++ /dev/null @@ -1,96 +0,0 @@ -package cc.co.evenprime.bukkit.nocheat.checks; - -import java.util.Set; - -import org.bukkit.Bukkit; -import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionAttachment; -import org.bukkit.permissions.PermissionAttachmentInfo; -import org.bukkit.plugin.Plugin; - - -public class NoCheatCommandSender implements CommandSender { - - @Override - public boolean isPermissionSet(String name) { - return true; - } - - @Override - public boolean isPermissionSet(Permission perm) { - return true; - } - - @Override - public boolean hasPermission(String name) { - return true; - } - - @Override - public boolean hasPermission(Permission perm) { - return true; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) { - return null; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin) { - return null; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) { - return null; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, int ticks) { - return null; - } - - @Override - public void removeAttachment(PermissionAttachment attachment) { - - } - - @Override - public void recalculatePermissions() { - - } - - @Override - public Set getEffectivePermissions() { - return null; - } - - @Override - public boolean isOp() { - return true; - } - - @Override - public void setOp(boolean value) { - - } - - @Override - public void sendMessage(String message) { - - } - - @Override - public Server getServer() { - return Bukkit.getServer(); - } - - @Override - public String getName() { - return "NoCheatCommandSender"; - } - -} diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheck.java new file mode 100644 index 00000000..df474e3f --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakCheck.java @@ -0,0 +1,44 @@ +package cc.co.evenprime.bukkit.nocheat.checks.blockbreak; + +import cc.co.evenprime.bukkit.nocheat.NoCheat; +import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; +import cc.co.evenprime.bukkit.nocheat.checks.Check; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; +import cc.co.evenprime.bukkit.nocheat.data.DataStore; +import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; + +public abstract class BlockBreakCheck extends Check { + + private static final String id = "blockbreak"; + + public BlockBreakCheck(NoCheat plugin, String name, String permission) { + super(plugin, name, permission); + } + + public abstract boolean check(NoCheatPlayer player, BlockBreakData data, CCBlockBreak cc); + + public abstract boolean isEnabled(CCBlockBreak cc); + + @Override + protected final ExecutionHistory getHistory(NoCheatPlayer player) { + return getData(player.getDataStore()).history; + } + + public static BlockBreakData getData(DataStore base) { + BlockBreakData data = base.get(id); + if(data == null) { + data = new BlockBreakData(); + base.set(id, data); + } + return data; + } + + public static CCBlockBreak getConfig(ConfigurationCacheStore cache) { + CCBlockBreak config = cache.get(id); + if(config == null) { + config = new CCBlockBreak(cache.getConfiguration()); + cache.set(id, config); + } + return config; + } +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/BlockBreakData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakData.java similarity index 75% rename from src/cc/co/evenprime/bukkit/nocheat/data/BlockBreakData.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakData.java index 4de9420e..51263466 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/BlockBreakData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakData.java @@ -1,12 +1,16 @@ -package cc.co.evenprime.bukkit.nocheat.data; +package cc.co.evenprime.bukkit.nocheat.checks.blockbreak; import java.util.Map; +import cc.co.evenprime.bukkit.nocheat.DataItem; +import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; +import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; + /** * Playerspecific data for the blockbreak check group * */ -public class BlockBreakData extends Data { +public class BlockBreakData implements DataItem { public double reachVL = 0.0D; public double reachTotalVL = 0.0D; @@ -37,9 +41,9 @@ public class BlockBreakData extends Data { @Override public void collectData(Map map) { - map.put("blockbreak.reach.vl", (int)reachTotalVL); - map.put("blockbreak.direction.vl", (int)directionTotalVL); - map.put("blockbreak.noswing.vl", (int)noswingTotalVL); + map.put("blockbreak.reach.vl", (int) reachTotalVL); + map.put("blockbreak.direction.vl", (int) directionTotalVL); + map.put("blockbreak.noswing.vl", (int) noswingTotalVL); map.put("blockbreak.reach.failed", reachFailed); map.put("blockbreak.direction.failed", directionFailed); map.put("blockbreak.noswing.failed", noswingFailed); diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/BlockBreakEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakEventManager.java similarity index 68% rename from src/cc/co/evenprime/bukkit/nocheat/events/BlockBreakEventManager.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakEventManager.java index 246fc9d0..d709d5cf 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/BlockBreakEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakEventManager.java @@ -1,4 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.events; +package cc.co.evenprime.bukkit.nocheat.checks.blockbreak; import java.util.ArrayList; import java.util.LinkedList; @@ -12,15 +12,10 @@ import org.bukkit.event.player.PlayerAnimationEvent; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.checks.BlockBreakCheck; -import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.DirectionCheck; -import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.NoswingCheck; -import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.ReachCheck; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; -import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData; import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType; +import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl; /** * Central location to listen to player-interact events and dispatch them to @@ -52,13 +47,13 @@ public class BlockBreakEventManager extends EventManagerImpl { boolean cancelled = false; final NoCheatPlayer player = plugin.getPlayer(event.getPlayer()); - final CCBlockBreak cc = player.getConfiguration().blockbreak; + final CCBlockBreak cc = BlockBreakCheck.getConfig(player.getConfigurationStore()); if(!cc.check || player.hasPermission(Permissions.BLOCKBREAK)) { return; } - final BlockBreakData data = player.getData().blockbreak; + final BlockBreakData data = BlockBreakCheck.getData(player.getDataStore()); data.brokenBlockLocation.set(event.getBlock()); @@ -80,27 +75,26 @@ public class BlockBreakEventManager extends EventManagerImpl { if(!event.getInstaBreak()) return; - // Get the player-specific stored data that applies here - final BlockBreakData data = plugin.getPlayer(event.getPlayer()).getData().blockbreak; - // Remember this location. We ignore block breaks in the block-break // direction check that are insta-breaks - data.instaBrokenBlockLocation.set(event.getBlock()); + BlockBreakCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore()).instaBrokenBlockLocation.set(event.getBlock()); } @Override protected void handlePlayerAnimationEvent(final PlayerAnimationEvent event, final Priority priority) { - plugin.getPlayer(event.getPlayer()).getData().blockbreak.armswung = true; + BlockBreakCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore()).armswung = true; } - public List getActiveChecks(ConfigurationCache cc) { + public List getActiveChecks(ConfigurationCacheStore cc) { LinkedList s = new LinkedList(); - if(cc.blockbreak.check && cc.blockbreak.directionCheck) + CCBlockBreak bb = BlockBreakCheck.getConfig(cc); + + if(bb.check && bb.directionCheck) s.add("blockbreak.direction"); - if(cc.blockbreak.check && cc.blockbreak.reachCheck) + if(bb.check && bb.reachCheck) s.add("blockbreak.reach"); - if(cc.blockbreak.check && cc.blockbreak.noswingCheck) + if(bb.check && bb.noswingCheck) s.add("blockbreak.noswing"); return s; diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockBreak.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/CCBlockBreak.java similarity index 89% rename from src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockBreak.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/CCBlockBreak.java index 8ddecdec..ca2f5410 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockBreak.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/CCBlockBreak.java @@ -1,5 +1,6 @@ -package cc.co.evenprime.bukkit.nocheat.config.cache; +package cc.co.evenprime.bukkit.nocheat.checks.blockbreak; +import cc.co.evenprime.bukkit.nocheat.ConfigItem; import cc.co.evenprime.bukkit.nocheat.config.Configuration; import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; @@ -8,7 +9,7 @@ import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; * Every world gets one of these assigned to it. * */ -public class CCBlockBreak { +public class CCBlockBreak implements ConfigItem { public final boolean check; public final boolean checkinstabreakblocks; 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 428549be..7ba126da 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/DirectionCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/DirectionCheck.java @@ -5,11 +5,8 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.BlockBreakCheck; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak; -import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; /** @@ -82,7 +79,7 @@ public class DirectionCheck extends BlockBreakCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().blockbreak.directionVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).directionVL); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/NoswingCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/NoswingCheck.java index c883491d..3ef2c0cd 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/NoswingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/NoswingCheck.java @@ -5,10 +5,7 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.BlockBreakCheck; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak; -import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData; public class NoswingCheck extends BlockBreakCheck { @@ -42,7 +39,7 @@ public class NoswingCheck extends BlockBreakCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().blockbreak.noswingVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).noswingVL); else return super.getParameter(wildcard, player); } 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 e815db3b..879d9c80 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/ReachCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/ReachCheck.java @@ -5,11 +5,8 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.BlockBreakCheck; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak; -import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; /** @@ -55,9 +52,9 @@ public class ReachCheck extends BlockBreakCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().blockbreak.reachVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).reachVL); else if(wildcard == ParameterName.REACHDISTANCE) - return String.format(Locale.US, "%.2f", player.getData().blockbreak.reachDistance); + return String.format(Locale.US, "%.2f", getData(player.getDataStore()).reachDistance); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/BlockPlaceCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheck.java similarity index 55% rename from src/cc/co/evenprime/bukkit/nocheat/checks/BlockPlaceCheck.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheck.java index 828fdaa0..45fe7a10 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/BlockPlaceCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceCheck.java @@ -1,12 +1,13 @@ -package cc.co.evenprime.bukkit.nocheat.checks; +package cc.co.evenprime.bukkit.nocheat.checks.blockplace; import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace; -import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData; +import cc.co.evenprime.bukkit.nocheat.checks.Check; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; +import cc.co.evenprime.bukkit.nocheat.data.DataStore; import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; @@ -15,6 +16,8 @@ import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; */ public abstract class BlockPlaceCheck extends Check { + private static final String id = "blockplace"; + public BlockPlaceCheck(NoCheat plugin, String name, String permission) { super(plugin, name, permission); } @@ -25,13 +28,13 @@ public abstract class BlockPlaceCheck extends Check { @Override protected final ExecutionHistory getHistory(NoCheatPlayer player) { - return player.getData().blockplace.history; + return getData(player.getDataStore()).history; } @Override public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.PLACE_LOCATION) { - SimpleLocation l = player.getData().blockplace.blockPlaced; + SimpleLocation l = getData(player.getDataStore()).blockPlaced; if(l.isSet()) { return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z); } else { @@ -40,7 +43,7 @@ public abstract class BlockPlaceCheck extends Check { } else if(wildcard == ParameterName.PLACE_AGAINST) { - SimpleLocation l = player.getData().blockplace.blockPlacedAgainst; + SimpleLocation l = getData(player.getDataStore()).blockPlacedAgainst; if(l.isSet()) { return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z); } else { @@ -51,4 +54,22 @@ public abstract class BlockPlaceCheck extends Check { else return super.getParameter(wildcard, player); } + + public static BlockPlaceData getData(DataStore base) { + BlockPlaceData data = base.get(id); + if(data == null) { + data = new BlockPlaceData(); + base.set(id, data); + } + return data; + } + + public static CCBlockPlace getConfig(ConfigurationCacheStore cache) { + CCBlockPlace config = cache.get(id); + if(config == null) { + config = new CCBlockPlace(cache.getConfiguration()); + cache.set(id, config); + } + return config; + } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/BlockPlaceData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceData.java similarity index 80% rename from src/cc/co/evenprime/bukkit/nocheat/data/BlockPlaceData.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceData.java index d3b350e7..fb57e5cb 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/BlockPlaceData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceData.java @@ -1,11 +1,15 @@ -package cc.co.evenprime.bukkit.nocheat.data; +package cc.co.evenprime.bukkit.nocheat.checks.blockplace; import java.util.Map; +import cc.co.evenprime.bukkit.nocheat.DataItem; +import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; +import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; + /** * */ -public class BlockPlaceData extends Data { +public class BlockPlaceData implements DataItem { public double reachVL = 0.0D; public double reachTotalVL = 0.0D; diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/BlockPlaceEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceEventManager.java similarity index 71% rename from src/cc/co/evenprime/bukkit/nocheat/events/BlockPlaceEventManager.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceEventManager.java index 4ebbfe25..6580b35d 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/BlockPlaceEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceEventManager.java @@ -1,4 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.events; +package cc.co.evenprime.bukkit.nocheat.checks.blockplace; import java.util.ArrayList; import java.util.LinkedList; @@ -10,14 +10,10 @@ import org.bukkit.event.block.BlockPlaceEvent; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.checks.BlockPlaceCheck; -import cc.co.evenprime.bukkit.nocheat.checks.blockplace.DirectionCheck; -import cc.co.evenprime.bukkit.nocheat.checks.blockplace.ReachCheck; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; -import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData; import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType; +import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl; /** * Central location to listen to Block-related events and dispatching them to @@ -48,13 +44,13 @@ public class BlockPlaceEventManager extends EventManagerImpl { boolean cancelled = false; final NoCheatPlayer player = plugin.getPlayer(event.getPlayer()); - final CCBlockPlace cc = player.getConfiguration().blockplace; + final CCBlockPlace cc = BlockPlaceCheck.getConfig(player.getConfigurationStore()); if(!cc.check || player.hasPermission(Permissions.BLOCKPLACE)) { return; } - final BlockPlaceData data = player.getData().blockplace; + final BlockPlaceData data = BlockPlaceCheck.getData(player.getDataStore()); data.blockPlaced.set(event.getBlock()); data.blockPlacedAgainst.set(event.getBlockAgainst()); @@ -70,10 +66,12 @@ public class BlockPlaceEventManager extends EventManagerImpl { event.setCancelled(cancelled); } - public List getActiveChecks(ConfigurationCache cc) { + public List getActiveChecks(ConfigurationCacheStore cc) { LinkedList s = new LinkedList(); - if(cc.blockplace.check && cc.blockplace.reachCheck) + CCBlockPlace bp = BlockPlaceCheck.getConfig(cc); + + if(bp.check && bp.reachCheck) s.add("blockplace.reach"); return s; diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockPlace.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/CCBlockPlace.java similarity index 85% rename from src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockPlace.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/CCBlockPlace.java index be62a5d6..3522ac1f 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCBlockPlace.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/CCBlockPlace.java @@ -1,12 +1,13 @@ -package cc.co.evenprime.bukkit.nocheat.config.cache; +package cc.co.evenprime.bukkit.nocheat.checks.blockplace; +import cc.co.evenprime.bukkit.nocheat.ConfigItem; import cc.co.evenprime.bukkit.nocheat.config.Configuration; import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; /** * */ -public class CCBlockPlace { +public class CCBlockPlace implements ConfigItem { public final boolean check; diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/DirectionCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/DirectionCheck.java index 66891999..8c619ea4 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/DirectionCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/DirectionCheck.java @@ -5,11 +5,8 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.BlockPlaceCheck; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace; -import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; public class DirectionCheck extends BlockPlaceCheck { @@ -96,7 +93,7 @@ public class DirectionCheck extends BlockPlaceCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().blockplace.directionVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).directionVL); else return super.getParameter(wildcard, player); } 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 df190110..6be7c31a 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/ReachCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/ReachCheck.java @@ -5,11 +5,8 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.BlockPlaceCheck; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace; -import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; /** @@ -56,9 +53,9 @@ public class ReachCheck extends BlockPlaceCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().blockplace.reachVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).reachVL); else if(wildcard == ParameterName.REACHDISTANCE) - return String.format(Locale.US, "%.2f", player.getData().blockplace.reachdistance); + return String.format(Locale.US, "%.2f", getData(player.getDataStore()).reachdistance); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCChat.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/CCChat.java similarity index 88% rename from src/cc/co/evenprime/bukkit/nocheat/config/cache/CCChat.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/chat/CCChat.java index 09056c3f..c7edc727 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCChat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/CCChat.java @@ -1,12 +1,13 @@ -package cc.co.evenprime.bukkit.nocheat.config.cache; +package cc.co.evenprime.bukkit.nocheat.checks.chat; import java.util.LinkedList; import java.util.List; +import cc.co.evenprime.bukkit.nocheat.ConfigItem; import cc.co.evenprime.bukkit.nocheat.config.Configuration; import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; -public class CCChat { +public class CCChat implements ConfigItem { public final boolean check; public final boolean spamCheck; diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheck.java new file mode 100644 index 00000000..ea5fca37 --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatCheck.java @@ -0,0 +1,55 @@ +package cc.co.evenprime.bukkit.nocheat.checks.chat; + +import cc.co.evenprime.bukkit.nocheat.NoCheat; +import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; +import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; +import cc.co.evenprime.bukkit.nocheat.checks.Check; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; +import cc.co.evenprime.bukkit.nocheat.data.ChatData; +import cc.co.evenprime.bukkit.nocheat.data.DataStore; +import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; + +public abstract class ChatCheck extends Check { + + private static final String id = "chat"; + + public ChatCheck(NoCheat plugin, String name, String permission) { + super(plugin, name, permission); + } + + public abstract boolean check(NoCheatPlayer player, ChatData data, CCChat cc); + + public abstract boolean isEnabled(CCChat cc); + + @Override + protected final ExecutionHistory getHistory(NoCheatPlayer player) { + return getData(player.getDataStore()).history; + } + + @Override + public String getParameter(ParameterName wildcard, NoCheatPlayer player) { + + if(wildcard == ParameterName.TEXT) + return getData(player.getDataStore()).message; + else + return super.getParameter(wildcard, player); + } + + public static ChatData getData(DataStore base) { + ChatData data = base.get(id); + if(data == null) { + data = new ChatData(); + base.set(id, data); + } + return data; + } + + public static CCChat getConfig(ConfigurationCacheStore cache) { + CCChat config = cache.get(id); + if(config == null) { + config = new CCChat(cache.getConfiguration()); + cache.set(id, config); + } + return config; + } +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/ChatEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatEventManager.java similarity index 75% rename from src/cc/co/evenprime/bukkit/nocheat/events/ChatEventManager.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatEventManager.java index b3f95cc7..75e5591d 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/ChatEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatEventManager.java @@ -1,4 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.events; +package cc.co.evenprime.bukkit.nocheat.checks.chat; import java.util.ArrayList; import java.util.LinkedList; @@ -11,14 +11,11 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.checks.ChatCheck; -import cc.co.evenprime.bukkit.nocheat.checks.chat.EmptyCheck; -import cc.co.evenprime.bukkit.nocheat.checks.chat.SpamCheck; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.ChatData; import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType; +import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl; public class ChatEventManager extends EventManagerImpl { @@ -47,13 +44,13 @@ public class ChatEventManager extends EventManagerImpl { boolean cancelled = false; final NoCheatPlayer player = plugin.getPlayer(event.getPlayer()); - final CCChat cc = player.getConfiguration().chat; + final CCChat cc = ChatCheck.getConfig(player.getConfigurationStore()); if(!cc.check || player.hasPermission(Permissions.CHAT)) { return; } - final ChatData data = player.getData().chat; + final ChatData data = ChatCheck.getData(player.getDataStore()); data.message = event.getMessage(); @@ -69,12 +66,13 @@ public class ChatEventManager extends EventManagerImpl { } } - public List getActiveChecks(ConfigurationCache cc) { + public List getActiveChecks(ConfigurationCacheStore cc) { LinkedList s = new LinkedList(); - if(cc.chat.check && cc.chat.spamCheck) + CCChat c = ChatCheck.getConfig(cc); + if(c.check && c.spamCheck) s.add("chat.spam"); - if(cc.chat.check && cc.chat.emptyCheck) + if(c.check && c.emptyCheck) s.add("chat.empty"); return s; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/EmptyCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/EmptyCheck.java index 41fad85c..cd23a6cb 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/EmptyCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/EmptyCheck.java @@ -5,9 +5,7 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.ChatCheck; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat; import cc.co.evenprime.bukkit.nocheat.data.ChatData; public class EmptyCheck extends ChatCheck { @@ -40,7 +38,7 @@ public class EmptyCheck extends ChatCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", player.getData().chat.emptyVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).emptyVL); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/SpamCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/SpamCheck.java index ff879097..e60a3530 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/SpamCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/SpamCheck.java @@ -5,9 +5,7 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.ChatCheck; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat; import cc.co.evenprime.bukkit.nocheat.data.ChatData; public class SpamCheck extends ChatCheck { @@ -60,7 +58,7 @@ public class SpamCheck extends ChatCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", player.getData().chat.spamVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).spamVL); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCFight.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/CCFight.java similarity index 87% rename from src/cc/co/evenprime/bukkit/nocheat/config/cache/CCFight.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/fight/CCFight.java index 8a263acc..ce1a678c 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCFight.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/CCFight.java @@ -1,9 +1,10 @@ -package cc.co.evenprime.bukkit.nocheat.config.cache; +package cc.co.evenprime.bukkit.nocheat.checks.fight; +import cc.co.evenprime.bukkit.nocheat.ConfigItem; import cc.co.evenprime.bukkit.nocheat.config.Configuration; import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; -public class CCFight { +public class CCFight implements ConfigItem { public final boolean check; public final boolean directionCheck; diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/DirectionCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/DirectionCheck.java index 70711b51..1c67c15e 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/DirectionCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/DirectionCheck.java @@ -10,10 +10,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; -import cc.co.evenprime.bukkit.nocheat.checks.FightCheck; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight; -import cc.co.evenprime.bukkit.nocheat.data.FightData; public class DirectionCheck extends FightCheck { @@ -87,7 +84,7 @@ public class DirectionCheck extends FightCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().fight.directionVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).directionVL); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheck.java new file mode 100644 index 00000000..2971aa54 --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightCheck.java @@ -0,0 +1,48 @@ +package cc.co.evenprime.bukkit.nocheat.checks.fight; + +import cc.co.evenprime.bukkit.nocheat.NoCheat; +import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; +import cc.co.evenprime.bukkit.nocheat.checks.Check; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; +import cc.co.evenprime.bukkit.nocheat.data.DataStore; +import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; + +/** + * Check various things related to fighting players/entities + * + */ +public abstract class FightCheck extends Check { + + private static final String id = "fight"; + + public FightCheck(NoCheat plugin, String name, String permission) { + super(plugin, name, permission); + } + + public abstract boolean check(NoCheatPlayer player, FightData data, CCFight cc); + + public abstract boolean isEnabled(CCFight cc); + + @Override + protected final ExecutionHistory getHistory(NoCheatPlayer player) { + return getData(player.getDataStore()).history; + } + + public static FightData getData(DataStore base) { + FightData data = base.get(id); + if(data == null) { + data = new FightData(); + base.set(id, data); + } + return data; + } + + public static CCFight getConfig(ConfigurationCacheStore cache) { + CCFight config = cache.get(id); + if(config == null) { + config = new CCFight(cache.getConfiguration()); + cache.set(id, config); + } + return config; + } +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/FightData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightData.java similarity index 82% rename from src/cc/co/evenprime/bukkit/nocheat/data/FightData.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightData.java index d02c5bfe..d63b22b6 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/FightData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightData.java @@ -1,10 +1,12 @@ -package cc.co.evenprime.bukkit.nocheat.data; +package cc.co.evenprime.bukkit.nocheat.checks.fight; import java.util.Map; import net.minecraft.server.Entity; +import cc.co.evenprime.bukkit.nocheat.DataItem; +import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; -public class FightData extends Data { +public class FightData implements DataItem { public double directionVL = 0.0D; public double directionTotalVL = 0.0D; @@ -32,4 +34,9 @@ public class FightData extends Data { map.put("fight.selfhit.failed", selfhitFailed); map.put("fight.noswing.failed", noswingFailed); } + + @Override + public void clearCriticalData() { + + } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/FightEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightEventManager.java similarity index 75% rename from src/cc/co/evenprime/bukkit/nocheat/events/FightEventManager.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightEventManager.java index 5abd648f..e3955fd7 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/FightEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightEventManager.java @@ -1,4 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.events; +package cc.co.evenprime.bukkit.nocheat.checks.fight; import java.util.ArrayList; import java.util.LinkedList; @@ -14,15 +14,10 @@ import org.bukkit.event.player.PlayerAnimationEvent; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.checks.FightCheck; -import cc.co.evenprime.bukkit.nocheat.checks.fight.DirectionCheck; -import cc.co.evenprime.bukkit.nocheat.checks.fight.NoswingCheck; -import cc.co.evenprime.bukkit.nocheat.checks.fight.SelfhitCheck; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; -import cc.co.evenprime.bukkit.nocheat.data.FightData; import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType; +import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl; public class FightEventManager extends EventManagerImpl { @@ -46,13 +41,13 @@ public class FightEventManager extends EventManagerImpl { final Player damager = (Player) event.getDamager(); final NoCheatPlayer player = plugin.getPlayer(damager); - final CCFight cc = player.getConfiguration().fight; + final CCFight cc = FightCheck.getConfig(player.getConfigurationStore()); if(!cc.check || player.hasPermission(Permissions.FIGHT)) { return; } - final FightData data = player.getData().fight; + final FightData data = FightCheck.getData(player.getDataStore()); // For some reason we decided to skip this event anyway if(data.skipNext) { @@ -84,7 +79,7 @@ public class FightEventManager extends EventManagerImpl { final Player damager = (Player) ((Projectile) event.getDamager()).getShooter(); final NoCheatPlayer player = plugin.getPlayer(damager); - final FightData data = player.getData().fight; + final FightData data = FightCheck.getData(player.getDataStore()); // Skip the next damage event, because it is the same as this one // just mislabelled as a "direct" attack from one player onto another @@ -99,7 +94,7 @@ public class FightEventManager extends EventManagerImpl { final Player damager = (Player) event.getDamager(); final NoCheatPlayer player = plugin.getPlayer(damager); - final FightData data = player.getData().fight; + final FightData data = FightCheck.getData(player.getDataStore()); // Skip the next damage event, because it is with high probability // something from the Heroes plugin @@ -110,17 +105,19 @@ public class FightEventManager extends EventManagerImpl { @Override protected void handlePlayerAnimationEvent(final PlayerAnimationEvent event, final Priority priority) { - plugin.getPlayer(event.getPlayer()).getData().fight.armswung = true; + FightCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore()).armswung = true; } - public List getActiveChecks(ConfigurationCache cc) { + public List getActiveChecks(ConfigurationCacheStore cc) { LinkedList s = new LinkedList(); - if(cc.fight.check && cc.fight.directionCheck) + CCFight f = FightCheck.getConfig(cc); + + if(f.check && f.directionCheck) s.add("fight.direction"); - if(cc.fight.check && cc.fight.selfhitCheck) + if(f.check && f.selfhitCheck) s.add("fight.selfhit"); - if(cc.fight.check && cc.fight.noswingCheck) + if(f.check && f.noswingCheck) s.add("fight.noswing"); return s; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/NoswingCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/NoswingCheck.java index af9b5f36..1c1b6969 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/NoswingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/NoswingCheck.java @@ -5,10 +5,7 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.FightCheck; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight; -import cc.co.evenprime.bukkit.nocheat.data.FightData; public class NoswingCheck extends FightCheck { @@ -43,7 +40,7 @@ public class NoswingCheck extends FightCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().fight.noswingVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).noswingVL); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/SelfhitCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/SelfhitCheck.java index 8688d977..67595b5e 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/SelfhitCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/SelfhitCheck.java @@ -5,10 +5,7 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.FightCheck; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight; -import cc.co.evenprime.bukkit.nocheat.data.FightData; public class SelfhitCheck extends FightCheck { @@ -43,7 +40,7 @@ public class SelfhitCheck extends FightCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().fight.selfhitVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).selfhitVL); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCInventory.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/CCInventory.java similarity index 82% rename from src/cc/co/evenprime/bukkit/nocheat/config/cache/CCInventory.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/inventory/CCInventory.java index faffae30..b97a4fd9 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCInventory.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/CCInventory.java @@ -1,9 +1,10 @@ -package cc.co.evenprime.bukkit.nocheat.config.cache; +package cc.co.evenprime.bukkit.nocheat.checks.inventory; +import cc.co.evenprime.bukkit.nocheat.ConfigItem; import cc.co.evenprime.bukkit.nocheat.config.Configuration; import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; -public class CCInventory { +public class CCInventory implements ConfigItem { public final boolean closebeforeteleports; public final boolean check; diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/DropCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/DropCheck.java index 4fc289fe..39a4552e 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/DropCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/DropCheck.java @@ -5,10 +5,7 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.InventoryCheck; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCInventory; -import cc.co.evenprime.bukkit.nocheat.data.InventoryData; public class DropCheck extends InventoryCheck { @@ -55,7 +52,7 @@ public class DropCheck extends InventoryCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", player.getData().inventory.dropVL); + return String.format(Locale.US, "%d", getData(player.getDataStore()).dropVL); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheck.java new file mode 100644 index 00000000..d81b03e2 --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheck.java @@ -0,0 +1,44 @@ +package cc.co.evenprime.bukkit.nocheat.checks.inventory; + +import cc.co.evenprime.bukkit.nocheat.NoCheat; +import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; +import cc.co.evenprime.bukkit.nocheat.checks.Check; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; +import cc.co.evenprime.bukkit.nocheat.data.DataStore; +import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; + +public abstract class InventoryCheck extends Check { + + private static final String id = "inventory"; + + public InventoryCheck(NoCheat plugin, String name, String permission) { + super(plugin, name, permission); + } + + public abstract boolean check(NoCheatPlayer player, InventoryData data, CCInventory cc); + + public abstract boolean isEnabled(CCInventory cc); + + @Override + protected final ExecutionHistory getHistory(NoCheatPlayer player) { + return getData(player.getDataStore()).history; + } + + public static InventoryData getData(DataStore base) { + InventoryData data = base.get(id); + if(data == null) { + data = new InventoryData(); + base.set(id, data); + } + return data; + } + + public static CCInventory getConfig(ConfigurationCacheStore cache) { + CCInventory config = cache.get(id); + if(config == null) { + config = new CCInventory(cache.getConfiguration()); + cache.set(id, config); + } + return config; + } +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/InventoryData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryData.java similarity index 63% rename from src/cc/co/evenprime/bukkit/nocheat/data/InventoryData.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryData.java index 06eec8b5..834c7320 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/InventoryData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryData.java @@ -1,8 +1,11 @@ -package cc.co.evenprime.bukkit.nocheat.data; +package cc.co.evenprime.bukkit.nocheat.checks.inventory; import java.util.Map; -public class InventoryData extends Data { +import cc.co.evenprime.bukkit.nocheat.DataItem; +import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; + +public class InventoryData implements DataItem { public int dropVL = 0; public double dropTotalVL = 0; @@ -16,4 +19,9 @@ public class InventoryData extends Data { map.put("inventory.drop.vl", (int) dropTotalVL); map.put("inventory.drop.failed", (int) dropFailed); } + + @Override + public void clearCriticalData() { + + } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/InventoryEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryEventManager.java similarity index 57% rename from src/cc/co/evenprime/bukkit/nocheat/events/InventoryEventManager.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryEventManager.java index 1ef069c6..236b7647 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/InventoryEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryEventManager.java @@ -1,22 +1,21 @@ -package cc.co.evenprime.bukkit.nocheat.events; +package cc.co.evenprime.bukkit.nocheat.checks.inventory; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.event.Event; import org.bukkit.event.Event.Priority; import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerTeleportEvent; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.checks.InventoryCheck; -import cc.co.evenprime.bukkit.nocheat.checks.inventory.DropCheck; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCInventory; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; -import cc.co.evenprime.bukkit.nocheat.data.InventoryData; import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType; +import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl; public class InventoryEventManager extends EventManagerImpl { @@ -29,19 +28,29 @@ public class InventoryEventManager extends EventManagerImpl { this.checks.add(new DropCheck(plugin)); registerListener(Event.Type.PLAYER_DROP_ITEM, Priority.Lowest, true, plugin.getPerformance(EventType.INVENTORY)); + registerListener(Event.Type.PLAYER_TELEPORT, Priority.Monitor, true, null); + } + + @Override + protected void handlePlayerTeleportEvent(final PlayerTeleportEvent event, final Priority priority) { + + CraftPlayer player = (CraftPlayer) event.getPlayer(); + if(InventoryCheck.getConfig(plugin.getPlayer(player).getConfigurationStore()).closebeforeteleports && event.getTo() != null && !(event.getTo().getWorld().equals(player.getWorld()))) { + player.getHandle().closeInventory(); + } } @Override protected void handlePlayerDropItemEvent(final PlayerDropItemEvent event, final Priority priority) { final NoCheatPlayer player = plugin.getPlayer(event.getPlayer()); - final CCInventory cc = player.getConfiguration().inventory; + final CCInventory cc = InventoryCheck.getConfig(player.getConfigurationStore()); if(!cc.check || player.hasPermission(Permissions.INVENTORY)) { return; } - final InventoryData data = player.getData().inventory; + final InventoryData data = InventoryCheck.getData(player.getDataStore()); boolean cancelled = false; @@ -56,12 +65,12 @@ public class InventoryEventManager extends EventManagerImpl { event.setCancelled(cancelled); } - public List getActiveChecks(ConfigurationCache cc) { + public List getActiveChecks(ConfigurationCacheStore cc) { LinkedList s = new LinkedList(); - if(cc.inventory.check && cc.inventory.dropCheck) + CCInventory i = InventoryCheck.getConfig(cc); + if(i.check && i.dropCheck) s.add("inventory.dropCheck"); return s; } - } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCMoving.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/CCMoving.java similarity index 92% rename from src/cc/co/evenprime/bukkit/nocheat/config/cache/CCMoving.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/moving/CCMoving.java index c4421f32..9b27f021 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCMoving.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/CCMoving.java @@ -1,5 +1,6 @@ -package cc.co.evenprime.bukkit.nocheat.config.cache; +package cc.co.evenprime.bukkit.nocheat.checks.moving; +import cc.co.evenprime.bukkit.nocheat.ConfigItem; import cc.co.evenprime.bukkit.nocheat.config.Configuration; import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; @@ -8,7 +9,7 @@ import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; * assigned to it. * */ -public class CCMoving { +public class CCMoving implements ConfigItem { public final boolean check; @@ -35,7 +36,7 @@ public class CCMoving { public final boolean morePacketsCheck; public final ActionList morePacketsActions; - public final double flyingHeightLimit; + public final double flyingHeightLimit; public CCMoving(Configuration data) { 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 bcf1d8c6..5a24f3ac 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/FlyingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/FlyingCheck.java @@ -5,9 +5,6 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving; -import cc.co.evenprime.bukkit.nocheat.data.MovingData; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; /** @@ -35,7 +32,7 @@ public class FlyingCheck extends MovingCheck { } PreciseLocation newToLocation = null; - + // Before doing anything, do a basic height check // This is silent for now, will log messages later // probably @@ -127,7 +124,7 @@ public class FlyingCheck extends MovingCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().moving.runflyVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).runflyVL); else return super.getParameter(wildcard, player); } 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 3b7fc314..8127f0e3 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java @@ -5,10 +5,7 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving; -import cc.co.evenprime.bukkit.nocheat.data.MovingData; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; /** @@ -110,9 +107,9 @@ public class MorePacketsCheck extends MovingCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().moving.morePacketsVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).morePacketsVL); else if(wildcard == ParameterName.PACKETS) - return String.valueOf(player.getData().moving.packets); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).packets); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/MovingCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingCheck.java similarity index 55% rename from src/cc/co/evenprime/bukkit/nocheat/checks/MovingCheck.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingCheck.java index 6a5b2567..210de699 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/MovingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingCheck.java @@ -1,17 +1,20 @@ -package cc.co.evenprime.bukkit.nocheat.checks; +package cc.co.evenprime.bukkit.nocheat.checks.moving; import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving; +import cc.co.evenprime.bukkit.nocheat.checks.Check; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; +import cc.co.evenprime.bukkit.nocheat.data.DataStore; import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; -import cc.co.evenprime.bukkit.nocheat.data.MovingData; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; public abstract class MovingCheck extends Check { + private static final String id = "moving"; + public MovingCheck(NoCheat plugin, String name, String permission) { super(plugin, name, permission); } @@ -28,24 +31,42 @@ public abstract class MovingCheck extends Check { @Override protected ExecutionHistory getHistory(NoCheatPlayer player) { - return player.getData().moving.history; + return getData(player.getDataStore()).history; } @Override public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.LOCATION) { - PreciseLocation from = player.getData().moving.from; + PreciseLocation from = getData(player.getDataStore()).from; return String.format(Locale.US, "%.2f,%.2f,%.2f", from.x, from.y, from.z); } else if(wildcard == ParameterName.MOVEDISTANCE) { - PreciseLocation from = player.getData().moving.from; - PreciseLocation to = player.getData().moving.to; + PreciseLocation from = getData(player.getDataStore()).from; + PreciseLocation to = getData(player.getDataStore()).to; return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x - from.x, to.y - from.y, to.z - from.z); } else if(wildcard == ParameterName.LOCATION_TO) { - PreciseLocation to = player.getData().moving.to; + PreciseLocation to = getData(player.getDataStore()).to; return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x, to.y, to.z); } else return super.getParameter(wildcard, player); } + + public static MovingData getData(DataStore base) { + MovingData data = base.get(id); + if(data == null) { + data = new MovingData(); + base.set(id, data); + } + return data; + } + + public static CCMoving getConfig(ConfigurationCacheStore cache) { + CCMoving config = cache.get(id); + if(config == null) { + config = new CCMoving(cache.getConfiguration()); + cache.set(id, config); + } + return config; + } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/MovingData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingData.java similarity index 90% rename from src/cc/co/evenprime/bukkit/nocheat/data/MovingData.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingData.java index ee4881d6..61da449d 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/MovingData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingData.java @@ -1,11 +1,15 @@ -package cc.co.evenprime.bukkit.nocheat.data; +package cc.co.evenprime.bukkit.nocheat.checks.moving; import java.util.Map; +import cc.co.evenprime.bukkit.nocheat.DataItem; +import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory; +import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; + /** * Player specific data for the moving check group */ -public class MovingData extends Data { +public class MovingData implements DataItem { public double runflyVL; diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/MovingEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingEventManager.java similarity index 83% rename from src/cc/co/evenprime/bukkit/nocheat/events/MovingEventManager.java rename to src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingEventManager.java index 6a9ca61e..46b744c5 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/MovingEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingEventManager.java @@ -1,4 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.events; +package cc.co.evenprime.bukkit.nocheat.checks.moving; import java.util.ArrayList; import java.util.LinkedList; @@ -17,16 +17,12 @@ import org.bukkit.util.Vector; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; -import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck; -import cc.co.evenprime.bukkit.nocheat.checks.moving.MorePacketsCheck; -import cc.co.evenprime.bukkit.nocheat.checks.moving.RunflyCheck; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; -import cc.co.evenprime.bukkit.nocheat.data.MovingData; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType; +import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl; /** * The only place that listens to and modifies player_move events if necessary @@ -59,7 +55,7 @@ public class MovingEventManager extends EventManagerImpl { final NoCheatPlayer player = plugin.getPlayer(event.getPlayer()); // Get the player-specific stored data that applies here - final MovingData data = player.getData().moving; + final MovingData data = MovingCheck.getData(player.getDataStore()); final Block blockPlaced = event.getBlockPlaced(); @@ -92,7 +88,7 @@ public class MovingEventManager extends EventManagerImpl { return; NoCheatPlayer player = plugin.getPlayer(event.getPlayer()); - final MovingData data = player.getData().moving; + final MovingData data = MovingCheck.getData(player.getDataStore()); if(data.teleportTo.isSet() && data.teleportTo.equals(event.getTo())) { event.setCancelled(false); @@ -112,13 +108,13 @@ public class MovingEventManager extends EventManagerImpl { return; } - final CCMoving cc = player.getConfiguration().moving; + final CCMoving cc = MovingCheck.getConfig(player.getConfigurationStore()); if(!cc.check || player.hasPermission(Permissions.MOVING)) { return; } - final MovingData data = player.getData().moving; + final MovingData data = MovingCheck.getData(player.getDataStore()); /******** DO GENERAL DATA MODIFICATIONS ONCE FOR EACH EVENT *****/ if(data.horizVelocityCounter > 0) { @@ -167,7 +163,7 @@ public class MovingEventManager extends EventManagerImpl { @Override protected void handlePlayerVelocityEvent(final PlayerVelocityEvent event, final Priority priority) { - final MovingData data = plugin.getPlayer(event.getPlayer()).getData().moving; + final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore()); final Vector v = event.getVelocity(); @@ -186,25 +182,27 @@ public class MovingEventManager extends EventManagerImpl { } } - public List getActiveChecks(ConfigurationCache cc) { + public List getActiveChecks(ConfigurationCacheStore cc) { LinkedList s = new LinkedList(); - if(cc.moving.check) { - if(cc.moving.runflyCheck) { + CCMoving m = MovingCheck.getConfig(cc); - if(!cc.moving.allowFlying) { + if(m.check) { + if(m.runflyCheck) { + + if(!m.allowFlying) { s.add("moving.runfly"); - if(cc.moving.swimmingCheck) + if(m.swimmingCheck) s.add("moving.swimming"); - if(cc.moving.sneakingCheck) + if(m.sneakingCheck) s.add("moving.sneaking"); - if(cc.moving.nofallCheck) + if(m.nofallCheck) s.add("moving.nofall"); } else s.add("moving.flying"); } - if(cc.moving.morePacketsCheck) + if(m.morePacketsCheck) s.add("moving.morepackets"); } 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 6151459f..eb140c54 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/NoFallCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/NoFallCheck.java @@ -5,10 +5,7 @@ import java.util.Locale; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; -import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving; -import cc.co.evenprime.bukkit.nocheat.data.MovingData; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; /** @@ -35,13 +32,13 @@ public class NoFallCheck extends MovingCheck { data.lastAddedFallDistance = 0F; return null; } - + // This check is pretty much always a step behind for technical reasons. if(data.fromOnOrInGround) { // Start with zero fall distance data.fallDistance = 0F; } - + // If we increased fall height before for no good reason, reduce now by // the same amount if(player.getPlayer().getFallDistance() > data.lastAddedFallDistance) { @@ -115,9 +112,9 @@ public class NoFallCheck extends MovingCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().moving.nofallVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).nofallVL); else if(wildcard == ParameterName.FALLDISTANCE) - return String.format(Locale.US, "%.2f", player.getData().moving.fallDistance); + return String.format(Locale.US, "%.2f", getData(player.getDataStore()).fallDistance); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunflyCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunflyCheck.java index 075955cf..34a88358 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunflyCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunflyCheck.java @@ -2,10 +2,7 @@ package cc.co.evenprime.bukkit.nocheat.checks.moving; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving; -import cc.co.evenprime.bukkit.nocheat.data.MovingData; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; public class RunflyCheck extends MovingCheck { 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 882e05d9..e99472ea 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunningCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunningCheck.java @@ -6,10 +6,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; -import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving; -import cc.co.evenprime.bukkit.nocheat.data.MovingData; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; /** @@ -232,9 +229,9 @@ public class RunningCheck extends MovingCheck { if(wildcard == ParameterName.CHECK) // Workaround for something until I find a better way to do it - return getName() + "." + player.getData().moving.checknamesuffix; + return getName() + "." + getData(player.getDataStore()).checknamesuffix; else if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", (int) player.getData().moving.runflyVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).runflyVL); else return super.getParameter(wildcard, player); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCDebug.java b/src/cc/co/evenprime/bukkit/nocheat/config/CCDebug.java similarity index 70% rename from src/cc/co/evenprime/bukkit/nocheat/config/cache/CCDebug.java rename to src/cc/co/evenprime/bukkit/nocheat/config/CCDebug.java index 469cf1f3..a7578e90 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCDebug.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/CCDebug.java @@ -1,6 +1,4 @@ -package cc.co.evenprime.bukkit.nocheat.config.cache; - -import cc.co.evenprime.bukkit.nocheat.config.Configuration; +package cc.co.evenprime.bukkit.nocheat.config; public class CCDebug { diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCLogging.java b/src/cc/co/evenprime/bukkit/nocheat/config/CCLogging.java similarity index 86% rename from src/cc/co/evenprime/bukkit/nocheat/config/cache/CCLogging.java rename to src/cc/co/evenprime/bukkit/nocheat/config/CCLogging.java index 2832d141..144eda48 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCLogging.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/CCLogging.java @@ -1,8 +1,7 @@ -package cc.co.evenprime.bukkit.nocheat.config.cache; +package cc.co.evenprime.bukkit.nocheat.config; import java.util.logging.Logger; -import cc.co.evenprime.bukkit.nocheat.config.Configuration; import cc.co.evenprime.bukkit.nocheat.log.Colors; import cc.co.evenprime.bukkit.nocheat.log.LogLevel; diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java b/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java index 1dc49651..234b251d 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java @@ -37,10 +37,10 @@ public abstract class Configuration { public static final OptionNode INVENTORY_CHECK = new OptionNode("check", INVENTORY, DataType.BOOLEAN); private final static OptionNode INVENTORY_DROP = new OptionNode("drop", INVENTORY, DataType.PARENT); - public final static OptionNode INVENTORY_DROP_CHECK = new OptionNode("check", INVENTORY_DROP, DataType.BOOLEAN); - public final static OptionNode INVENTORY_DROP_TIMEFRAME = new OptionNode("timeframe", INVENTORY_DROP, DataType.INTEGER); - public final static OptionNode INVENTORY_DROP_LIMIT = new OptionNode("limit", INVENTORY_DROP, DataType.INTEGER); - public final static OptionNode INVENTORY_DROP_ACTIONS = new OptionNode("actions", INVENTORY_DROP, DataType.ACTIONLIST); + public final static OptionNode INVENTORY_DROP_CHECK = new OptionNode("check", INVENTORY_DROP, DataType.BOOLEAN); + public final static OptionNode INVENTORY_DROP_TIMEFRAME = new OptionNode("timeframe", INVENTORY_DROP, DataType.INTEGER); + public final static OptionNode INVENTORY_DROP_LIMIT = new OptionNode("limit", INVENTORY_DROP, DataType.INTEGER); + public final static OptionNode INVENTORY_DROP_ACTIONS = new OptionNode("actions", INVENTORY_DROP, DataType.ACTIONLIST); private final static OptionNode MOVING = new OptionNode("moving", ROOT, DataType.PARENT); public final static OptionNode MOVING_CHECK = new OptionNode("check", MOVING, DataType.BOOLEAN); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationCacheStore.java b/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationCacheStore.java new file mode 100644 index 00000000..7641c79f --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationCacheStore.java @@ -0,0 +1,48 @@ +package cc.co.evenprime.bukkit.nocheat.config; + +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; + +import cc.co.evenprime.bukkit.nocheat.ConfigItem; + +/** + * A class to keep all configurables of the plugin associated with + * a world + * + */ +public class ConfigurationCacheStore { + + public final CCLogging logging; + public final CCDebug debug; + + private final Map configMap = new HashMap(); + + private final Configuration data; + + /** + * Instantiate a config cache and populate it with the data of a + * Config tree (and its parent tree) + */ + public ConfigurationCacheStore(Configuration data, Logger worldSpecificFileLogger) { + + logging = new CCLogging(data, worldSpecificFileLogger); + debug = new CCDebug(data); + + this.data = data; + } + + @SuppressWarnings("unchecked") + public T get(String id) { + return (T) configMap.get(id); + } + + public void set(String id, ConfigItem config) { + + configMap.put(id, config); + } + + public Configuration getConfiguration() { + return this.data; + } +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java b/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java index 12a71bd1..b51cd8a9 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/ConfigurationManager.java @@ -15,7 +15,6 @@ import java.util.logging.Level; 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; /** @@ -24,17 +23,17 @@ import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper; */ public class ConfigurationManager { - private final static String configFileName = "config.txt"; - private final static String actionFileName = "actions.txt"; - private final static String defaultActionFileName = "default_actions.txt"; + private final static String configFileName = "config.txt"; + private final static String actionFileName = "actions.txt"; + private final static String defaultActionFileName = "default_actions.txt"; - private final Map worldnameToConfigCacheMap = new HashMap(); + private final Map worldnameToConfigCacheMap = new HashMap(); // Only use one filehandler per file, therefore keep open filehandlers in a // map - private final Map fileToFileHandlerMap = new HashMap(); + private final Map fileToFileHandlerMap = new HashMap(); - private final Configuration defaultConfig; + private final Configuration defaultConfig; private static class LogFileFormatter extends Formatter { @@ -136,7 +135,7 @@ public class ConfigurationManager { // Create a corresponding Configuration Cache // put the global config on the config map - worldnameToConfigCacheMap.put(null, new ConfigurationCache(root, setupFileLogger(new File(rootConfigFolder, root.getString(DefaultConfiguration.LOGGING_FILENAME))))); + worldnameToConfigCacheMap.put(null, new ConfigurationCacheStore(root, setupFileLogger(new File(rootConfigFolder, root.getString(DefaultConfiguration.LOGGING_FILENAME))))); // Try to find world-specific config files Map worldFiles = getWorldSpecificConfigFiles(rootConfigFolder); @@ -162,9 +161,9 @@ public class ConfigurationManager { } } - private ConfigurationCache createConfigurationCache(File rootConfigFolder, Configuration configProvider) { + private ConfigurationCacheStore createConfigurationCache(File rootConfigFolder, Configuration configProvider) { - return new ConfigurationCache(configProvider, setupFileLogger(new File(rootConfigFolder, configProvider.getString(DefaultConfiguration.LOGGING_FILENAME)))); + return new ConfigurationCacheStore(configProvider, setupFileLogger(new File(rootConfigFolder, configProvider.getString(DefaultConfiguration.LOGGING_FILENAME)))); } @@ -238,7 +237,7 @@ public class ConfigurationManager { public void cleanup() { // Remove handlers from the logger - for(ConfigurationCache c : worldnameToConfigCacheMap.values()) { + for(ConfigurationCacheStore c : worldnameToConfigCacheMap.values()) { for(Handler h : c.logging.filelogger.getHandlers()) { c.logging.filelogger.removeHandler(h); } @@ -258,9 +257,9 @@ public class ConfigurationManager { * @param worldname * @return */ - public ConfigurationCache getConfigurationCacheForWorld(String worldname) { + public ConfigurationCacheStore getConfigurationCacheForWorld(String worldname) { - ConfigurationCache cache = worldnameToConfigCacheMap.get(worldname); + ConfigurationCacheStore cache = worldnameToConfigCacheMap.get(worldname); if(cache != null) { return cache; diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java b/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java index d0e43cad..a493230a 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java @@ -30,7 +30,7 @@ public class Explainations { set(Configuration.INVENTORY_PREVENTITEMDUPE, "Close inventories of players before they get teleported between worlds, preventing creation of duplicate items."); set(Configuration.INVENTORY_CHECK, "If true, do various checks on Inventory related things."); set(Configuration.INVENTORY_DROP_CHECK, "If true, prevent players from dropping too many items in a short timeframe to reduce lag"); - set(Configuration.INVENTORY_DROP_TIMEFRAME , "Over how many seconds should item drops be counted."); + set(Configuration.INVENTORY_DROP_TIMEFRAME, "Over how many seconds should item drops be counted."); set(Configuration.INVENTORY_DROP_LIMIT, "How many seperate items should the player be allowed to drop during that timeframe"); set(Configuration.INVENTORY_DROP_ACTIONS, "What should be done if a player drops more items than that.\nUnit is item drops above the limit."); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/ConfigurationCache.java b/src/cc/co/evenprime/bukkit/nocheat/config/cache/ConfigurationCache.java deleted file mode 100644 index 89f3e609..00000000 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/ConfigurationCache.java +++ /dev/null @@ -1,38 +0,0 @@ -package cc.co.evenprime.bukkit.nocheat.config.cache; - -import java.util.logging.Logger; - -import cc.co.evenprime.bukkit.nocheat.config.Configuration; - -/** - * A class to keep all configurables of the plugin associated with - * a world, everything unmodifiable for security/performance - * - */ -public class ConfigurationCache { - - public final CCMoving moving; - public final CCLogging logging; - public final CCBlockBreak blockbreak; - public final CCBlockPlace blockplace; - public final CCChat chat; - public final CCDebug debug; - public final CCFight fight; - public final CCInventory inventory; - - /** - * Instantiate a config cache and populate it with the data of a - * Config tree (and its parent tree) - */ - public ConfigurationCache(Configuration data, Logger worldSpecificFileLogger) { - - moving = new CCMoving(data); - blockbreak = new CCBlockBreak(data); - blockplace = new CCBlockPlace(data); - chat = new CCChat(data); - logging = new CCLogging(data, worldSpecificFileLogger); - debug = new CCDebug(data); - fight = new CCFight(data); - inventory = new CCInventory(data); - } -} diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/BaseData.java b/src/cc/co/evenprime/bukkit/nocheat/data/BaseData.java deleted file mode 100644 index f9784a73..00000000 --- a/src/cc/co/evenprime/bukkit/nocheat/data/BaseData.java +++ /dev/null @@ -1,47 +0,0 @@ -package cc.co.evenprime.bukkit.nocheat.data; - -import java.util.Map; - -public class BaseData extends Data { - - public final BlockBreakData blockbreak; - public final BlockPlaceData blockplace; - public final ChatData chat; - public final MovingData moving; - public final FightData fight; - public final InventoryData inventory; - - private final Data[] data; // for convenience - - private final long timestamp; - - public BaseData() { - this.blockbreak = new BlockBreakData(); - this.blockplace = new BlockPlaceData(); - this.chat = new ChatData(); - this.moving = new MovingData(); - this.fight = new FightData(); - this.inventory = new InventoryData(); - - data = new Data[] {this.blockbreak, this.blockplace, this.chat, - this.moving, this.fight, this.inventory}; - - this.timestamp = System.currentTimeMillis(); - - } - - public void clearCriticalData() { - for(Data d : data) { - d.clearCriticalData(); - } - } - - public void collectData(Map map) { - for(Data d : data) { - d.collectData(map); - } - - map.put("nocheat.starttime", timestamp); - map.put("nocheat.endtime", System.currentTimeMillis()); - } -} diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java b/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java index 1ed526b8..8812c7b1 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java @@ -2,10 +2,12 @@ package cc.co.evenprime.bukkit.nocheat.data; import java.util.Map; +import cc.co.evenprime.bukkit.nocheat.DataItem; + /** * */ -public class ChatData extends Data { +public class ChatData implements DataItem { public int spamVL; public int spamTotalVL; @@ -26,4 +28,9 @@ public class ChatData extends Data { map.put("chat.spam.failed", spamFailed); map.put("chat.empty.failed", emptyFailed); } + + @Override + public void clearCriticalData() { + + } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/DataStore.java b/src/cc/co/evenprime/bukkit/nocheat/data/DataStore.java new file mode 100644 index 00000000..df407774 --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/data/DataStore.java @@ -0,0 +1,37 @@ +package cc.co.evenprime.bukkit.nocheat.data; + +import java.util.HashMap; +import java.util.Map; + +import cc.co.evenprime.bukkit.nocheat.DataItem; + +public class DataStore { + + private final Map dataMap = new HashMap(); + + private final long timestamp = System.currentTimeMillis(); + + @SuppressWarnings("unchecked") + public T get(String id) { + return (T) dataMap.get(id); + } + + public void set(String id, DataItem data) { + dataMap.put(id, data); + } + + public void clearCriticalData() { + for(DataItem data : dataMap.values()) { + data.clearCriticalData(); + } + } + + public void collectData(Map map) { + for(DataItem data : dataMap.values()) { + data.collectData(map); + } + + map.put("nocheat.starttime", timestamp); + map.put("nocheat.endtime", System.currentTimeMillis()); + } +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/PlayerManager.java b/src/cc/co/evenprime/bukkit/nocheat/data/PlayerManager.java index c286229c..2b89486a 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/PlayerManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/PlayerManager.java @@ -52,14 +52,14 @@ public class PlayerManager { */ public void clearCriticalData() { for(NoCheatPlayer b : this.players.values()) { - b.getData().clearCriticalData(); + b.getDataStore().clearCriticalData(); } } public void clearCriticalData(String playerName) { NoCheatPlayer p = this.players.get(playerName.toLowerCase()); if(p != null) { - p.getData().clearCriticalData(); + p.getDataStore().clearCriticalData(); } } @@ -83,9 +83,8 @@ public class PlayerManager { NoCheatPlayer player = this.players.get(playerName.toLowerCase()); if(player != null) { - BaseData data = player.getData(); + player.getDataStore().collectData(map); - data.collectData(map); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java b/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java index 04b08dfa..ecdb6a86 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java +++ b/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java @@ -6,7 +6,7 @@ import org.bukkit.World; import cc.co.evenprime.bukkit.nocheat.EventManager; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl; import cc.co.evenprime.bukkit.nocheat.log.LogLevel; @@ -24,7 +24,7 @@ public class ActiveCheckPrinter { int length = line.length(); - ConfigurationCache cc = plugin.getConfig(world); + ConfigurationCacheStore cc = plugin.getConfig(world); if(!cc.debug.showchecks) continue; diff --git a/src/cc/co/evenprime/bukkit/nocheat/debug/LagMeasureTask.java b/src/cc/co/evenprime/bukkit/nocheat/debug/LagMeasureTask.java index b97fc2dd..51087a23 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/debug/LagMeasureTask.java +++ b/src/cc/co/evenprime/bukkit/nocheat/debug/LagMeasureTask.java @@ -27,7 +27,7 @@ public class LagMeasureTask implements Runnable { // If the previous second took to long, skip checks during // this second skipCheck = lastIngamesecondDuration > 1500; - + long time = System.currentTimeMillis(); lastIngamesecondDuration = time - lastIngamesecondTime; if(lastIngamesecondDuration < 1000) @@ -38,13 +38,12 @@ public class LagMeasureTask implements Runnable { } lastIngamesecondTime = time; ingameseconds++; - + // Check if some data is outdated now and let it be removed if(ingameseconds % 62 == 0) { plugin.cleanDataMap(); } - } - catch(Exception e) { + } catch(Exception e) { // Just prevent this thread from dying for whatever reason } diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/EventManagerImpl.java b/src/cc/co/evenprime/bukkit/nocheat/events/EventManagerImpl.java index aaafc1bc..6b4eb7fa 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/EventManagerImpl.java +++ b/src/cc/co/evenprime/bukkit/nocheat/events/EventManagerImpl.java @@ -31,7 +31,7 @@ import org.bukkit.event.player.PlayerVelocityEvent; import cc.co.evenprime.bukkit.nocheat.EventManager; import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.debug.Performance; /** @@ -157,7 +157,7 @@ public abstract class EventManagerImpl implements EventManager { m.handlePlayerMoveEvent(event, priority); } } - + @Override public void onPlayerDropItem(final PlayerDropItemEvent event) { if(ignoreCancelledEvents && event.isCancelled()) @@ -382,7 +382,7 @@ public abstract class EventManagerImpl implements EventManager { * .co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache) */ @Override - public List getActiveChecks(ConfigurationCache cc) { + public List getActiveChecks(ConfigurationCacheStore cc) { return Collections.emptyList(); } @@ -453,7 +453,7 @@ public abstract class EventManagerImpl implements EventManager { protected void handleCustomDamageByPlayerEvent(EntityDamageByEntityEvent event, Priority priority) { handleEvent(event, priority); } - + protected void handlePlayerDropItemEvent(PlayerDropItemEvent event, Priority priority) { handleEvent(event, priority); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/WorkaroundsEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/events/WorkaroundsEventManager.java index 1f7a0ab7..28275c9f 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/WorkaroundsEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/events/WorkaroundsEventManager.java @@ -1,7 +1,6 @@ package cc.co.evenprime.bukkit.nocheat.events; import org.bukkit.Location; -import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.Event.Priority; @@ -56,7 +55,7 @@ public class WorkaroundsEventManager extends EventManagerImpl { // Fix a common mistake that other developers make (cancelling move // events is crazy, rather set the target location to the from location) - if(plugin.getPlayer(event.getPlayer()).getConfiguration().debug.overrideIdiocy) { + if(plugin.getPlayer(event.getPlayer()).getConfigurationStore().debug.overrideIdiocy) { event.setCancelled(false); event.setTo(event.getFrom().clone()); } @@ -65,15 +64,12 @@ public class WorkaroundsEventManager extends EventManagerImpl { @Override protected void handlePlayerToggleSprintEvent(final PlayerToggleSprintEvent event, final Priority priority) { if(event.isCancelled() && event.isSprinting()) { - if(plugin.getPlayer(event.getPlayer()).getConfiguration().debug.overrideIdiocy) + if(plugin.getPlayer(event.getPlayer()).getConfigurationStore().debug.overrideIdiocy) event.setCancelled(false); } } private void handleTeleportation(final Player player, final Location to) { - if(plugin.getPlayer(player).getConfiguration().inventory.closebeforeteleports && player instanceof CraftPlayer && to != null && !(to.getWorld().equals(player.getWorld()))) { - ((CraftPlayer) player).getHandle().closeInventory(); - } plugin.clearCriticalData(player.getName()); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/log/LogManager.java b/src/cc/co/evenprime/bukkit/nocheat/log/LogManager.java index 269d7e55..2a6b2126 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/log/LogManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/log/LogManager.java @@ -6,8 +6,8 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; import cc.co.evenprime.bukkit.nocheat.config.Permissions; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; /** * Manage logging throughout NoCheat. Messages may be logged directly to a @@ -28,7 +28,7 @@ public class LogManager { * @param message * @param cc */ - public void log(LogLevel level, String message, ConfigurationCache cc) { + public void log(LogLevel level, String message, ConfigurationCacheStore cc) { if(!cc.logging.active) return; diff --git a/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java b/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java index d167a72b..1cf13410 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java +++ b/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java @@ -1,7 +1,5 @@ package cc.co.evenprime.bukkit.nocheat.player; -import java.lang.reflect.Method; - import net.minecraft.server.EntityPlayer; import net.minecraft.server.MobEffectList; @@ -11,30 +9,29 @@ import org.bukkit.entity.Player; import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; -import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; -import cc.co.evenprime.bukkit.nocheat.data.BaseData; +import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; +import cc.co.evenprime.bukkit.nocheat.data.DataStore; public class NoCheatPlayerImpl implements NoCheatPlayer { - protected Player player; - protected final NoCheat plugin; - protected final BaseData data; - protected long lastUsedTime; - - // The method that's used to artifically "fast-forward" the player - protected static Method incAge = null; + protected Player player; + protected final NoCheat plugin; + protected final DataStore data; + protected ConfigurationCacheStore config; + protected long lastUsedTime; public NoCheatPlayerImpl(Player player, NoCheat plugin) { this.player = player; this.plugin = plugin; - this.data = new BaseData(); + this.data = new DataStore(); this.lastUsedTime = System.currentTimeMillis(); } public void refresh(Player player) { this.player = player; + this.config = plugin.getConfig(player); } public boolean isDead() { @@ -49,18 +46,18 @@ public class NoCheatPlayerImpl implements NoCheatPlayer { return player.hasPermission(permission); } - public BaseData getData() { + public DataStore getDataStore() { return data; } + public ConfigurationCacheStore getConfigurationStore() { + return config; + } + public Player getPlayer() { return player; } - public ConfigurationCache getConfiguration() { - return plugin.getConfig(player); - } - public String getName() { return player.getName(); }