Fixed a protection bug with pistons + slime blocks.

This commit is contained in:
ryanhamshire 2015-02-25 17:31:30 -08:00
parent 07ea755b4d
commit 97c9347772

View File

@ -471,15 +471,9 @@ public class BlockEventHandler implements Listener
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBlockPistonRetract (BlockPistonRetractEvent event) public void onBlockPistonRetract (BlockPistonRetractEvent event)
{ {
//we only care about sticky pistons retracting
if(!event.isSticky()) return;
//pulling up is always safe //pulling up is always safe
if(event.getDirection() == BlockFace.UP) return; if(event.getDirection() == BlockFace.UP) return;
//if pulling "air", always safe
if(event.getRetractLocation().getBlock().getType() == Material.AIR) return;
//don't track in worlds where claims are not enabled //don't track in worlds where claims are not enabled
if(!GriefPrevention.instance.claimsEnabledForWorld(event.getBlock().getWorld())) return; if(!GriefPrevention.instance.claimsEnabledForWorld(event.getBlock().getWorld())) return;
@ -494,33 +488,39 @@ public class BlockEventHandler implements Listener
return; return;
} }
//if pulled block isn't in the same land claim, cancel the event for(Block movedBlock : event.getBlocks())
if(!pistonClaim.contains(event.getRetractLocation(), false, false))
{ {
event.setCancelled(true); //if pulled block isn't in the same land claim, cancel the event
return; if(!pistonClaim.contains(movedBlock.getLocation(), false, false))
{
event.setCancelled(true);
return;
}
} }
} }
//otherwise, consider ownership of both piston and block //otherwise, consider ownership of both piston and block
else else
{ {
//who owns the moving block, if anyone? //who owns the piston, if anyone?
String movingBlockOwnerName = "_"; String pistonOwnerName = "_";
Claim movingBlockClaim = this.dataStore.getClaimAt(event.getRetractLocation(), false, null); Location pistonLocation = event.getBlock().getLocation();
if(movingBlockClaim != null) movingBlockOwnerName = movingBlockClaim.getOwnerName(); Claim pistonClaim = this.dataStore.getClaimAt(pistonLocation, false, null);
if(pistonClaim != null) pistonOwnerName = pistonClaim.getOwnerName();
//who owns the piston, if anyone?
String pistonOwnerName = "_"; String movingBlockOwnerName = "_";
Location pistonLocation = event.getBlock().getLocation(); for(Block movedBlock : event.getBlocks())
Claim pistonClaim = this.dataStore.getClaimAt(pistonLocation, false, movingBlockClaim);
if(pistonClaim != null) pistonOwnerName = pistonClaim.getOwnerName();
//if there are owners for the blocks, they must be the same player
//otherwise cancel the event
if(!pistonOwnerName.equals(movingBlockOwnerName))
{ {
event.setCancelled(true); //who owns the moving block, if anyone?
Claim movingBlockClaim = this.dataStore.getClaimAt(movedBlock.getLocation(), false, pistonClaim);
if(movingBlockClaim != null) movingBlockOwnerName = movingBlockClaim.getOwnerName();
//if there are owners for the blocks, they must be the same player
//otherwise cancel the event
if(!pistonOwnerName.equals(movingBlockOwnerName))
{
event.setCancelled(true);
}
} }
} }
} }