2014-06-15 14:22:32 +02:00
|
|
|
package com.gmail.nossr50.runnables;
|
|
|
|
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.util.BlockUtils;
|
2014-06-15 14:22:32 +02:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BlockFace;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
2019-01-15 07:11:58 +01:00
|
|
|
import java.util.List;
|
2014-06-15 14:22:32 +02:00
|
|
|
|
|
|
|
public class PistonTrackerTask extends BukkitRunnable {
|
2020-07-13 20:39:03 +02:00
|
|
|
private final List<Block> blocks;
|
|
|
|
private final BlockFace direction;
|
|
|
|
private final Block futureEmptyBlock;
|
2014-06-15 14:22:32 +02:00
|
|
|
|
|
|
|
public PistonTrackerTask(List<Block> blocks, BlockFace direction, Block futureEmptyBlock) {
|
|
|
|
this.blocks = blocks;
|
|
|
|
this.direction = direction;
|
|
|
|
this.futureEmptyBlock = futureEmptyBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
// Check to see if futureEmptyBlock is empty - if it isn't; the blocks didn't move
|
|
|
|
if (!BlockUtils.isPistonPiece(futureEmptyBlock.getState())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mcMMO.getPlaceStore().isTrue(futureEmptyBlock)) {
|
|
|
|
mcMMO.getPlaceStore().setFalse(futureEmptyBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Block b : blocks) {
|
|
|
|
Block nextBlock = b.getRelative(direction);
|
|
|
|
|
|
|
|
if (nextBlock.hasMetadata(mcMMO.blockMetadataKey)) {
|
|
|
|
mcMMO.getPlaceStore().setTrue(nextBlock);
|
|
|
|
nextBlock.removeMetadata(mcMMO.blockMetadataKey, mcMMO.p);
|
|
|
|
}
|
|
|
|
else if (mcMMO.getPlaceStore().isTrue(nextBlock)) {
|
|
|
|
// Block doesn't have metadatakey but isTrue - set it to false
|
|
|
|
mcMMO.getPlaceStore().setFalse(nextBlock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|