diff --git a/pom.xml b/pom.xml index 24c8100e..3392b2a5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cc.co.evenprime.bukkit NoCheat - 3.2.1 + 3.2.2 jar NoCheat diff --git a/src/cc/co/evenprime/bukkit/nocheat/DataItem.java b/src/cc/co/evenprime/bukkit/nocheat/DataItem.java index 57088e19..4e92eea4 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/DataItem.java +++ b/src/cc/co/evenprime/bukkit/nocheat/DataItem.java @@ -1,13 +1,8 @@ package cc.co.evenprime.bukkit.nocheat; -import java.util.Map; - /** * * Every class that is extending this has to implement an empty Constructor() * */ -public interface DataItem { - - public abstract void collectData(Map map); -} +public interface DataItem {} diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java index 718e8043..f1e77ed8 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java @@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.TreeMap; import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.World; @@ -170,9 +169,7 @@ public class NoCheat extends JavaPlugin implements Listener { */ public Map getPlayerData(String playerName) { - Map map = new TreeMap(); - - players.getPlayerData(playerName, map); + Map map = players.getPlayerData(playerName); map.put("nocheat.version", this.getDescription().getVersion()); diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java b/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java index fea6e0dd..a5cc4a7b 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java @@ -16,6 +16,7 @@ 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.ConfigurationCacheStore; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public abstract class Check { @@ -66,6 +67,10 @@ public abstract class Check { return special; } + protected void incrementStatistics(NoCheatPlayer player, Id id, double vl) { + player.getDataStore().getStatistics().increment(id, vl); + } + private final void executeLogAction(LogAction l, Check check, NoCheatPlayer player, ConfigurationCacheStore cc) { if(!cc.logging.active) diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakData.java index 7bff4f3c..0ee0dec9 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/BlockBreakData.java @@ -1,6 +1,5 @@ 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.SimpleLocation; @@ -11,14 +10,8 @@ import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; public class BlockBreakData implements DataItem { public double reachVL = 0.0D; - public double reachTotalVL = 0.0D; - public int reachFailed = 0; public double directionVL = 0.0D; - public double directionTotalVL = 0.0D; - public int directionFailed = 0; public double noswingVL = 0.0D; - public double noswingTotalVL = 0.0D; - public int noswingFailed = 0; public long directionLastViolationTime = 0; public final SimpleLocation instaBrokenBlockLocation = new SimpleLocation(); @@ -27,14 +20,4 @@ public class BlockBreakData implements DataItem { public double reachDistance; public boolean armswung = true; public final SimpleLocation lastDamagedBlock = new SimpleLocation(); - - @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.failed", reachFailed); - map.put("blockbreak.direction.failed", directionFailed); - map.put("blockbreak.noswing.failed", noswingFailed); - } } 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 a34a11f4..2bf71573 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/DirectionCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/DirectionCheck.java @@ -7,6 +7,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; /** * The DirectionCheck will find out if a player tried to interact with something @@ -42,8 +43,7 @@ public class DirectionCheck extends BlockBreakCheck { off /= 10; } data.directionVL += off; - data.directionTotalVL += off; - data.directionFailed++; + incrementStatistics(player, Id.BB_DIRECTION, off); cancel = executeActions(player, ccblockbreak.directionActions.getActions(data.directionVL)); 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 2000136a..f3331063 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/NoswingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/NoswingCheck.java @@ -1,11 +1,11 @@ package cc.co.evenprime.bukkit.nocheat.checks.blockbreak; 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.Permissions; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public class NoswingCheck extends BlockBreakCheck { @@ -23,8 +23,7 @@ public class NoswingCheck extends BlockBreakCheck { data.noswingVL *= 0.90D; } else { data.noswingVL += 1; - data.noswingTotalVL += 1; - data.noswingFailed++; + incrementStatistics(player, Id.BB_NOSWING, 1); cancel = executeActions(player, cc.noswingActions.getActions(data.noswingVL)); } 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 b52a4809..d0c7af79 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/ReachCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockbreak/ReachCheck.java @@ -7,6 +7,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; /** * The reach check will find out if a player interacts with something that's too @@ -32,8 +33,7 @@ public class ReachCheck extends BlockBreakCheck { // Increment violation counter data.reachVL += distance; - data.reachTotalVL += distance; - data.reachFailed++; + incrementStatistics(player, Id.BB_REACH, distance); data.reachDistance = distance; cancel = executeActions(player, cc.reachActions.getActions(data.reachVL)); diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceData.java index 83f91591..d282020b 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/BlockPlaceData.java @@ -1,6 +1,5 @@ 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.SimpleLocation; @@ -9,30 +8,12 @@ import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; */ public class BlockPlaceData implements DataItem { - public double reachVL = 0.0D; - public double reachTotalVL = 0.0D; - public int reachFailed = 0; - public double directionVL = 0.0D; - public double directionTotalVL = 0.0D; - public int directionFailed = 0; + public double reachVL = 0.0D; + public double directionVL = 0.0D; - public long directionLastViolationTime = 0; + public long directionLastViolationTime = 0; - public final SimpleLocation blockPlacedAgainst = new SimpleLocation(); - public final SimpleLocation blockPlaced = new SimpleLocation(); - public double reachdistance; - - public void clearCriticalData() { - blockPlacedAgainst.reset(); - blockPlaced.reset(); - directionLastViolationTime = 0; - } - - @Override - public void collectData(Map map) { - map.put("blockplace.reach.vl", (int) reachTotalVL); - map.put("blockplace.direction.vl", (int) directionTotalVL); - map.put("blockplace.reach.failed", reachFailed); - map.put("blockplace.direction.failed", directionFailed); - } + public final SimpleLocation blockPlacedAgainst = new SimpleLocation(); + public final SimpleLocation blockPlaced = new SimpleLocation(); + public double reachdistance; } 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 0d6861f7..50b664ee 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/DirectionCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/DirectionCheck.java @@ -1,13 +1,13 @@ 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.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public class DirectionCheck extends BlockPlaceCheck { @@ -59,8 +59,7 @@ public class DirectionCheck extends BlockPlaceCheck { // Player failed the check // Increment violation counter data.directionVL += off; - data.directionTotalVL += off; - data.directionFailed++; + incrementStatistics(player, Id.BP_DIRECTION, off); // Prepare some event-specific values for logging and custom actions 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 ca0779b5..2d2c253f 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/ReachCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/blockplace/ReachCheck.java @@ -1,13 +1,13 @@ 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.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; /** * The reach check will find out if a player interacts with something that's too @@ -33,8 +33,7 @@ public class ReachCheck extends BlockPlaceCheck { // Increment violation counter data.reachVL += distance; - data.reachTotalVL += distance; - data.reachFailed++; + incrementStatistics(player, Id.BP_REACH, distance); data.reachdistance = distance; cancel = executeActions(player, cc.reachActions.getActions(data.reachVL)); diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatData.java index 9090b6b1..e431f1bf 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatData.java @@ -1,6 +1,5 @@ package cc.co.evenprime.bukkit.nocheat.checks.chat; -import java.util.Map; import cc.co.evenprime.bukkit.nocheat.DataItem; /** @@ -9,22 +8,10 @@ import cc.co.evenprime.bukkit.nocheat.DataItem; public class ChatData implements DataItem { public int spamVL; - public int spamTotalVL; - public int spamFailed; public int colorVL; - public int colorTotalVL; - public int colorFailed; public int messageCount = 0; public int commandCount = 0; public long spamLastTime = 0; public String message = ""; - - @Override - public void collectData(Map map) { - map.put("chat.spam.vl", (int) spamTotalVL); - map.put("chat.color.vl", (int) colorTotalVL); - map.put("chat.spam.failed", spamFailed); - map.put("chat.color.failed", colorFailed); - } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ColorCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ColorCheck.java index 976eac6f..25ca3bb5 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ColorCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ColorCheck.java @@ -5,6 +5,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.config.Permissions; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public class ColorCheck extends ChatCheck { @@ -17,8 +18,7 @@ public class ColorCheck extends ChatCheck { if(data.message.matches(".*\247.*")) { data.colorVL += 1; - data.colorTotalVL += 1; - data.colorFailed++; + incrementStatistics(player, Id.CHAT_COLOR, 1); boolean filter = executeActions(player, cc.colorActions.getActions(data.colorVL)); 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 7140ed5d..442e328f 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/SpamCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/SpamCheck.java @@ -5,6 +5,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.config.Permissions; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public class SpamCheck extends ChatCheck { @@ -44,8 +45,7 @@ public class SpamCheck extends ChatCheck { data.spamVL = Math.max(0, data.messageCount - cc.spamLimit); data.spamVL += Math.max(0, data.commandCount - cc.commandLimit); - data.spamTotalVL++; - data.spamFailed++; + incrementStatistics(player, Id.CHAT_SPAM, 1); cancel = executeActions(player, cc.spamActions.getActions(data.spamVL)); } 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 580e1677..91d679f0 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/DirectionCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/DirectionCheck.java @@ -1,7 +1,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.fight; import java.util.Locale; - import net.minecraft.server.Entity; import net.minecraft.server.EntityComplex; import net.minecraft.server.EntityComplexPart; @@ -11,6 +10,7 @@ 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.config.Permissions; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public class DirectionCheck extends FightCheck { @@ -51,8 +51,7 @@ public class DirectionCheck extends FightCheck { if(!plugin.skipCheck()) { double sqrt = Math.sqrt(off); data.directionVL += sqrt; - data.directionTotalVL += sqrt; - data.directionFailed++; + incrementStatistics(player, Id.FI_DIRECTION, sqrt); } cancel = executeActions(player, cc.directionActions.getActions(data.directionVL)); diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightData.java index 1c3ef394..99a16c0c 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/FightData.java @@ -1,23 +1,14 @@ package cc.co.evenprime.bukkit.nocheat.checks.fight; -import java.util.Map; import net.minecraft.server.Entity; import cc.co.evenprime.bukkit.nocheat.DataItem; public class FightData implements DataItem { public double directionVL; - public double directionTotalVL; - public int directionFailed; public double noswingVL; - public double noswingTotalVL; - public int noswingFailed; public double reachVL; - public double reachTotalVL; - public int reachFailed; public int speedVL; - public int speedTotalVL; - public int speedFailed; public long directionLastViolationTime; public long reachLastViolationTime; @@ -28,19 +19,4 @@ public class FightData implements DataItem { public long speedTime; public int speedAttackCount; - - @Override - public void collectData(Map map) { - map.put("fight.direction.vl", (int) directionTotalVL); - map.put("fight.noswing.vl", (int) noswingTotalVL); - map.put("fight.reach.vl", (int) reachTotalVL); - map.put("fight.speed.vl", (int) speedTotalVL); - - - map.put("fight.direction.failed", (int) directionFailed); - map.put("fight.noswing.failed", (int) noswingFailed); - map.put("fight.reach.failed", (int) reachFailed); - map.put("fight.speed.failed", (int) speedFailed); - - } } 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 5c627842..4580b331 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/NoswingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/NoswingCheck.java @@ -1,11 +1,11 @@ package cc.co.evenprime.bukkit.nocheat.checks.fight; 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.Permissions; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public class NoswingCheck extends FightCheck { @@ -23,8 +23,7 @@ public class NoswingCheck extends FightCheck { data.noswingVL *= 0.90D; } else { data.noswingVL += 1; - data.noswingTotalVL += 1; - data.noswingFailed++; + incrementStatistics(player, Id.FI_NOSWING, 1); cancel = executeActions(player, cc.noswingActions.getActions(data.noswingVL)); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/ReachCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/ReachCheck.java index b030c3a1..77d89db9 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/ReachCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/ReachCheck.java @@ -10,6 +10,7 @@ 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.config.Permissions; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public class ReachCheck extends FightCheck { @@ -49,8 +50,7 @@ public class ReachCheck extends FightCheck { if(!plugin.skipCheck()) { double sqrt = Math.sqrt(off); data.reachVL += sqrt; - data.reachTotalVL += sqrt; - data.reachFailed++; + incrementStatistics(player, Id.FI_REACH, sqrt); } cancel = executeActions(player, cc.reachActions.getActions(data.reachVL)); diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/SpeedCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/SpeedCheck.java index 1ca8f73c..12e51479 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/fight/SpeedCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/fight/SpeedCheck.java @@ -5,6 +5,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.config.Permissions; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public class SpeedCheck extends FightCheck { @@ -29,8 +30,7 @@ public class SpeedCheck extends FightCheck { if(data.speedAttackCount > cc.speedAttackLimit) { if(!plugin.skipCheck()) { data.speedVL += 1; - data.speedTotalVL += 1; - data.speedFailed++; + incrementStatistics(player, Id.FI_SPEED, 1); } cancel = executeActions(player, cc.speedActions.getActions(data.speedVL)); 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 c8546df1..d4666aa1 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/DropCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/DropCheck.java @@ -5,6 +5,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.config.Permissions; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public class DropCheck extends InventoryCheck { @@ -32,8 +33,7 @@ public class DropCheck extends InventoryCheck { if(data.dropCount > cc.dropLimit) { data.dropVL = data.dropCount - cc.dropLimit; - data.dropTotalVL++; - data.dropFailed++; + incrementStatistics(player, Id.INV_DROP, 1); cancel = executeActions(player, cc.dropActions.getActions(data.dropVL)); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InstantBowCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InstantBowCheck.java index a9ef0c36..6bdcfe2e 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InstantBowCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InstantBowCheck.java @@ -6,11 +6,12 @@ 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.Permissions; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public class InstantBowCheck extends InventoryCheck { public InstantBowCheck(NoCheat plugin) { - super(plugin, "fight.instantbow", Permissions.INVENTORY_INSTANTBOW); + super(plugin, "inventory.instantbow", Permissions.INVENTORY_INSTANTBOW); } public boolean check(NoCheatPlayer player, EntityShootBowEvent event, InventoryData data, InventoryConfig cc) { @@ -31,8 +32,7 @@ public class InstantBowCheck extends InventoryCheck { // Seems fishy, increase violation level int vl = ((int) (expectedTimeWhenStringDrawn - time)) / 100; data.instantBowVL += vl; - data.instantBowTotalVL += vl; - data.instantBowFailed++; + incrementStatistics(player, Id.INV_BOW, vl); cancelled = executeActions(player, cc.bowActions.getActions(data.instantBowVL)); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InstantEatCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InstantEatCheck.java index d1fe03da..7d8b1e11 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InstantEatCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InstantEatCheck.java @@ -6,6 +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.config.Permissions; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; public class InstantEatCheck extends InventoryCheck { @@ -34,8 +35,7 @@ public class InstantEatCheck extends InventoryCheck { // Seems fishy, increase violation level int vl = ((int) (expectedTimeWhenEatingFinished - time)) / 100; data.instantEatVL += vl; - data.instantEatTotalVL += vl; - data.instantEatFailed++; + incrementStatistics(player, Id.INV_EAT, vl); cancelled = executeActions(player, cc.eatActions.getActions(data.instantEatVL)); } @@ -45,7 +45,7 @@ public class InstantEatCheck extends InventoryCheck { public String getParameter(ParameterName wildcard, NoCheatPlayer player) { if(wildcard == ParameterName.VIOLATIONS) - return String.format(Locale.US, "%d", getData(player.getDataStore()).instantEatVL); + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).instantEatVL); else if(wildcard == ParameterName.FOOD) return getData(player.getDataStore()).foodMaterial.toString(); else diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheckListener.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheckListener.java index e2d29dae..6ad85b80 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheckListener.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryCheckListener.java @@ -78,10 +78,10 @@ public class InventoryCheckListener implements Listener, EventManager { } else if(CheckUtil.isFood(event.getItem())) { // Remember food Material, because we don't have that info in the other event data.foodMaterial = event.getItem().getType(); - data.lastFoodInteractTime = System.currentTimeMillis(); + data.lastEatInteractTime = System.currentTimeMillis(); } else { data.lastBowInteractTime = 0; - data.lastFoodInteractTime = 0; + data.lastEatInteractTime = 0; data.foodMaterial = null; } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryData.java index f70708b1..c8421fe5 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/inventory/InventoryData.java @@ -1,40 +1,18 @@ package cc.co.evenprime.bukkit.nocheat.checks.inventory; -import java.util.Map; import org.bukkit.Material; import cc.co.evenprime.bukkit.nocheat.DataItem; public class InventoryData implements DataItem { public int dropVL; - public double dropTotalVL; - public int dropFailed; public long dropLastTime; public int dropCount; public int instantBowVL; - public int instantBowTotalVL; - public int instantBowFailed; + public long lastBowInteractTime; public double instantEatVL; - public int instantEatTotalVL; - public int instantEatFailed; - - public long lastBowInteractTime; - public int lastEatInteractTime; + public long lastEatInteractTime; public Material foodMaterial; - public long lastFoodInteractTime; - public int newFoodLevel; - - @Override - public void collectData(Map map) { - map.put("inventory.drop.vl", (int) dropTotalVL); - map.put("inventory.drop.failed", (int) dropFailed); - - map.put("inventory.instantbow.vl", (int) instantBowTotalVL); - map.put("inventory.instantbow.failed", (int) instantBowFailed); - - map.put("inventory.instanteat.vl", (int) instantEatTotalVL); - map.put("inventory.instanteat.failed", (int) instantEatFailed); - } } 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 d4df17b7..da0c1cb2 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/FlyingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/FlyingCheck.java @@ -5,6 +5,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.data.PreciseLocation; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; /** * A check designed for people that are allowed to fly. The complement to @@ -98,13 +99,11 @@ public class FlyingCheck extends MovingCheck { // Increment violation counter data.runflyVL += result; if(resultHoriz > 0) { - data.runflyRunningTotalVL += resultHoriz; - data.runflyRunningFailed++; + incrementStatistics(player, Id.MOV_RUNNING, resultHoriz); } if(resultVert > 0) { - data.runflyFlyingTotalVL += resultVert; - data.runflyFlyingFailed++; + incrementStatistics(player, Id.MOV_FLYING, resultVert); } boolean cancel = executeActions(player, ccmoving.flyingActions.getActions(data.runflyVL)); 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 34a43fb1..ede98ddd 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java @@ -6,6 +6,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; /** * The morePacketsCheck (previously called SpeedhackCheck) will try to identify @@ -51,8 +52,7 @@ public class MorePacketsCheck extends MovingCheck { if(data.morePacketsBuffer < 0) { data.morePacketsVL = -data.morePacketsBuffer; - data.morePacketsTotalVL++; - data.morePacketsFailed++; + incrementStatistics(player, Id.MOV_MOREPACKETS, 1); data.packets = -data.morePacketsBuffer; @@ -64,7 +64,7 @@ public class MorePacketsCheck extends MovingCheck { if(data.morePacketsLastTime + 1000 < time) { // More than 1 second elapsed, but how many? - double seconds = ((double)(time - data.morePacketsLastTime)) / 1000D; + double seconds = ((double) (time - data.morePacketsLastTime)) / 1000D; // For each second, fill the buffer data.morePacketsBuffer += packetsPerTimeframe * seconds; @@ -84,7 +84,7 @@ public class MorePacketsCheck extends MovingCheck { // Set the new "last" time data.morePacketsLastTime = time; - + // Set the new "setback" location if(newToLocation == null) { data.morePacketsSetbackPoint.set(data.from); diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingData.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingData.java index 8af07bde..7fa26350 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MovingData.java @@ -1,8 +1,8 @@ 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.PreciseLocation; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; /** * Player specific data for the moving check group @@ -10,26 +10,8 @@ import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; public class MovingData implements DataItem { public double runflyVL; - - public double runflyRunningTotalVL; - public int runflyRunningFailed; - - public double runflyFlyingTotalVL; - public int runflyFlyingFailed; - - public double runflySneakingTotalVL; - public int runflySneakingFailed; - - public double runflySwimmingTotalVL; - public int runflySwimmingFailed; - public double nofallVL; - public double nofallTotalVL; - public int nofallFailed; - public double morePacketsVL; - public double morePacketsTotalVL; - public int morePacketsFailed; public int jumpPhase; public double lastJumpAmplifier; @@ -62,7 +44,7 @@ public class MovingData implements DataItem { public boolean fromOnOrInGround; public boolean toOnOrInGround; - public String checknamesuffix = ""; + public Id statisticCategory = Id.MOV_RUNNING; public int packets; @@ -77,21 +59,4 @@ public class MovingData implements DataItem { public void clearMorePacketsData() { morePacketsSetbackPoint.reset(); } - - @Override - public void collectData(Map map) { - map.put("moving.running.vl", (int) runflyRunningTotalVL); - map.put("moving.flying.vl", (int) runflyFlyingTotalVL); - map.put("moving.sneaking.vl", (int) runflySneakingTotalVL); - map.put("moving.swimming.vl", (int) runflySwimmingTotalVL); - map.put("moving.nofall.vl", (int) nofallTotalVL); - map.put("moving.morepackets.vl", (int) morePacketsTotalVL); - - map.put("moving.running.failed", runflyRunningFailed); - map.put("moving.flying.failed", runflyFlyingFailed); - map.put("moving.sneaking.failed", runflySneakingFailed); - map.put("moving.swimming.failed", runflySwimmingFailed); - map.put("moving.nofall.failed", nofallFailed); - map.put("moving.morepackets.failed", morePacketsFailed); - } } 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 ea90a68c..16df8c77 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/NoFallCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/NoFallCheck.java @@ -6,6 +6,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; /** * A check to see if people cheat by tricking the server to not deal them @@ -41,8 +42,7 @@ public class NoFallCheck extends MovingCheck { if(cc.nofallaggressive && data.fromOnOrInGround && data.toOnOrInGround && data.from.y <= data.to.y && player.getPlayer().getFallDistance() > 3.0F) { data.fallDistance = player.getPlayer().getFallDistance(); data.nofallVL += data.fallDistance; - data.nofallTotalVL += data.fallDistance; - data.nofallFailed++; + incrementStatistics(player, Id.MOV_NOFALL, data.fallDistance); final boolean cancel = executeActions(player, cc.nofallActions.getActions(data.nofallVL)); if(cancel) { player.dealFallDamage(); @@ -64,8 +64,7 @@ public class NoFallCheck extends MovingCheck { if(difference > 1.0F && data.toOnOrInGround && data.fallDistance > 2.0F) { data.nofallVL += difference; - data.nofallTotalVL += difference; - data.nofallFailed++; + incrementStatistics(player, Id.MOV_NOFALL, difference); final boolean cancel = executeActions(player, cc.nofallActions.getActions(data.nofallVL)); 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 eb004e70..7eac8e6b 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunningCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/RunningCheck.java @@ -9,6 +9,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil; import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; +import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id; /** * The counterpart to the FlyingCheck. People that are not allowed to fly @@ -76,19 +77,7 @@ public class RunningCheck extends MovingCheck { // Increment violation counter data.runflyVL += result; - if(data.checknamesuffix.equals("sneaking")) { - data.runflySneakingTotalVL += result; - data.runflySneakingFailed++; - } else if(data.checknamesuffix.equals("swimming")) { - data.runflySwimmingTotalVL += result; - data.runflySwimmingFailed++; - } else if(data.checknamesuffix.equals("vertical")) { - data.runflyFlyingTotalVL += result; - data.runflyFlyingFailed++; - } else { - data.runflyRunningTotalVL += result; - data.runflyRunningFailed++; - } + incrementStatistics(player, data.statisticCategory, result); boolean cancel = executeActions(player, cc.actions.getActions(data.runflyVL)); @@ -143,7 +132,7 @@ public class RunningCheck extends MovingCheck { double limit = 0.0D; - String suffix = null; + Id statisticsCategory = null; // Player on ice? Block b = player.getPlayer().getLocation().getBlock(); @@ -155,16 +144,16 @@ public class RunningCheck extends MovingCheck { if(cc.sneakingCheck && player.getPlayer().isSneaking() && !player.hasPermission(Permissions.MOVING_SNEAKING)) { limit = cc.sneakingSpeedLimit; - suffix = "sneaking"; + statisticsCategory = Id.MOV_SNEAKING; } else if(isSwimming && !player.hasPermission(Permissions.MOVING_SWIMMING)) { limit = cc.swimmingSpeedLimit; - suffix = "swimming"; + statisticsCategory = Id.MOV_SWIMMING; } else if(!sprinting) { limit = cc.walkingSpeedLimit; - suffix = "walking"; + statisticsCategory = Id.MOV_RUNNING; } else { limit = cc.sprintingSpeedLimit; - suffix = "sprinting"; + statisticsCategory = Id.MOV_RUNNING; } if(data.onIce > 0) { @@ -204,7 +193,7 @@ public class RunningCheck extends MovingCheck { } if(distanceAboveLimit > 0) { - data.checknamesuffix = suffix; + data.statisticCategory = statisticsCategory; } return distanceAboveLimit; @@ -235,7 +224,7 @@ public class RunningCheck extends MovingCheck { distanceAboveLimit = data.to.y - data.runflySetBackPoint.y - limit; if(distanceAboveLimit > 0) { - data.checknamesuffix = "vertical"; + data.statisticCategory = Id.MOV_FLYING; } if(toOnGround || fromOnGround) { @@ -254,7 +243,7 @@ public class RunningCheck extends MovingCheck { if(wildcard == ParameterName.CHECK) // Workaround for something until I find a better way to do it - return getName() + "." + getData(player.getDataStore()).checknamesuffix; + return getData(player.getDataStore()).statisticCategory.toString(); else if(wildcard == ParameterName.VIOLATIONS) return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).runflyVL); else diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/DataStore.java b/src/cc/co/evenprime/bukkit/nocheat/data/DataStore.java index 6ab3c745..28271ba4 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/DataStore.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/DataStore.java @@ -6,9 +6,10 @@ import cc.co.evenprime.bukkit.nocheat.DataItem; public class DataStore { - private final Map dataMap = new HashMap(); + private final Map dataMap = new HashMap(); + private final Statistics statistics = new Statistics(); - private final long timestamp = System.currentTimeMillis(); + private final long timestamp = System.currentTimeMillis(); @SuppressWarnings("unchecked") public T get(String id) { @@ -19,12 +20,15 @@ public class DataStore { dataMap.put(id, data); } - public void collectData(Map map) { - for(DataItem data : dataMap.values()) { - data.collectData(map); - } - + public Map collectData() { + Map map = statistics.get(); map.put("nocheat.starttime", timestamp); map.put("nocheat.endtime", System.currentTimeMillis()); + + return map; + } + + public Statistics getStatistics() { + return statistics; } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/PlayerManager.java b/src/cc/co/evenprime/bukkit/nocheat/data/PlayerManager.java index 3c57b6dd..7ade1ac1 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/PlayerManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/PlayerManager.java @@ -59,14 +59,15 @@ public class PlayerManager { } } - public void getPlayerData(String playerName, Map map) { + public Map getPlayerData(String playerName) { NoCheatPlayer player = this.players.get(playerName.toLowerCase()); if(player != null) { - player.getDataStore().collectData(map); - + return player.getDataStore().collectData(); } + + return new HashMap(); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/Statistics.java b/src/cc/co/evenprime/bukkit/nocheat/data/Statistics.java new file mode 100644 index 00000000..6933bd73 --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/data/Statistics.java @@ -0,0 +1,71 @@ +package cc.co.evenprime.bukkit.nocheat.data; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +public class Statistics { + + public enum Id { + + BB_DIRECTION("blockbreak.direction"), BB_NOSWING("blockbreak.noswing"), + BB_REACH("blockbreak.reach"), BP_DIRECTION("blockplace.direction"), + BP_REACH("blockplace.reach"), CHAT_COLOR("chat.color"), + CHAT_SPAM("chat.spam"), FI_DIRECTION("fight.direction"), + FI_NOSWING("fight.noswing"), FI_REACH("fight.reach"), + FI_SPEED("fight.speed"), INV_DROP("inventory.drop"), + INV_BOW("inventory.instantbow"), INV_EAT("inventory.instanteat"), + MOV_RUNNING("moving.running"), MOV_FLYING("moving.flying"), + MOV_MOREPACKETS("moving.morepackets"), MOV_NOFALL("moving.nofall"), + MOV_SNEAKING("moving.sneaking"), MOV_SWIMMING("moving.swimming"); + + private final String name; + + private Id(String name) { + this.name = name; + } + + public String toString() { + return this.name; + } + + } + + private final Map statisticVLs = new HashMap(Id.values().length); + private final Map statisticFails = new HashMap(Id.values().length); + + public Statistics() { + // Initialize statistic values + for(Id id : Id.values()) { + statisticVLs.put(id, 0D); + statisticFails.put(id, 0); + } + } + + public void increment(Id id, double vl) { + Double stored = statisticVLs.get(id); + if(stored == null) + stored = 0D; + statisticVLs.put(id, stored + vl); + + Integer failed = statisticFails.get(id); + if(failed == null) + failed = 0; + statisticFails.put(id, failed + 1); + } + + public Map get() { + Map map = new TreeMap(); + + for(Entry entry : statisticVLs.entrySet()) { + map.put(entry.getKey().toString() + ".vl", entry.getValue().intValue()); + } + + for(Entry entry : statisticFails.entrySet()) { + map.put(entry.getKey().toString() + ".failed", entry.getValue()); + } + + return map; + } +}