Piston handling tweaks.

1) Performance for pistons outside of land claims when they're allowed
to move blocks.  2) When not allowed to move blocks, now allowing
pistons outside land claims to retract when they can't pulling a block.
3) When allowed to move blocks, auto-break sticky pistons for sake of
perf just like I've been doing for non-sticky pistons for a long time.
This commit is contained in:
ryanhamshire 2016-06-03 20:56:28 -07:00
parent 943dde60a3
commit cfe61ef945

View File

@ -489,9 +489,9 @@ public class BlockEventHandler implements Listener
if(!claim.getOwnerName().equals(pistonClaimOwnerName)) if(!claim.getOwnerName().equals(pistonClaimOwnerName))
{ {
event.setCancelled(true); event.setCancelled(true);
event.getBlock().getWorld().createExplosion(event.getBlock().getLocation(), 0); pistonBlock.getWorld().createExplosion(pistonBlock.getLocation(), 0);
event.getBlock().getWorld().dropItem(event.getBlock().getLocation(), new ItemStack(event.getBlock().getType())); pistonBlock.getWorld().dropItem(pistonBlock.getLocation(), new ItemStack(pistonBlock.getType()));
event.getBlock().setType(Material.AIR); pistonBlock.setType(Material.AIR);
return; return;
} }
} }
@ -520,9 +520,9 @@ public class BlockEventHandler implements Listener
if(!newOwnerName.equals(originalOwnerName) && !newOwnerName.isEmpty()) if(!newOwnerName.equals(originalOwnerName) && !newOwnerName.isEmpty())
{ {
event.setCancelled(true); event.setCancelled(true);
event.getBlock().getWorld().createExplosion(event.getBlock().getLocation(), 0); pistonBlock.getWorld().createExplosion(pistonBlock.getLocation(), 0);
event.getBlock().getWorld().dropItem(event.getBlock().getLocation(), new ItemStack(event.getBlock().getType())); pistonBlock.getWorld().dropItem(pistonBlock.getLocation(), new ItemStack(pistonBlock.getType()));
event.getBlock().setType(Material.AIR); pistonBlock.setType(Material.AIR);
return; return;
} }
} }
@ -546,7 +546,7 @@ public class BlockEventHandler implements Listener
{ {
//if piston not in a land claim, cancel event //if piston not in a land claim, cancel event
Claim pistonClaim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, null); Claim pistonClaim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, null);
if(pistonClaim == null) if(pistonClaim == null && !event.getBlocks().isEmpty())
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -568,7 +568,8 @@ public class BlockEventHandler implements Listener
{ {
//who owns the piston, if anyone? //who owns the piston, if anyone?
String pistonOwnerName = "_"; String pistonOwnerName = "_";
Location pistonLocation = event.getBlock().getLocation(); Block block = event.getBlock();
Location pistonLocation = block.getLocation();
Claim pistonClaim = this.dataStore.getClaimAt(pistonLocation, false, null); Claim pistonClaim = this.dataStore.getClaimAt(pistonLocation, false, null);
if(pistonClaim != null) pistonOwnerName = pistonClaim.getOwnerName(); if(pistonClaim != null) pistonOwnerName = pistonClaim.getOwnerName();
@ -584,6 +585,10 @@ public class BlockEventHandler implements Listener
if(!pistonOwnerName.equals(movingBlockOwnerName)) if(!pistonOwnerName.equals(movingBlockOwnerName))
{ {
event.setCancelled(true); event.setCancelled(true);
block.getWorld().createExplosion(block.getLocation(), 0);
block.getWorld().dropItem(block.getLocation(), new ItemStack(Material.PISTON_STICKY_BASE));
block.setType(Material.AIR);
return;
} }
} }
} }