From 9c925d332770a2aa5513facdde9a537eec158d1c Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 3 Mar 2014 11:40:36 -0500 Subject: [PATCH] We can do this without needing a runnable. --- .../nossr50/listeners/BlockListener.java | 16 +++++++--- .../runnables/StickyPistonTrackerTask.java | 31 ------------------- 2 files changed, 12 insertions(+), 35 deletions(-) delete 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 7622a1732..0709c3909 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -10,6 +10,7 @@ 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; @@ -31,7 +32,6 @@ 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; @@ -90,10 +90,18 @@ public class BlockListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) { - if (event.isSticky()) { - // Needed only because under some circumstances Minecraft doesn't move the block - new StickyPistonTrackerTask(event.getDirection(), event.getBlock()).runTaskLater(plugin, 2); + if (!event.isSticky()) { + return; } + + Block movedBlock = event.getRetractLocation().getBlock(); + + if (movedBlock.getPistonMoveReaction() != PistonMoveReaction.MOVE || !mcMMO.getPlaceStore().isTrue(movedBlock)) { + return; + } + + mcMMO.getPlaceStore().setFalse(movedBlock); + mcMMO.getPlaceStore().setTrue(event.getBlock().getRelative(event.getDirection())); } /** diff --git a/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java b/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java deleted file mode 100644 index 37a054ada..000000000 --- a/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.gmail.nossr50.runnables; - -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.scheduler.BukkitRunnable; - -import com.gmail.nossr50.mcMMO; - -public class StickyPistonTrackerTask extends BukkitRunnable { - private BlockFace direction; - private Block block; - - public StickyPistonTrackerTask(BlockFace direction, Block block) { - this.direction = direction; - this.block = block; - } - - @Override - public void run() { - Block newBlock = block.getRelative(direction); - Block originalBlock = newBlock.getRelative(direction); - - if (originalBlock.getType() != Material.AIR || !mcMMO.getPlaceStore().isTrue(originalBlock)) { - return; - } - - mcMMO.getPlaceStore().setFalse(originalBlock); - mcMMO.getPlaceStore().setTrue(newBlock); - } -}