Search in sources :

Example 6 with Countable

use of com.sk89q.worldedit.util.Countable in project FastAsyncWorldEdit by IntellectualSites.

the class BlockDistributionCounter method apply.

@Override
public boolean apply(BlockVector3 position) throws WorldEditException {
    BlockState blk = extent.getBlock(position);
    if (!separateStates) {
        blk = blk.getBlockType().getDefaultState();
    }
    if (map.containsKey(blk)) {
        map.get(blk).increment();
    } else {
        Countable<BlockState> c = new Countable<>(blk, 1);
        map.put(blk, c);
        distribution.add(c);
    }
    return true;
}
Also used : Countable(com.sk89q.worldedit.util.Countable) BlockState(com.sk89q.worldedit.world.block.BlockState)

Example 7 with Countable

use of com.sk89q.worldedit.util.Countable in project FastAsyncWorldEdit by IntellectualSites.

the class HistorySubCommands method distr.

@Command(name = "distr", aliases = { "distribution" }, desc = "View block distribution for an edit")
@CommandPermissions("worldedit.history.distr")
public void distr(Player player, LocalSession session, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @Arg(desc = "edit index") Integer index, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) throws ExecutionException, InterruptedException {
    String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
    Reference<PaginationBox> cached = player.getMeta(pageCommand);
    PaginationBox pages = cached == null ? null : cached.get();
    if (page == null || pages == null) {
        RollbackOptimizedHistory edit = database.getEdit(other, index).get();
        SimpleChangeSetSummary summary = edit.summarize(RegionWrapper.GLOBAL(), false);
        if (summary != null) {
            List<Countable<BlockState>> distr = summary.getBlockDistributionWithData();
            SelectionCommands.BlockDistributionResult distrPages = new SelectionCommands.BlockDistributionResult(distr, true, pageCommand);
            pages = new PaginationBox.MergedPaginationBox("Block Distribution", pageCommand, pages, distrPages);
            player.setMeta(pageCommand, new SoftReference<>(pages));
        }
        page = 1;
    }
    if (pages == null) {
        player.print(Caption.of("fawe.worldedit.history.distr.summary_null"));
    } else {
        player.print(pages.create(page));
    }
}
Also used : Countable(com.sk89q.worldedit.util.Countable) SimpleChangeSetSummary(com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

Countable (com.sk89q.worldedit.util.Countable)7 BlockState (com.sk89q.worldedit.world.block.BlockState)3 ArrayList (java.util.ArrayList)3 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)2 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 BlockType (com.sk89q.worldedit.world.block.BlockType)2 Command (org.enginehub.piston.annotation.Command)2 RollbackOptimizedHistory (com.fastasyncworldedit.core.history.RollbackOptimizedHistory)1 SimpleChangeSetSummary (com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary)1 Entity (com.sk89q.worldedit.entity.Entity)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 PaginationBox (com.sk89q.worldedit.util.formatting.component.PaginationBox)1 List (java.util.List)1