diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java b/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java index 68829f398..c8b284bd8 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java @@ -52,6 +52,7 @@ import org.bukkit.material.Attachable; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; +import java.util.List; public class BlockListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -126,15 +127,15 @@ public void onRedstoneEvent(@NotNull BlockRedstoneEvent e) { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPistonExtendEvent(@NotNull BlockPistonExtendEvent e) { - onPistonEvent(e); + onPistonEvent(e, e.getBlocks()); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPistonRetractEvent(@NotNull BlockPistonRetractEvent e) { - onPistonEvent(e); + onPistonEvent(e, e.getBlocks()); } - public void onPistonEvent(@NotNull BlockPistonEvent e) { + public void onPistonEvent(@NotNull BlockPistonEvent e, final @NotNull List affectedBlocks) { Block block = e.getBlock(); Location location = block.getLocation(); MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(location); @@ -143,15 +144,13 @@ public void onPistonEvent(@NotNull BlockPistonEvent e) { continue; if (!craft.isNotProcessing()) - e.setCancelled(true); // prevent pistons on cruising crafts - if (!(e instanceof BlockPistonExtendEvent)) - return; - // merge piston extensions to craft - if (craft.getType().getBoolProperty(CraftType.MERGE_PISTON_EXTENSIONS)) + e.setCancelled(true); // prevent pistons on cruising crafts + // merge piston extensions to craft if the property is true + if (!craft.getType().getBoolProperty(CraftType.MERGE_PISTON_EXTENSIONS)) continue; BitmapHitBox hitBox = new BitmapHitBox(); - for (Block b : ((BlockPistonExtendEvent) e).getBlocks()) { + for (Block b : affectedBlocks) { Vector dir = e.getDirection().getDirection(); hitBox.add(new MovecraftLocation(b.getX() + dir.getBlockX(), b.getY() + dir.getBlockY(), b.getZ() + dir.getBlockZ())); }