diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 011bef5e0..2c142d1b5 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.listeners; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -94,18 +95,27 @@ public class BlockListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) { - /*if (!EventUtils.shouldProcessEvent(event.getBlock(), false)) { - return; - }*/ - - if (!event.isSticky()) { + if (!EventUtils.shouldProcessEvent(event.getBlock(), false)) { return; } - Block movedBlock = event.getRetractLocation().getBlock(); + // Don't even work, return ALLWAYS false xD + /*if (!event.isSticky()){ + return; + }*/ + + // Sticky piston return PISTON_MOVING_PIECE and normal piston PISTON_BASE, so mess stuff + if (event.getBlock().getType() != Material.PISTON_MOVING_PIECE) { + return; + } + + // event.getRetractLocation() return wrong side and too far away + // Get opposite direction so we get correct block, so mess stuff + Block movedBlock = event.getBlock().getRelative(event.getDirection().getOppositeFace()); // Needed only because under some circumstances Minecraft doesn't move the block - new StickyPistonTrackerTask(event.getDirection(), event.getBlock(), movedBlock).runTaskLater(plugin, 2); + // Opposite side here too + new StickyPistonTrackerTask(event.getDirection().getOppositeFace(), event.getBlock(), movedBlock).runTaskLater(plugin, 2); } /** diff --git a/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java b/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java index 148ce83b2..bad701619 100644 --- a/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.runnables; +import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.scheduler.BukkitRunnable; @@ -20,7 +21,7 @@ public class StickyPistonTrackerTask extends BukkitRunnable { @Override public void run() { - if (!mcMMO.getPlaceStore().isTrue(movedBlock)) { + if (!mcMMO.getPlaceStore().isTrue(movedBlock.getRelative(direction))) { return; } @@ -30,7 +31,7 @@ public class StickyPistonTrackerTask extends BukkitRunnable { } // The sticky piston actually pulled the block so move the PlaceStore data - mcMMO.getPlaceStore().setFalse(movedBlock); - mcMMO.getPlaceStore().setTrue(movedBlock.getRelative(direction)); + mcMMO.getPlaceStore().setFalse(movedBlock.getRelative(direction)); + mcMMO.getPlaceStore().setTrue(movedBlock); } }