We do need to use a runnable.

This commit is contained in:
TfT_02 2014-03-10 20:51:52 +01:00
parent e1a8f02bce
commit ebdf11300b
2 changed files with 32 additions and 7 deletions

View File

@ -10,7 +10,6 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.BrewingStand; import org.bukkit.block.BrewingStand;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; 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.datatypes.skills.ToolType;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; 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.alchemy.Alchemy;
import com.gmail.nossr50.skills.excavation.ExcavationManager; import com.gmail.nossr50.skills.excavation.ExcavationManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.herbalism.HerbalismManager;
@ -96,12 +96,8 @@ public class BlockListener implements Listener {
Block movedBlock = event.getRetractLocation().getBlock(); Block movedBlock = event.getRetractLocation().getBlock();
if (!BlockUtils.shouldBeWatched(movedBlock.getState()) || movedBlock.getPistonMoveReaction() != PistonMoveReaction.MOVE || !mcMMO.getPlaceStore().isTrue(movedBlock)) { // Needed only because under some circumstances Minecraft doesn't move the block
return; new StickyPistonTrackerTask(event.getDirection(), movedBlock).runTaskLater(plugin, 2);
}
mcMMO.getPlaceStore().setFalse(movedBlock);
mcMMO.getPlaceStore().setTrue(event.getBlock().getRelative(event.getDirection()));
} }
/** /**

View File

@ -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));
}
}