From cfe61ef94534e5eb452ee5b635608139e5b78fec Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Fri, 3 Jun 2016 20:56:28 -0700 Subject: [PATCH] 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. --- .../GriefPrevention/BlockEventHandler.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java b/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java index 15507e3..126b49f 100644 --- a/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java @@ -489,9 +489,9 @@ public class BlockEventHandler implements Listener if(!claim.getOwnerName().equals(pistonClaimOwnerName)) { event.setCancelled(true); - event.getBlock().getWorld().createExplosion(event.getBlock().getLocation(), 0); - event.getBlock().getWorld().dropItem(event.getBlock().getLocation(), new ItemStack(event.getBlock().getType())); - event.getBlock().setType(Material.AIR); + pistonBlock.getWorld().createExplosion(pistonBlock.getLocation(), 0); + pistonBlock.getWorld().dropItem(pistonBlock.getLocation(), new ItemStack(pistonBlock.getType())); + pistonBlock.setType(Material.AIR); return; } } @@ -520,9 +520,9 @@ public class BlockEventHandler implements Listener if(!newOwnerName.equals(originalOwnerName) && !newOwnerName.isEmpty()) { event.setCancelled(true); - event.getBlock().getWorld().createExplosion(event.getBlock().getLocation(), 0); - event.getBlock().getWorld().dropItem(event.getBlock().getLocation(), new ItemStack(event.getBlock().getType())); - event.getBlock().setType(Material.AIR); + pistonBlock.getWorld().createExplosion(pistonBlock.getLocation(), 0); + pistonBlock.getWorld().dropItem(pistonBlock.getLocation(), new ItemStack(pistonBlock.getType())); + pistonBlock.setType(Material.AIR); return; } } @@ -546,7 +546,7 @@ public class BlockEventHandler implements Listener { //if piston not in a land claim, cancel event Claim pistonClaim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, null); - if(pistonClaim == null) + if(pistonClaim == null && !event.getBlocks().isEmpty()) { event.setCancelled(true); return; @@ -568,7 +568,8 @@ public class BlockEventHandler implements Listener { //who owns the piston, if anyone? String pistonOwnerName = "_"; - Location pistonLocation = event.getBlock().getLocation(); + Block block = event.getBlock(); + Location pistonLocation = block.getLocation(); Claim pistonClaim = this.dataStore.getClaimAt(pistonLocation, false, null); if(pistonClaim != null) pistonOwnerName = pistonClaim.getOwnerName(); @@ -584,6 +585,10 @@ public class BlockEventHandler implements Listener if(!pistonOwnerName.equals(movingBlockOwnerName)) { 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; } } }