From f3891aaaf90a67d663b498eb93c87cdcdb506c73 Mon Sep 17 00:00:00 2001 From: sk89q Date: Wed, 3 Jun 2015 23:46:14 -0700 Subject: [PATCH] Add a workaround for incorrect piston retract information. --- .../listener/EventAbstractionListener.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index bd2a4075..cb2a0f18 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -64,9 +64,8 @@ import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import org.bukkit.material.*; import org.bukkit.material.Dispenser; -import org.bukkit.material.MaterialData; -import org.bukkit.material.SpawnEgg; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; @@ -243,18 +242,28 @@ public void onEntityExplode(EntityExplodeEvent event) { Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR)); } + @SuppressWarnings("deprecation") @EventHandler(ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) { if (event.isSticky()) { EventDebounce.Entry entry = pistonRetractDebounce.getIfNotPresent(new BlockPistonRetractKey(event), event); if (entry != null) { - Cause cause = create(event.getBlock()); - Events.fireToCancel(event, new BreakBlockEvent(event, cause, event.getRetractLocation(), Material.AIR)); - Events.fireToCancel(event, new PlaceBlockEvent(event, cause, event.getBlock().getRelative(event.getDirection()))); + Block piston = event.getBlock(); + Cause cause = create(piston); + + // Workaround for incorrect piston events + BlockFace direction = event.getDirection(); + if (piston.getType() == Material.PISTON_MOVING_PIECE) { + direction = new PistonExtensionMaterial(Material.PISTON_STICKY_BASE.getId(), piston.getData()).getFacing(); + } + Location retractLocation = piston.getRelative(direction, 2).getLocation(); + + Events.fireToCancel(event, new BreakBlockEvent(event, cause, retractLocation, Material.AIR)); + Events.fireToCancel(event, new PlaceBlockEvent(event, cause, piston.getRelative(direction))); entry.setCancelled(event.isCancelled()); if (event.isCancelled()) { - playDenyEffect(event.getBlock().getLocation().add(0.5, 1, 0.5)); + playDenyEffect(piston.getLocation().add(0.5, 1, 0.5)); } } }