From 6c29da94f30a98aff391c517d0698b8ced2675c7 Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Wed, 11 Mar 2015 11:36:51 +0200 Subject: [PATCH 1/2] Fixed duplication Bug #2419 --- src/main/java/com/gmail/nossr50/listeners/BlockListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 72b4676ac..011bef5e0 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -94,9 +94,9 @@ public class BlockListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) { - if (!EventUtils.shouldProcessEvent(event.getBlock(), false)) { + /*if (!EventUtils.shouldProcessEvent(event.getBlock(), false)) { return; - } + }*/ if (!event.isSticky()) { return; From f76771f0a8a4a4893d6c7eeff183579c576f703d Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Wed, 11 Mar 2015 14:31:56 +0200 Subject: [PATCH 2/2] Fixed duplication bug #2419 (Correct fix) --- .../nossr50/listeners/BlockListener.java | 24 +++++++++++++------ .../runnables/StickyPistonTrackerTask.java | 7 +++--- 2 files changed, 21 insertions(+), 10 deletions(-) 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); } }