use of com.elmakers.mine.bukkit.api.block.BlockData in project MagicPlugin by elBukkit.
the class UndoList method undoNext.
@Nullable
@Override
public BlockData undoNext(boolean applyPhysics) {
if (blockList.size() == 0) {
return null;
}
BlockData blockData = blockList.removeFirst();
BlockState currentState = blockData.getBlock().getState();
if (undo(blockData, applyPhysics)) {
blockIdMap.remove(blockData.getId());
if (consumed && !isScheduled() && currentState.getType() != Material.AIR && owner != null) {
owner.giveItem(new ItemStack(currentState.getType(), 1, DeprecatedUtils.getRawData(currentState)));
}
CastContext context = getContext();
if (context != null && context.hasEffects("undo_block")) {
Block block = blockData.getBlock();
if (block.getType() != currentState.getType()) {
context.playEffects("undo_block", 1.0f, null, null, block.getLocation(), null, block);
}
}
return blockData;
}
blockList.addFirst(blockData);
return null;
}
use of com.elmakers.mine.bukkit.api.block.BlockData in project MagicPlugin by elBukkit.
the class UndoList method commit.
@Override
public void commit() {
unlink();
unregisterWatched();
if (blockList == null)
return;
for (BlockData block : blockList) {
commit(block);
}
clear();
}
use of com.elmakers.mine.bukkit.api.block.BlockData in project MagicPlugin by elBukkit.
the class UndoList method undo.
private boolean undo(BlockData undoBlock, boolean applyPhysics) {
BlockData priorState = undoBlock.getPriorState();
// Remove any tagged metadata
if (undoBreakable) {
registry.removeBreakable(undoBlock);
}
if (undoReflective) {
registry.removeReflective(undoBlock);
}
boolean isTopOfQueue = undoBlock.getNextState() == null;
if (undoBlock.undo(applyPhysics ? ModifyType.NORMAL : modifyType)) {
removeFromModified(undoBlock, priorState);
// Continue watching this block until we completely finish the undo process
registerWatched(undoBlock);
// Undo breaking state only if this was the top of the queue
if (undoBreaking && isTopOfQueue) {
// This may have been unregistered already, if the block was broken for instance.
if (registry.removeBreaking(undoBlock) != null) {
CompatibilityUtils.clearBreaking(undoBlock.getBlock());
}
}
return true;
}
return false;
}
use of com.elmakers.mine.bukkit.api.block.BlockData in project MagicPlugin by elBukkit.
the class UndoList method prune.
@Override
public void prune() {
if (blockList == null)
return;
Iterator<BlockData> iterator = iterator();
while (iterator.hasNext()) {
BlockData block = iterator.next();
if (!block.isDifferent()) {
removeFromMap(block);
iterator.remove();
}
}
modifiedTime = System.currentTimeMillis();
}
use of com.elmakers.mine.bukkit.api.block.BlockData in project MagicPlugin by elBukkit.
the class UndoList method addAttachable.
protected boolean addAttachable(BlockData block, BlockFace direction, @Nonnull MaterialSet materials) {
Block testBlock = block.getBlock().getRelative(direction);
Long blockId = com.elmakers.mine.bukkit.block.BlockData.getBlockId(testBlock);
// This gets called recursively, so don't re-process anything
if (blockIdMap != null && blockIdMap.contains(blockId)) {
return false;
}
if (watching != null && watching.containsKey(blockId)) {
return false;
}
if (materials.testBlock(testBlock)) {
BlockData newBlock = new com.elmakers.mine.bukkit.block.BlockData(testBlock);
if (contain(newBlock)) {
registerWatched(newBlock);
newBlock.setUndoList(this);
if (attachablesDouble.testBlock(testBlock)) {
if (direction != BlockFace.UP) {
add(newBlock);
addAttachable(newBlock, BlockFace.DOWN, materials);
} else if (direction != BlockFace.DOWN) {
add(newBlock);
addAttachable(newBlock, BlockFace.UP, materials);
}
}
return true;
}
}
return false;
}
Aggregations