I made it pretty

This commit is contained in:
H31IX committed 2012-06-05 23:25:22 -04:00
1 parent 1f53f4d1cd
commit 7ad0f63c34
2 files changed
+205 -225

No files matched your search

@@ -156,15 +156,14 @@ public class PlayerListener extends EventListener
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
if(checkManager.willCheck(player, CheckType.INTERACTION) && Utilities.isInteractable(block.getType())) if(checkManager.willCheck(player, CheckType.INTERACTION) && Utilities.isInteractable(block.getType()))
{ {
// save load and actually call the backend check here. System.out.println("checking interaction");
if(backend.checkInteraction(player, block)) // save load and actually call the backend check here.
{ if(backend.checkInteraction(player, block))
event.setCancelled(true); {
log("failed interaction check",player,CheckType.INTERACTION); event.setCancelled(true);
} log("failed interaction check",player,CheckType.INTERACTION);
}
} }
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
@@ -263,10 +263,8 @@ public class Backend
public boolean checkInteraction(Player player, Block block) public boolean checkInteraction(Player player, Block block)
{ {
// The most complicated check in the world...approaching nirvana.
int strikes = 0; int strikes = 0;
// now let's swing the bat.
Distance distance = new Distance(player.getLocation(), block.getLocation()); Distance distance = new Distance(player.getLocation(), block.getLocation());
//player coords //player coords
@@ -292,231 +290,214 @@ public class Backend
if(direction != null) if(direction != null)
{ {
for(int g = 0; g < 2; g++)
{
py = py+g;
if(direction.equals("N") || direction.equals("NE"))
{
if(x > 0)
{
boolean ignoreothers = false;
for(int a = 0; a < x + 1; a++)
{
Location coords = new Location(player.getWorld(), px-a,py,pz);
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 3D)
{
ignoreothers = true;
}
// Don't detect farther than we should be allowed to.
if(coords.getX() < block.getLocation().getX())
{
ignoreothers = true;
//player.sendBlockChange(coords, 66, (byte) 0);
}
if(block.getLocation().distance(coords) > 5D)
{
continue;
}
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);
strikes++;
}
}
}
if(z > 0)
{
boolean ignoreothers = false;
for(int a = 0; a < z + 1; a++)
{
Location coords = new Location(player.getWorld(), px,py,pz-a);
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 3D)
{
ignoreothers = true;
}
if(block.getLocation().distance(coords) > 5D)
{
continue;
}
// Don't detect farther than we should be allowed to.
if(coords.getZ() < block.getLocation().getZ())
{
ignoreothers = true;
//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);
strikes++;
}
}
}
}
if(direction.equals("E") || direction.equals("SE"))
{
if(x > 0)
{
boolean ignoreothers = false;
for(int a = 0; a < x + 1; a++)
{
Location coords = new Location(player.getWorld(), px+a,py,pz);
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 3D)
{
ignoreothers = true;
}
if(block.getLocation().distance(coords) > 5D)
{
continue;
}
// Don't detect farther than we should be allowed to.
if(coords.getX() < block.getLocation().getX())
{
ignoreothers = true;
//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);
strikes++;
}
}
}
if(z > 0)
{
boolean ignoreothers = false;
for(int a = 0; a < z + 1; a++)
{
Location coords = new Location(player.getWorld(), px,py,pz-a);
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 4D)
{
ignoreothers = true;
}
for(int g = 0; g < 2; g++) if(block.getLocation().distance(coords) > 5D)
{ {
py = py+g; continue;
}
if(direction.equals("N") || direction.equals("NE")) // Don't detect farther than we should be allowed to.
{ if(coords.getZ() < block.getLocation().getZ())
if(x > 0) {
{ ignoreothers = true;
boolean ignoreothers = false; //player.sendBlockChange(coords, 66, (byte) 0);
for(int a = 0; a < x + 1; a++) }
{
Location coords = new Location(player.getWorld(), px-a,py,pz);
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 3D)
{
ignoreothers = true;
}
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);
strikes++;
}
}
}
}
if(direction.equals("S") || direction.equals("SW") || direction.equals("W"))
{
if(x > 0)
{
for(int a = 0; a < x + 1; a++)
{
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);
strikes++;
}
}
}
if(z > 0)
{
for(int a = 0; a < z + 1; a++)
{
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);
strikes++;
}
}
}
}
if(direction.equals("NW"))
{
if(x > 0)
{
boolean ignoreothers = false;
for(int a = 0; a < x + 1; a++)
{
Location coords = new Location(player.getWorld(), px-a,py,pz);
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 3D)
{
ignoreothers = true;
}
// Don't detect farther than we should be allowed to. if(block.getLocation().distance(coords) > 5D)
if(coords.getX() < block.getLocation().getX()) {
{ continue;
ignoreothers = true; }
//player.sendBlockChange(coords, 66, (byte) 0);
}
if(block.getLocation().distance(coords) > 5D) if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers)
{ {
continue; //player.sendMessage("Block detected at -X: " + a + " Block: " + coords.getBlock().getType().toString());
} //player.sendBlockChange(coords, 46, (byte) 0);
strikes++;
}
}
}
if(z > 0)
{
boolean ignoreothers = false;
for(int a = 0; a < z + 1; a++)
{
Location coords = new Location(player.getWorld(), px,py,pz+a);
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 3D)
{
ignoreothers = true;
}
if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers) if(block.getLocation().distance(coords) > 5D)
{ {
//player.sendMessage("Block detected at -X: " + a + " Block: " + coords.getBlock().getType().toString()); continue;
//player.sendBlockChange(coords, 46, (byte) 0); }
strikes++;
}
}
}
if(z > 0) if(coords.getBlock().getTypeId() != 0 && coords.getBlock().getTypeId() != block.getTypeId() && !ignoreothers)
{ {
boolean ignoreothers = false; //player.sendMessage("Block detected at +Z: " + a + " Block: " + coords.getBlock().getType().toString());
for(int a = 0; a < z + 1; a++) //player.sendBlockChange(coords, 46, (byte) 0);
{ strikes++;
Location coords = new Location(player.getWorld(), px,py,pz-a); }
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 3D) }
{ }
ignoreothers = true; }
} }
if(block.getLocation().distance(coords) > 5D) {
continue;
}
// Don't detect farther than we should be allowed to.
if(coords.getZ() < block.getLocation().getZ())
{
ignoreothers = true;
//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);
strikes++;
}
}
}
}
if(direction.equals("E") || direction.equals("SE"))
{
if(x > 0)
{
boolean ignoreothers = false;
for(int a = 0; a < x + 1; a++)
{
Location coords = new Location(player.getWorld(), px+a,py,pz);
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 3D)
{
ignoreothers = true;
}
if(block.getLocation().distance(coords) > 5D) {
continue;
}
// Don't detect farther than we should be allowed to.
if(coords.getX() < block.getLocation().getX())
{
ignoreothers = true;
//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);
strikes++;
}
}
}
if(z > 0)
{
boolean ignoreothers = false;
for(int a = 0; a < z + 1; a++)
{
Location coords = new Location(player.getWorld(), px,py,pz-a);
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 4D)
{
ignoreothers = true;
}
if(block.getLocation().distance(coords) > 5D) {
continue;
}
// Don't detect farther than we should be allowed to.
if(coords.getZ() < block.getLocation().getZ())
{
ignoreothers = true;
//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);
strikes++;
}
}
}
}
if(direction.equals("S") || direction.equals("SW") || direction.equals("W"))
{
if(x > 0)
{
for(int a = 0; a < x + 1; a++)
{
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);
strikes++;
}
}
}
if(z > 0)
{
for(int a = 0; a < z + 1; a++)
{
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);
strikes++;
}
}
}
}
if(direction.equals("NW"))
{
if(x > 0)
{
boolean ignoreothers = false;
for(int a = 0; a < x + 1; a++)
{
Location coords = new Location(player.getWorld(), px-a,py,pz);
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 3D)
{
ignoreothers = true;
}
if(block.getLocation().distance(coords) > 5D) {
continue;
}
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);
strikes++;
}
}
}
if(z > 0)
{
boolean ignoreothers = false;
for(int a = 0; a < z + 1; a++)
{
Location coords = new Location(player.getWorld(), px,py,pz+a);
if(coords.getBlock().getTypeId() == block.getTypeId() && coords.distance(block.getLocation()) < 3D)
{
ignoreothers = true;
}
if(block.getLocation().distance(coords) > 5D) {
continue;
}
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);
strikes++;
}
}
}
}
}
} }
//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;
} }