From ebdf11300bbeafc133ac3443c191a271a83a1b49 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Mon, 10 Mar 2014 20:51:52 +0100 Subject: [PATCH] We do need to use a runnable. --- .../nossr50/listeners/BlockListener.java | 10 ++----- .../runnables/StickyPistonTrackerTask.java | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index d9fecf819..f6224ed06 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -10,7 +10,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.BrewingStand; -import org.bukkit.block.PistonMoveReaction; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -32,6 +31,7 @@ import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; +import com.gmail.nossr50.runnables.StickyPistonTrackerTask; import com.gmail.nossr50.skills.alchemy.Alchemy; import com.gmail.nossr50.skills.excavation.ExcavationManager; import com.gmail.nossr50.skills.herbalism.HerbalismManager; @@ -96,12 +96,8 @@ public class BlockListener implements Listener { Block movedBlock = event.getRetractLocation().getBlock(); - if (!BlockUtils.shouldBeWatched(movedBlock.getState()) || movedBlock.getPistonMoveReaction() != PistonMoveReaction.MOVE || !mcMMO.getPlaceStore().isTrue(movedBlock)) { - return; - } - - mcMMO.getPlaceStore().setFalse(movedBlock); - mcMMO.getPlaceStore().setTrue(event.getBlock().getRelative(event.getDirection())); + // Needed only because under some circumstances Minecraft doesn't move the block + new StickyPistonTrackerTask(event.getDirection(), 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 new file mode 100644 index 000000000..0324a8f73 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java @@ -0,0 +1,29 @@ +package com.gmail.nossr50.runnables; + +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.PistonMoveReaction; +import org.bukkit.scheduler.BukkitRunnable; + +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.util.BlockUtils; + +public class StickyPistonTrackerTask extends BukkitRunnable { + private BlockFace direction; + private Block movedBlock; + + public StickyPistonTrackerTask(BlockFace direction, Block movedBlock) { + this.direction = direction; + this.movedBlock = movedBlock; + } + + @Override + public void run() { + if (!BlockUtils.shouldBeWatched(movedBlock.getState()) || movedBlock.getPistonMoveReaction() != PistonMoveReaction.MOVE || !mcMMO.getPlaceStore().isTrue(movedBlock)) { + return; + } + + mcMMO.getPlaceStore().setFalse(movedBlock); + mcMMO.getPlaceStore().setTrue(movedBlock.getRelative(direction)); + } +}