From 8c11e720952840301f0d31e5bc5bf4bc02b09dc5 Mon Sep 17 00:00:00 2001 From: Evenprime Date: Thu, 3 Mar 2011 20:14:09 +0100 Subject: [PATCH] Fixed sleeping + fixed hidden water ladders + version bump Players going to sleep can now stand further away from the bed without triggering a violation. Quick fix for hidden water ladders. --- plugin.yml | 2 +- .../nocheat/checks/DupebydeathCheck.java | 2 +- .../bukkit/nocheat/checks/MovingCheck.java | 25 +++++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/plugin.yml b/plugin.yml index cb48c9d1..e119a750 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,5 +3,5 @@ name: NoCheatPlugin author: Evenprime main: cc.co.evenprime.bukkit.nocheat.NoCheatPlugin -version: 0.6.1 +version: 0.6.2 diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/DupebydeathCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/DupebydeathCheck.java index a16ffe2e..296c744c 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/DupebydeathCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/DupebydeathCheck.java @@ -37,7 +37,7 @@ public class DupebydeathCheck { for(int i = 0; i < playerInventory.getSize(); i++) { if(playerInventory.getItem(i).equals(drop)) { playerInventory.clear(i); - i = playerInventory.getSize(); + break; } } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/MovingCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/MovingCheck.java index a1f0b8f5..1f37699c 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/MovingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/MovingCheck.java @@ -142,15 +142,20 @@ public class MovingCheck { Location from = event.getFrom(); Location to = event.getTo(); - Level vl = null; // The violation level (none, minor, normal, heavy) - // First check the distance the player has moved horizontally // TODO: Make this check much more precise double xDistance = Math.abs(from.getX() - to.getX()); double zDistance = Math.abs(from.getZ() - to.getZ()); double combined = xDistance * xDistance + zDistance * zDistance; - // How far are we off? + // If the target is a bed and distance not too big, allow it + if(to.getWorld().getBlockTypeIdAt(to) == Material.BED_BLOCK.getId() && xDistance < 5.0D && zDistance < 5.0D) { + return; // players are allowed to "teleport" into a bed over short distances + } + + Level vl = null; // The violation level (none, minor, normal, heavy) + + // How far are we off? if(combined > movingDistanceHigh) { vl = max(vl, Level.SEVERE); } @@ -160,18 +165,12 @@ public class MovingCheck { else if(combined > movingDistanceLow) { vl = max(vl, Level.INFO); } - - // If the target is a bed, allow it - if(to.getWorld().getBlockTypeIdAt(to) == Material.BED_BLOCK.getId() && (vl == null || vl.intValue() < Level.SEVERE.intValue())) { - return; // players are allowed to "teleport" into a bed over short distances - } - // pre-calculate boundary values that are needed multiple times in the following checks // the array each contains [lowerX, higherX, Y, lowerZ, higherZ] int fromValues[] = {floor_double(from.getX() - 0.3D), (int)Math.floor(from.getX() + 0.3D), from.getBlockY(), floor_double(from.getZ() - 0.3D),(int)Math.floor(from.getZ() + 0.3D) }; int toValues[] = {floor_double(to.getX() - 0.3D), (int)Math.floor(to.getX() + 0.3D), to.getBlockY(), floor_double(to.getZ() - 0.3D), (int)Math.floor(to.getZ() + 0.3D) }; - + // compare locations to the world to guess if the player is standing on the ground, a half-block or next to a ladder boolean onGroundFrom = playerIsOnGround(from.getWorld(), fromValues, from); boolean onGroundTo = playerIsOnGround(from.getWorld(), toValues, to); @@ -433,10 +432,16 @@ public class MovingCheck { types[w.getBlockTypeIdAt(values[0], values[2]+1, values[4])] != BlockType.NONSOLID || types[w.getBlockTypeIdAt(values[1], values[2]+1, values[4])] != BlockType.NONSOLID) return true; + // Allow using a bug called "water elevator" + else if(types[w.getBlockTypeIdAt(values[0]+1, values[2]-1, values[3]+1)] == BlockType.LIQUID || + types[w.getBlockTypeIdAt(values[0]+1, values[2], values[3]+1)] == BlockType.LIQUID || + types[w.getBlockTypeIdAt(values[0]+1, values[2]+1, values[3]+1)] == BlockType.LIQUID) + return true; else return false; } + public static int floor_double(double d) { int i = (int)d;