Search in sources :

Example 1 with BlockBagExtent

use of com.sk89q.worldedit.extent.inventory.BlockBagExtent in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method popMissingBlocks.

/**
 * Gets the list of missing blocks and clears the list for the next
 * operation.
 *
 * @return a map of missing blocks
 */
public Map<BlockType, Integer> popMissingBlocks() {
    BlockBag bag = getBlockBag();
    if (bag != null) {
        bag.flushChanges();
        Map<BlockType, Integer> missingBlocks;
        ChangeSet changeSet = getChangeSet();
        if (changeSet instanceof BlockBagChangeSet) {
            missingBlocks = ((BlockBagChangeSet) changeSet).popMissing();
        } else {
            ExtentTraverser<BlockBagExtent> find = new ExtentTraverser<>(getExtent()).find(BlockBagExtent.class);
            if (find != null && find.get() != null) {
                missingBlocks = find.get().popMissing();
            } else {
                missingBlocks = null;
            }
        }
        if (missingBlocks != null && !missingBlocks.isEmpty()) {
            StringBuilder str = new StringBuilder();
            int size = missingBlocks.size();
            int i = 0;
            for (Map.Entry<BlockType, Integer> entry : missingBlocks.entrySet()) {
                BlockType type = entry.getKey();
                int amount = entry.getValue();
                str.append((type.getName())).append((amount != 1 ? "x" + amount : ""));
                ++i;
                if (i != size) {
                    str.append(", ");
                }
            }
            actor.print(Caption.of("fawe.error.worldedit.some.fails.blockbag", str.toString()));
        }
    }
    return Collections.emptyMap();
}
Also used : BlockBagExtent(com.sk89q.worldedit.extent.inventory.BlockBagExtent) BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) BlockBagChangeSet(com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BlockType(com.sk89q.worldedit.world.block.BlockType) BlockBagChangeSet(com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) AbstractChangeSet(com.fastasyncworldedit.core.history.changeset.AbstractChangeSet) Map(java.util.Map) HashMap(java.util.HashMap) BlockMap(com.sk89q.worldedit.util.collection.BlockMap)

Aggregations

AbstractChangeSet (com.fastasyncworldedit.core.history.changeset.AbstractChangeSet)1 BlockBagChangeSet (com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet)1 BlockBag (com.sk89q.worldedit.extent.inventory.BlockBag)1 BlockBagExtent (com.sk89q.worldedit.extent.inventory.BlockBagExtent)1 ChangeSet (com.sk89q.worldedit.history.changeset.ChangeSet)1 BlockMap (com.sk89q.worldedit.util.collection.BlockMap)1 BlockType (com.sk89q.worldedit.world.block.BlockType)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1