mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
We can do this without needing a runnable.
This commit is contained in:
parent
30f7521a3a
commit
9c925d3327
@ -10,6 +10,7 @@ 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;
|
||||||
@ -31,7 +32,6 @@ 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;
|
||||||
@ -90,10 +90,18 @@ public class BlockListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||||
if (event.isSticky()) {
|
if (!event.isSticky()) {
|
||||||
// Needed only because under some circumstances Minecraft doesn't move the block
|
return;
|
||||||
new StickyPistonTrackerTask(event.getDirection(), event.getBlock()).runTaskLater(plugin, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user