Screw it, i'm calling it the interactables check. Only blocks that can be "switched" in anyway are blocked.

This commit is contained in:
Super Spy committed 2012-06-05 21:49:17 -05:00
1 parent 3a8c591c5b
commit dcb7795f4f
4 files changed
+52 -36

No files matched your search

@@ -152,20 +152,17 @@ public class PlayerListener extends EventListener
backend.checkLongReachBlock(player,distance.getXDifference(), distance.getYDifference(), distance.getZDifference()); backend.checkLongReachBlock(player,distance.getXDifference(), distance.getYDifference(), distance.getZDifference());
} }
/* Visuals Check */ /* Interactions Check */
if(event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) Block block = event.getClickedBlock();
if(checkManager.willCheck(player, CheckType.INTERACTION) && Utilities.isInteractable(block.getType()))
{ {
Block block = event.getClickedBlock(); // save load and actually call the backend check here.
if(checkManager.willCheck(player, CheckType.VISUALS)) if(backend.checkInteraction(player, block))
{ {
// save load and actually call the backend check here. event.setCancelled(true);
if(backend.checkVisuals(player, block)) log("failed interaction check",player,CheckType.INTERACTION);
{
event.setCancelled(true);
log("failed visuals check",player,CheckType.VISUALS);
}
} }
} }
} }
@@ -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. // The most complicated check in the world...approaching nirvana.
int strikes = 0; int strikes = 0;
@@ -292,6 +292,7 @@ public class Backend
if(direction != null) if(direction != null)
{ {
for(int g = 0; g < 2; g++) for(int g = 0; g < 2; g++)
{ {
py = py+g; py = py+g;
@@ -314,7 +315,7 @@ public class Backend
if(coords.getX() < block.getLocation().getX()) if(coords.getX() < block.getLocation().getX())
{ {
ignoreothers = true; ignoreothers = true;
player.sendBlockChange(coords, 66, (byte) 0); //player.sendBlockChange(coords, 66, (byte) 0);
} }
if(block.getLocation().distance(coords) > 5D) if(block.getLocation().distance(coords) > 5D)
@@ -324,8 +325,8 @@ public class Backend
if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers) if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers)
{ {
player.sendMessage("Block detected at -X: " + a + " Block: " + coords.getBlock().getType().toString()); //player.sendMessage("Block detected at -X: " + a + " Block: " + coords.getBlock().getType().toString());
player.sendBlockChange(coords, 46, (byte) 0); //player.sendBlockChange(coords, 46, (byte) 0);
strikes++; strikes++;
} }
} }
@@ -350,13 +351,13 @@ public class Backend
if(coords.getZ() < block.getLocation().getZ()) if(coords.getZ() < block.getLocation().getZ())
{ {
ignoreothers = true; 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) if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers)
{ {
player.sendMessage("Block detected at -Z: " + a + " Block: " + coords.getBlock().getType().toString()); //player.sendMessage("Block detected at -Z: " + a + " Block: " + coords.getBlock().getType().toString());
player.sendBlockChange(coords, 46, (byte) 0); //player.sendBlockChange(coords, 46, (byte) 0);
strikes++; strikes++;
} }
} }
@@ -385,13 +386,13 @@ public class Backend
if(coords.getX() < block.getLocation().getX()) if(coords.getX() < block.getLocation().getX())
{ {
ignoreothers = true; 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) if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers)
{ {
player.sendMessage("Block detected at +X: " + a + " Block: " + coords.getBlock().getType().toString()); //player.sendMessage("Block detected at +X: " + a + " Block: " + coords.getBlock().getType().toString());
player.sendBlockChange(coords, 46, (byte) 0); //player.sendBlockChange(coords, 46, (byte) 0);
strikes++; strikes++;
} }
} }
@@ -416,13 +417,13 @@ public class Backend
if(coords.getZ() < block.getLocation().getZ()) if(coords.getZ() < block.getLocation().getZ())
{ {
ignoreothers = true; 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) if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers)
{ {
player.sendMessage("Block detected at -Z: " + a + " Block: " + coords.getBlock().getType().toString()); //player.sendMessage("Block detected at -Z: " + a + " Block: " + coords.getBlock().getType().toString());
player.sendBlockChange(coords, 46, (byte) 0); //player.sendBlockChange(coords, 46, (byte) 0);
strikes++; strikes++;
} }
} }
@@ -438,8 +439,8 @@ public class Backend
Location coords = new Location(player.getWorld(), px+a,py,pz); Location coords = new Location(player.getWorld(), px+a,py,pz);
if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId()) if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId())
{ {
player.sendMessage("Block detected at +X: " + a + " Block: " + coords.getBlock().getType().toString()); //player.sendMessage("Block detected at +X: " + a + " Block: " + coords.getBlock().getType().toString());
player.sendBlockChange(coords, 46, (byte) 0); //player.sendBlockChange(coords, 46, (byte) 0);
strikes++; strikes++;
} }
} }
@@ -452,8 +453,8 @@ public class Backend
Location coords = new Location(player.getWorld(), px,py,pz+a); Location coords = new Location(player.getWorld(), px,py,pz+a);
if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId()) if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId())
{ {
player.sendMessage("Block detected at +Z: " + a + " Block: " + coords.getBlock().getType().toString()); //player.sendMessage("Block detected at +Z: " + a + " Block: " + coords.getBlock().getType().toString());
player.sendBlockChange(coords, 46, (byte) 0); //player.sendBlockChange(coords, 46, (byte) 0);
strikes++; strikes++;
} }
} }
@@ -479,8 +480,8 @@ public class Backend
if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers) if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers)
{ {
player.sendMessage("Block detected at -X: " + a + " Block: " + coords.getBlock().getType().toString()); //player.sendMessage("Block detected at -X: " + a + " Block: " + coords.getBlock().getType().toString());
player.sendBlockChange(coords, 46, (byte) 0); //player.sendBlockChange(coords, 46, (byte) 0);
strikes++; strikes++;
} }
} }
@@ -503,8 +504,8 @@ public class Backend
if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers) if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers)
{ {
player.sendMessage("Block detected at +Z: " + a + " Block: " + coords.getBlock().getType().toString()); //player.sendMessage("Block detected at +Z: " + a + " Block: " + coords.getBlock().getType().toString());
player.sendBlockChange(coords, 46, (byte) 0); //player.sendBlockChange(coords, 46, (byte) 0);
strikes++; strikes++;
} }
} }
@@ -513,8 +514,8 @@ public class Backend
} }
} }
player.sendMessage("Strikes: " + strikes + " Dir: " + direction); //player.sendMessage("Strikes: " + strikes + " Dir: " + direction);
player.sendMessage("X: " + x + " Y: " + y + " Z:" + z); //player.sendMessage("X: " + x + " Y: " + y + " Z:" + z);
return strikes > 0; return strikes > 0;
} }
@@ -38,7 +38,7 @@ public enum CheckType
WATER_WALK("anticheat.waterwalk"), WATER_WALK("anticheat.waterwalk"),
NO_SWING("anticheat.noswing"), NO_SWING("anticheat.noswing"),
FAST_BREAK("anticheat.fastbreak"), FAST_BREAK("anticheat.fastbreak"),
VISUALS("anticheat.visuals"), INTERACTION("anticheat.interaction"),
FAST_PLACE("anticheat.fastplace"), FAST_PLACE("anticheat.fastplace"),
SPAM("anticheat.spam"), SPAM("anticheat.spam"),
SPRINT("anticheat.sprint"), SPRINT("anticheat.sprint"),
@@ -34,6 +34,7 @@ public final class Utilities
{ {
private static final List<Material> INSTANT_BREAK = new ArrayList<Material>(); private static final List<Material> INSTANT_BREAK = new ArrayList<Material>();
private static final List<Material> FOOD = new ArrayList<Material>(); private static final List<Material> FOOD = new ArrayList<Material>();
private static final List<Material> INTERACTABLE = new ArrayList<Material>();
private Utilities() private Utilities()
{ {
@@ -82,7 +83,10 @@ public final class Utilities
public static boolean isFood(Material m) public static boolean isFood(Material m)
{ {
return FOOD.contains(m); return FOOD.contains(m);
} }
public static boolean isInteractable(Material m) {
return INTERACTABLE.contains(m);
}
public static boolean sprintFly(Player player) public static boolean sprintFly(Player player)
{ {
return player.isSprinting() || player.isFlying(); return player.isSprinting() || player.isFlying();
@@ -197,6 +201,20 @@ public final class Utilities
INSTANT_BREAK.add(Material.CROPS); INSTANT_BREAK.add(Material.CROPS);
INSTANT_BREAK.add(Material.SNOW); INSTANT_BREAK.add(Material.SNOW);
INSTANT_BREAK.add(Material.TNT); 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_BEEF);
FOOD.add(Material.COOKED_CHICKEN); FOOD.add(Material.COOKED_CHICKEN);
FOOD.add(Material.COOKED_FISH); FOOD.add(Material.COOKED_FISH);