Visuals Check is now bulletproof. Will work on any block interaction. Also improved location checks for visuals.

This commit is contained in:
Super Spy committed 2012-06-12 19:26:28 -05:00
1 parent bb7b43afdb
commit 659d73752c
2 files changed
+15 -14

No files matched your search

@@ -157,6 +157,7 @@ public class PlayerListener extends EventListener
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block playerClick = player.getTargetBlock(null, 5);
PlayerInventory inv = player.getInventory(); PlayerInventory inv = player.getInventory();
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
{ {
@@ -181,9 +182,9 @@ public class PlayerListener extends EventListener
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
if(block != null) if(block != null)
{ {
if(checkManager.willCheck(player, CheckType.VISUAL) && Utilities.isInteractable(block.getType())) if(checkManager.willCheck(player, CheckType.VISUAL))
{ {
if(backend.checkInteraction(player, block)) if(backend.checkInteraction(player, block, playerClick))
{ {
event.setCancelled(true); event.setCancelled(true);
log("tried to interact with an object that they couldn't see", player, CheckType.VISUAL); //boring description though. log("tried to interact with an object that they couldn't see", player, CheckType.VISUAL); //boring description though.
@@ -59,6 +59,8 @@ public class Backend
private static final int FASTPLACE_MAXVIOLATIONS_CREATIVE = 3; private static final int FASTPLACE_MAXVIOLATIONS_CREATIVE = 3;
private static final int FASTPLACE_MAXVIOLATIONTIME = 10000; private static final int FASTPLACE_MAXVIOLATIONTIME = 10000;
private static final double VISUALS_MAXOFFSET = 2;
private static final int BLOCK_PUNCH_MIN = 5; private static final int BLOCK_PUNCH_MIN = 5;
private static final int PROJECTILE_MAX = 8; private static final int PROJECTILE_MAX = 8;
@@ -272,22 +274,20 @@ public class Backend
} }
} }
public boolean checkInteraction(Player player, Block block) public boolean checkInteraction(Player player, Block targetBlock, Block playerClick)
{ {
int strikes = 0; int strikes = 0;
// First Line of Defense double x = targetBlock.getX() - playerClick.getX() * ((targetBlock.getX() - playerClick.getX() * 1) < 0 ? -1 : 1);
Block imple = player.getTargetBlock(null, 5); double y = targetBlock.getY() - playerClick.getY() * ((targetBlock.getY() - playerClick.getY() * 1) < 0 ? -1 : 1);
if(imple.getTypeId() != block.getTypeId()) double z = targetBlock.getZ() - playerClick.getZ() * ((targetBlock.getZ() - playerClick.getZ() * 1) < 0 ? -1 : 1);
{
strikes++; player.sendMessage("X: " + x + " Y: " + y + " Z: " + z);
}
if (x >= VISUALS_MAXOFFSET) strikes++;
if (y >= VISUALS_MAXOFFSET) strikes++;
if (z >= VISUALS_MAXOFFSET) strikes++;
// Second line of defense.
if(!imple.getLocation().equals(block.getLocation()))
{
strikes++;
}
return strikes > 0; return strikes > 0;
} }