Fix piston retraction checking one block further than it needs to (#1036)

This commit is contained in:
jacob1 2020-10-12 00:15:54 -04:00 committed by GitHub
parent e4a666f8be
commit a34a0fecab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -493,18 +493,18 @@ public class BlockEventHandler implements Listener
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBlockPistonExtend(BlockPistonExtendEvent event)
{
onPistonEvent(event, event.getBlocks());
onPistonEvent(event, event.getBlocks(), false);
}
// Prevent pistons pulling blocks into or out of claims.
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBlockPistonRetract(BlockPistonRetractEvent event)
{
onPistonEvent(event, event.getBlocks());
onPistonEvent(event, event.getBlocks(), true);
}
// Handle piston push and pulls.
private void onPistonEvent(BlockPistonEvent event, List<Block> blocks)
private void onPistonEvent(BlockPistonEvent event, List<Block> blocks, boolean isRetract)
{
PistonMode pistonMode = GriefPrevention.instance.config_pistonMovement;
// Return if piston movements are ignored.
@ -514,6 +514,11 @@ public class BlockEventHandler implements Listener
if (!GriefPrevention.instance.claimsEnabledForWorld(event.getBlock().getWorld())) return;
BlockFace direction = event.getDirection();
// Direction is always piston facing, correct for retraction.
if (isRetract)
direction = direction.getOppositeFace();
Block pistonBlock = event.getBlock();
Claim pistonClaim = this.dataStore.getClaimAt(pistonBlock.getLocation(), false, null);
@ -583,7 +588,7 @@ public class BlockEventHandler implements Listener
}
// Pushing down or pulling up is safe if all blocks are in line with the piston.
if (minX == maxX && minZ == maxZ && direction == (event instanceof BlockPistonExtendEvent ? BlockFace.DOWN : BlockFace.UP)) return;
if (minX == maxX && minZ == maxZ && direction == (isRetract ? BlockFace.UP : BlockFace.DOWN)) return;
// Fast mode: Use the intersection of a cuboid containing all blocks instead of individual locations.
if (pistonMode == PistonMode.EVERYWHERE_SIMPLE)