From ea414167e0673b4fe844d1bc7021c8e5350d568a Mon Sep 17 00:00:00 2001 From: Evenprime Date: Mon, 28 Feb 2011 16:57:15 +0100 Subject: [PATCH] New check "dupebydeath" + big changes to "speedhack" check --- plugin.yml | 2 +- .../bukkit/nocheat/DupePrevention.java | 35 +++++++++++++ .../bukkit/nocheat/NoCheatConfiguration.java | 24 ++++----- .../bukkit/nocheat/NoCheatEntityListener.java | 20 ++++++++ .../bukkit/nocheat/NoCheatPlugin.java | 8 +-- .../bukkit/nocheat/NoCheatPluginData.java | 11 ++-- .../bukkit/nocheat/SpeedhackCheck.java | 50 +++++++++++++------ 7 files changed, 116 insertions(+), 34 deletions(-) create mode 100644 src/cc/co/evenprime/bukkit/nocheat/DupePrevention.java create mode 100644 src/cc/co/evenprime/bukkit/nocheat/NoCheatEntityListener.java diff --git a/plugin.yml b/plugin.yml index 06a1e89f..5b34216a 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,5 +3,5 @@ name: NoCheatPlugin author: Evenprime main: cc.co.evenprime.bukkit.nocheat.NoCheatPlugin -version: 0.5.9 +version: 0.5.9a diff --git a/src/cc/co/evenprime/bukkit/nocheat/DupePrevention.java b/src/cc/co/evenprime/bukkit/nocheat/DupePrevention.java new file mode 100644 index 00000000..32c59dd9 --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/DupePrevention.java @@ -0,0 +1,35 @@ +package cc.co.evenprime.bukkit.nocheat; + +import java.util.List; + +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +public class DupePrevention { + + /** + * Explicitly remove all items that are going to be dropped from the players inventory + * @param event + */ + public static void playerDeath(EntityDeathEvent event) { + + if(event.getEntity() instanceof Player) { + + Player p = (Player)event.getEntity(); + + PlayerInventory playerInventory = p.getInventory(); + List drops = event.getDrops(); + + for(ItemStack drop : drops) { + for(int i = 0; i < playerInventory.getSize(); i++) { + if(playerInventory.getItem(i).equals(drop)) { + p.getInventory().clear(i); + i = playerInventory.getSize(); + } + } + } + } + } +} \ No newline at end of file diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java index 8ff226a0..a86fbace 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java @@ -27,12 +27,12 @@ public class NoCheatConfiguration { public static boolean speedhackCheckActive = true; public static boolean movingCheckActive = true; public static boolean airbuildCheckActive = false; + public static boolean dupebydeathCheckActive = false; // Limits for the speedhack check - public static int speedhackInterval = 2000; - public static int speedhackLow = 60; - public static int speedhackMed = 90; - public static int speedhackHigh = 120; + public static int speedhackLow = 30; + public static int speedhackMed = 45; + public static int speedhackHigh = 60; public static int movingFreeMoves = 10; @@ -91,11 +91,11 @@ public class NoCheatConfiguration { speedhackCheckActive = c.getBoolean("active.speedhack", true); movingCheckActive = c.getBoolean("active.moving", true); airbuildCheckActive = c.getBoolean("active.airbuild", false); + dupebydeathCheckActive = c.getBoolean("active.dupebydeath", false); - speedhackInterval = c.getInt("speedhack.interval", 2000); - speedhackLow = c.getInt("speedhack.limits.low", 60); - speedhackMed = c.getInt("speedhack.limits.med", 90); - speedhackHigh = c.getInt("speedhack.limits.high", 120); + speedhackLow = c.getInt("speedhack.limits.low", 30); + speedhackMed = c.getInt("speedhack.limits.med", 45); + speedhackHigh = c.getInt("speedhack.limits.high", 60); movingLogOnly = c.getBoolean("moving.logonly", false); movingFreeMoves = c.getInt("moving.freemoves", 10); @@ -141,13 +141,13 @@ public class NoCheatConfiguration { w.write(" speedhack: true"); w.newLine(); w.write(" moving: true"); w.newLine(); w.write(" airbuild: false"); w.newLine(); + w.write(" dupebydeath: false"); w.newLine(); w.write("# Speedhack: interval in milliseconds, limits are events in that interval") ;w.newLine(); w.write("speedhack:"); w.newLine(); - w.write(" interval: 2000"); w.newLine(); w.write(" limits:"); w.newLine(); - w.write(" low: 60"); w.newLine(); - w.write(" med: 90"); w.newLine(); - w.write(" high: 120"); w.newLine(); + w.write(" low: 30"); w.newLine(); + w.write(" med: 45"); w.newLine(); + w.write(" high: 60"); w.newLine(); w.write("moving:"); w.newLine(); w.write(" logonly: false"); w.newLine(); w.write(" freemoves: 10"); w.newLine(); diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheatEntityListener.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheatEntityListener.java new file mode 100644 index 00000000..dfda5ab5 --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheatEntityListener.java @@ -0,0 +1,20 @@ +package cc.co.evenprime.bukkit.nocheat; + +import java.util.List; + +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityListener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +public class NoCheatEntityListener extends EntityListener { + + @Override + public void onEntityDeath(EntityDeathEvent event) { + + if(NoCheatConfiguration.dupebydeathCheckActive) { + DupePrevention.playerDeath(event); + } + } +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlugin.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlugin.java index d80ec01f..2a3cad0f 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlugin.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlugin.java @@ -6,12 +6,10 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.event.Event.Priority; import org.bukkit.event.Event; import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.PluginManager; @@ -33,6 +31,7 @@ public class NoCheatPlugin extends JavaPlugin { private final NoCheatPluginPlayerListener playerListener; private final NoCheatPluginVehicleListener vehicleListener; private final NoCheatPluginBlockListener blockListener; + private final NoCheatEntityListener entityListener; // My main logger private static Logger log; @@ -62,6 +61,7 @@ public class NoCheatPlugin extends JavaPlugin { playerListener = new NoCheatPluginPlayerListener(); vehicleListener = new NoCheatPluginVehicleListener(playerListener); blockListener = new NoCheatPluginBlockListener(); + entityListener = new NoCheatEntityListener(); log = NoCheatConfiguration.logger; @@ -107,6 +107,7 @@ public class NoCheatPlugin extends JavaPlugin { pm.registerEvent(Event.Type.VEHICLE_EXIT, vehicleListener, Priority.Monitor, this); // used for moving check pm.registerEvent(Event.Type.VEHICLE_DAMAGE, vehicleListener, Priority.Monitor, this); // used for moving check pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Low, this); // used for airbuild check + pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Highest, this); // used for dupebydeath check PluginDescriptionFile pdfFile = this.getDescription(); @@ -118,7 +119,8 @@ public class NoCheatPlugin extends JavaPlugin { String checks = (NoCheatConfiguration.movingCheckActive ? "moving ": "") + (NoCheatConfiguration.speedhackCheckActive ? "speedhack " : "") + - (NoCheatConfiguration.airbuildCheckActive ? "airbuild " : ""); + (NoCheatConfiguration.airbuildCheckActive ? "airbuild " : "") + + (NoCheatConfiguration.dupebydeathCheckActive ? "dupebydeath " : ""); Logger.getLogger("Minecraft").info( "[NoCheatPlugin] version [" + pdfFile.getVersion() + "] is enabled with the following checks: "+checks); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPluginData.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPluginData.java index dcde4f3f..d34adfc0 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPluginData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPluginData.java @@ -13,15 +13,18 @@ public class NoCheatPluginData { /** * Don't rely on any of these yet, they are likely going to change their name/functionality */ - int movingJumpPhase = 0; // current jumpingPhase - long lastSpeedHackCheck = System.currentTimeMillis(); // timestamp of last check for speedhacks - int eventsSinceLastSpeedHackCheck = 0; // used to identify speedhacks + + int movingIgnoreNextXEvents = 0; - + int movingJumpPhase = 0; // current jumpingPhase int movingMinorViolationsInARow = 0; int movingNormalViolationsInARow = 0; int movingHeavyViolationsInARow = 0; Location movingSetBackPoint = null; + long speedhackLastCheck = System.currentTimeMillis(); // timestamp of last check for speedhacks + int speedhackEventsSinceLastCheck = 0; // used to identify speedhacks + int speedhackViolationsInARow = 0; + NoCheatPluginData() { } } \ No newline at end of file diff --git a/src/cc/co/evenprime/bukkit/nocheat/SpeedhackCheck.java b/src/cc/co/evenprime/bukkit/nocheat/SpeedhackCheck.java index 61cde87b..c77c4aa5 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/SpeedhackCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/SpeedhackCheck.java @@ -10,6 +10,15 @@ import org.bukkit.event.player.PlayerMoveEvent; */ public class SpeedhackCheck { + // Violation levels + private static final int HEAVY = 3; + private static final int NORMAL = 2; + private static final int MINOR = 1; + private static final int NONE = 0; + + private static final long interval = 1000; + private static final int violationsLimit = 3; + public static void check(NoCheatPluginData data, PlayerMoveEvent event) { // Should we check at all? @@ -22,27 +31,40 @@ public class SpeedhackCheck { // Get the time of the server long time = System.currentTimeMillis(); + + int vl = NONE; // Is it time for a speedhack check now? - if(time > NoCheatConfiguration.speedhackInterval + data.lastSpeedHackCheck ) { + if(time > interval + data.speedhackLastCheck ) { // Yes // TODO: Needs some better handling for server lag - int limitLow = (int)((NoCheatConfiguration.speedhackLow * (time - data.lastSpeedHackCheck)) / NoCheatConfiguration.speedhackInterval); - int limitMed = (int)((NoCheatConfiguration.speedhackMed * (time - data.lastSpeedHackCheck)) / NoCheatConfiguration.speedhackInterval); - int limitHigh = (int)((NoCheatConfiguration.speedhackHigh * (time - data.lastSpeedHackCheck)) / NoCheatConfiguration.speedhackInterval); + int limitLow = (int)((NoCheatConfiguration.speedhackLow * (time - data.speedhackLastCheck)) / interval); + int limitMed = (int)((NoCheatConfiguration.speedhackMed * (time - data.speedhackLastCheck)) / interval); + int limitHigh = (int)((NoCheatConfiguration.speedhackHigh * (time - data.speedhackLastCheck)) / interval); + + + if(data.speedhackEventsSinceLastCheck > limitHigh) vl = HEAVY; + else if(data.speedhackEventsSinceLastCheck > limitMed) vl = NORMAL; + else if(data.speedhackEventsSinceLastCheck > limitLow) vl = MINOR; - if(data.eventsSinceLastSpeedHackCheck > limitHigh) - NoCheatPlugin.logHeavy("NoCheatPlugin: "+event.getPlayer().getName()+" sent "+ data.eventsSinceLastSpeedHackCheck + " move events, but only "+limitLow+ " were allowed. Speedhack?"); - else if(data.eventsSinceLastSpeedHackCheck > limitMed) - NoCheatPlugin.logNormal("NoCheatPlugin: "+event.getPlayer().getName()+" sent "+ data.eventsSinceLastSpeedHackCheck + " move events, but only "+limitLow+ " were allowed. Speedhack?"); - else if(data.eventsSinceLastSpeedHackCheck > limitLow) - NoCheatPlugin.logMinor("NoCheatPlugin: "+event.getPlayer().getName()+" sent "+ data.eventsSinceLastSpeedHackCheck + " move events, but only "+limitLow+ " were allowed. Speedhack?"); // Reset values for next check - data.eventsSinceLastSpeedHackCheck = 0; - data.lastSpeedHackCheck = time; + data.speedhackEventsSinceLastCheck = 0; + data.speedhackLastCheck = time; + + if(vl > NONE) data.speedhackViolationsInARow++; + else data.speedhackViolationsInARow = 0; + + if(data.speedhackViolationsInARow >= violationsLimit) { + String message = "NoCheatPlugin: "+event.getPlayer().getName()+" sent "+ data.speedhackEventsSinceLastCheck + " move events, but only "+limitLow+ " were allowed. Speedhack?"; + switch(vl) { + case HEAVY: NoCheatPlugin.logHeavy(message); break; + case NORMAL: NoCheatPlugin.logNormal(message); break; + case MINOR: NoCheatPlugin.logMinor(message); break; + } + } + } - - data.eventsSinceLastSpeedHackCheck++; + data.speedhackEventsSinceLastCheck++; } }