From dcb7795f4f28357dcf5506d8d527b956a14b67d9 Mon Sep 17 00:00:00 2001 From: Super Spy Date: Tue, 5 Jun 2012 21:49:17 -0500 Subject: [PATCH] Screw it, i'm calling it the interactables check. Only blocks that can be "switched" in anyway are blocked. --- .../h31ix/anticheat/event/PlayerListener.java | 19 ++++---- .../net/h31ix/anticheat/manage/Backend.java | 47 ++++++++++--------- .../net/h31ix/anticheat/manage/CheckType.java | 2 +- .../net/h31ix/anticheat/util/Utilities.java | 20 +++++++- 4 files changed, 52 insertions(+), 36 deletions(-) diff --git a/src/main/java/net/h31ix/anticheat/event/PlayerListener.java b/src/main/java/net/h31ix/anticheat/event/PlayerListener.java index ebb83b1..fa28537 100644 --- a/src/main/java/net/h31ix/anticheat/event/PlayerListener.java +++ b/src/main/java/net/h31ix/anticheat/event/PlayerListener.java @@ -152,20 +152,17 @@ public class PlayerListener extends EventListener backend.checkLongReachBlock(player,distance.getXDifference(), distance.getYDifference(), distance.getZDifference()); } - /* Visuals Check */ - if(event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) + /* Interactions Check */ + Block block = event.getClickedBlock(); + if(checkManager.willCheck(player, CheckType.INTERACTION) && Utilities.isInteractable(block.getType())) { - Block block = event.getClickedBlock(); - if(checkManager.willCheck(player, CheckType.VISUALS)) + // save load and actually call the backend check here. + if(backend.checkInteraction(player, block)) { - // save load and actually call the backend check here. - if(backend.checkVisuals(player, block)) - { - event.setCancelled(true); - log("failed visuals check",player,CheckType.VISUALS); - } + event.setCancelled(true); + log("failed interaction check",player,CheckType.INTERACTION); } - } + } } diff --git a/src/main/java/net/h31ix/anticheat/manage/Backend.java b/src/main/java/net/h31ix/anticheat/manage/Backend.java index a0525b7..08bd3d3 100644 --- a/src/main/java/net/h31ix/anticheat/manage/Backend.java +++ b/src/main/java/net/h31ix/anticheat/manage/Backend.java @@ -261,7 +261,7 @@ public class Backend } } - public boolean checkVisuals(Player player, Block block) + public boolean checkInteraction(Player player, Block block) { // The most complicated check in the world...approaching nirvana. int strikes = 0; @@ -292,6 +292,7 @@ public class Backend if(direction != null) { + for(int g = 0; g < 2; g++) { py = py+g; @@ -314,7 +315,7 @@ public class Backend if(coords.getX() < block.getLocation().getX()) { ignoreothers = true; - player.sendBlockChange(coords, 66, (byte) 0); + //player.sendBlockChange(coords, 66, (byte) 0); } if(block.getLocation().distance(coords) > 5D) @@ -324,8 +325,8 @@ public class Backend if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers) { - player.sendMessage("Block detected at -X: " + a + " Block: " + coords.getBlock().getType().toString()); - player.sendBlockChange(coords, 46, (byte) 0); + //player.sendMessage("Block detected at -X: " + a + " Block: " + coords.getBlock().getType().toString()); + //player.sendBlockChange(coords, 46, (byte) 0); strikes++; } } @@ -350,13 +351,13 @@ public class Backend if(coords.getZ() < block.getLocation().getZ()) { ignoreothers = true; - player.sendBlockChange(coords, 66, (byte) 0); + //player.sendBlockChange(coords, 66, (byte) 0); } if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers) { - player.sendMessage("Block detected at -Z: " + a + " Block: " + coords.getBlock().getType().toString()); - player.sendBlockChange(coords, 46, (byte) 0); + //player.sendMessage("Block detected at -Z: " + a + " Block: " + coords.getBlock().getType().toString()); + //player.sendBlockChange(coords, 46, (byte) 0); strikes++; } } @@ -385,13 +386,13 @@ public class Backend if(coords.getX() < block.getLocation().getX()) { ignoreothers = true; - player.sendBlockChange(coords, 66, (byte) 0); + //player.sendBlockChange(coords, 66, (byte) 0); } if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers) { - player.sendMessage("Block detected at +X: " + a + " Block: " + coords.getBlock().getType().toString()); - player.sendBlockChange(coords, 46, (byte) 0); + //player.sendMessage("Block detected at +X: " + a + " Block: " + coords.getBlock().getType().toString()); + //player.sendBlockChange(coords, 46, (byte) 0); strikes++; } } @@ -416,13 +417,13 @@ public class Backend if(coords.getZ() < block.getLocation().getZ()) { ignoreothers = true; - player.sendBlockChange(coords, 66, (byte) 0); + //player.sendBlockChange(coords, 66, (byte) 0); } if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers) { - player.sendMessage("Block detected at -Z: " + a + " Block: " + coords.getBlock().getType().toString()); - player.sendBlockChange(coords, 46, (byte) 0); + //player.sendMessage("Block detected at -Z: " + a + " Block: " + coords.getBlock().getType().toString()); + //player.sendBlockChange(coords, 46, (byte) 0); strikes++; } } @@ -438,8 +439,8 @@ public class Backend Location coords = new Location(player.getWorld(), px+a,py,pz); if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId()) { - player.sendMessage("Block detected at +X: " + a + " Block: " + coords.getBlock().getType().toString()); - player.sendBlockChange(coords, 46, (byte) 0); + //player.sendMessage("Block detected at +X: " + a + " Block: " + coords.getBlock().getType().toString()); + //player.sendBlockChange(coords, 46, (byte) 0); strikes++; } } @@ -452,8 +453,8 @@ public class Backend Location coords = new Location(player.getWorld(), px,py,pz+a); if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId()) { - player.sendMessage("Block detected at +Z: " + a + " Block: " + coords.getBlock().getType().toString()); - player.sendBlockChange(coords, 46, (byte) 0); + //player.sendMessage("Block detected at +Z: " + a + " Block: " + coords.getBlock().getType().toString()); + //player.sendBlockChange(coords, 46, (byte) 0); strikes++; } } @@ -479,8 +480,8 @@ public class Backend if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers) { - player.sendMessage("Block detected at -X: " + a + " Block: " + coords.getBlock().getType().toString()); - player.sendBlockChange(coords, 46, (byte) 0); + //player.sendMessage("Block detected at -X: " + a + " Block: " + coords.getBlock().getType().toString()); + //player.sendBlockChange(coords, 46, (byte) 0); strikes++; } } @@ -503,8 +504,8 @@ public class Backend if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers) { - player.sendMessage("Block detected at +Z: " + a + " Block: " + coords.getBlock().getType().toString()); - player.sendBlockChange(coords, 46, (byte) 0); + //player.sendMessage("Block detected at +Z: " + a + " Block: " + coords.getBlock().getType().toString()); + //player.sendBlockChange(coords, 46, (byte) 0); strikes++; } } @@ -513,8 +514,8 @@ public class Backend } } - player.sendMessage("Strikes: " + strikes + " Dir: " + direction); - player.sendMessage("X: " + x + " Y: " + y + " Z:" + z); + //player.sendMessage("Strikes: " + strikes + " Dir: " + direction); + //player.sendMessage("X: " + x + " Y: " + y + " Z:" + z); return strikes > 0; } diff --git a/src/main/java/net/h31ix/anticheat/manage/CheckType.java b/src/main/java/net/h31ix/anticheat/manage/CheckType.java index 2cca275..3c5a259 100644 --- a/src/main/java/net/h31ix/anticheat/manage/CheckType.java +++ b/src/main/java/net/h31ix/anticheat/manage/CheckType.java @@ -38,7 +38,7 @@ public enum CheckType WATER_WALK("anticheat.waterwalk"), NO_SWING("anticheat.noswing"), FAST_BREAK("anticheat.fastbreak"), - VISUALS("anticheat.visuals"), + INTERACTION("anticheat.interaction"), FAST_PLACE("anticheat.fastplace"), SPAM("anticheat.spam"), SPRINT("anticheat.sprint"), diff --git a/src/main/java/net/h31ix/anticheat/util/Utilities.java b/src/main/java/net/h31ix/anticheat/util/Utilities.java index a45ed49..eeff140 100644 --- a/src/main/java/net/h31ix/anticheat/util/Utilities.java +++ b/src/main/java/net/h31ix/anticheat/util/Utilities.java @@ -34,6 +34,7 @@ public final class Utilities { private static final List INSTANT_BREAK = new ArrayList(); private static final List FOOD = new ArrayList(); + private static final List INTERACTABLE = new ArrayList(); private Utilities() { @@ -82,7 +83,10 @@ public final class Utilities public static boolean isFood(Material m) { return FOOD.contains(m); - } + } + public static boolean isInteractable(Material m) { + return INTERACTABLE.contains(m); + } public static boolean sprintFly(Player player) { return player.isSprinting() || player.isFlying(); @@ -197,6 +201,20 @@ public final class Utilities INSTANT_BREAK.add(Material.CROPS); INSTANT_BREAK.add(Material.SNOW); INSTANT_BREAK.add(Material.TNT); + INTERACTABLE.add(Material.STONE_BUTTON); + INTERACTABLE.add(Material.LEVER); + INTERACTABLE.add(Material.CHEST); + INTERACTABLE.add(Material.DISPENSER); + INTERACTABLE.add(Material.CAULDRON); + INTERACTABLE.add(Material.ENCHANTMENT_TABLE); + INTERACTABLE.add(Material.WOOD_DOOR); + INTERACTABLE.add(Material.IRON_DOOR); + INTERACTABLE.add(Material.WORKBENCH); + INTERACTABLE.add(Material.CAKE_BLOCK); + INTERACTABLE.add(Material.STONE_PLATE); + INTERACTABLE.add(Material.FENCE_GATE); + INTERACTABLE.add(Material.TRAP_DOOR); + //INTERACTABLE.add(Material. - placeholder. FOOD.add(Material.COOKED_BEEF); FOOD.add(Material.COOKED_CHICKEN); FOOD.add(Material.COOKED_FISH);