Search in sources :

Example 1 with BlockDistributionCounter

use of com.sk89q.worldedit.function.block.BlockDistributionCounter in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method distr.

@Command(name = "/distr", desc = "Get the distribution of blocks in the selection")
@CommandPermissions("worldedit.analysis.distr")
public void distr(Actor actor, World world, LocalSession session, // FAWE start > add extent to RegionVisitor to allow chunk preloading
EditSession editSession, // FAWE end
@Switch(name = 'c', desc = "Get the distribution of the clipboard instead") boolean clipboardDistr, @Switch(name = 'd', desc = "Separate blocks by state") boolean separateStates, @ArgFlag(name = 'p', desc = "Gets page from a previous distribution.") Integer page) throws WorldEditException {
    List<Countable<BlockState>> distribution;
    if (page == null) {
        if (clipboardDistr) {
            // throws if missing
            Clipboard clipboard = session.getClipboard().getClipboard();
            BlockDistributionCounter count = new BlockDistributionCounter(clipboard, separateStates);
            // FAWE start > add extent to RegionVisitor to allow chunk preloading
            RegionVisitor visitor = new RegionVisitor(clipboard.getRegion(), count, editSession);
            // FAWE end
            Operations.completeBlindly(visitor);
            distribution = count.getDistribution();
        } else {
            distribution = editSession.getBlockDistribution(session.getSelection(world), separateStates);
        }
        session.setLastDistribution(distribution);
        page = 1;
    } else {
        distribution = session.getLastDistribution();
        if (distribution == null) {
            actor.print(Caption.of("worldedit.distr.no-previous"));
            return;
        }
    }
    if (distribution.isEmpty()) {
        // *Should* always be false
        actor.print(Caption.of("worldedit.distr.no-blocks"));
        return;
    }
    BlockDistributionResult res = new BlockDistributionResult(distribution, separateStates);
    if (!actor.isPlayer()) {
        res.formatForConsole();
    }
    actor.print(res.create(page));
}
Also used : Countable(com.sk89q.worldedit.util.Countable) RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) BlockDistributionCounter(com.sk89q.worldedit.function.block.BlockDistributionCounter) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 BlockDistributionCounter (com.sk89q.worldedit.function.block.BlockDistributionCounter)1 RegionVisitor (com.sk89q.worldedit.function.visitor.RegionVisitor)1 Countable (com.sk89q.worldedit.util.Countable)1 Command (org.enginehub.piston.annotation.Command)1