Search in sources :

Example 16 with BlockData

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;
}
Also used : BlockState(org.bukkit.block.BlockState) CastContext(com.elmakers.mine.bukkit.api.action.CastContext) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) BlockData(com.elmakers.mine.bukkit.api.block.BlockData) ItemStack(org.bukkit.inventory.ItemStack) Nullable(javax.annotation.Nullable)

Example 17 with BlockData

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();
}
Also used : BlockData(com.elmakers.mine.bukkit.api.block.BlockData)

Example 18 with BlockData

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;
}
Also used : BlockData(com.elmakers.mine.bukkit.api.block.BlockData)

Example 19 with BlockData

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();
}
Also used : BlockData(com.elmakers.mine.bukkit.api.block.BlockData)

Example 20 with BlockData

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;
}
Also used : Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) BlockData(com.elmakers.mine.bukkit.api.block.BlockData)

Aggregations

BlockData (com.elmakers.mine.bukkit.api.block.BlockData)22 Block (org.bukkit.block.Block)6 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 Location (org.bukkit.Location)2 FallingBlock (org.bukkit.entity.FallingBlock)2 ItemStack (org.bukkit.inventory.ItemStack)2 CastContext (com.elmakers.mine.bukkit.api.action.CastContext)1 Batch (com.elmakers.mine.bukkit.api.batch.Batch)1 BlockList (com.elmakers.mine.bukkit.api.block.BlockList)1 MaterialBrush (com.elmakers.mine.bukkit.api.block.MaterialBrush)1 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)1 UndoQueue (com.elmakers.mine.bukkit.api.block.UndoQueue)1 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 MagicAPI (com.elmakers.mine.bukkit.api.magic.MagicAPI)1 MaterialSet (com.elmakers.mine.bukkit.api.magic.MaterialSet)1 LostWand (com.elmakers.mine.bukkit.api.wand.LostWand)1 UndoList (com.elmakers.mine.bukkit.block.UndoList)1 MagicController (com.elmakers.mine.bukkit.magic.MagicController)1