From 8eccdc74445a08e87bc80df3ee3d05bbafd8c039 Mon Sep 17 00:00:00 2001 From: wizjany Date: Mon, 25 Mar 2019 22:38:51 -0400 Subject: [PATCH] Add -f flag to //count to allow fuzzy inputs. Also re-implement //distr -c. And remove outdated help text on //copy. --- .../worldedit/command/ClipboardCommands.java | 3 +-- .../worldedit/command/SelectionCommands.java | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 95cb27f66..0f61f0d2a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -75,8 +75,7 @@ public class ClipboardCommands { help = "Copy the selection to the clipboard\n" + "Flags:\n" + " -e will also copy entities\n" + - " -m sets a source mask so that excluded blocks become air\n" + - "WARNING: Pasting entities cannot yet be undone!", + " -m sets a source mask so that excluded blocks become air", min = 0, max = 0 ) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java index f0fc6634f..9ded39f33 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java @@ -36,6 +36,9 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.function.block.BlockDistributionCounter; +import com.sk89q.worldedit.function.operation.Operations; +import com.sk89q.worldedit.function.visitor.RegionVisitor; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; @@ -625,6 +628,7 @@ public class SelectionCommands { @Command( aliases = { "/count" }, usage = "", + flags = "f", desc = "Counts the number of a certain type of block", min = 1, max = 1 @@ -638,6 +642,7 @@ public class SelectionCommands { context.setWorld(player.getWorld()); context.setSession(session); context.setRestricted(false); + context.setPreferringWildcard(args.hasFlag('f')); Set searchBlocks = we.getBlockFactory().parseFromListInput(args.getString(0), context); int count = editSession.countBlocks(session.getSelection(player.getWorld()), searchBlocks); @@ -659,16 +664,17 @@ public class SelectionCommands { @CommandPermissions("worldedit.analysis.distr") public void distr(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException, CommandException { - int size; boolean separateStates = args.hasFlag('d'); List> distribution; if (args.hasFlag('c')) { - // TODO: Update for new clipboard - throw new CommandException("Needs to be re-written again"); + Clipboard clipboard = session.getClipboard().getClipboard(); // throws if missing + BlockDistributionCounter count = new BlockDistributionCounter(clipboard, separateStates); + RegionVisitor visitor = new RegionVisitor(clipboard.getRegion(), count); + Operations.completeBlindly(visitor); + distribution = count.getDistribution(); } else { distribution = editSession.getBlockDistribution(session.getSelection(player.getWorld()), separateStates); - size = session.getSelection(player.getWorld()).getArea(); } if (distribution.isEmpty()) { // *Should* always be false @@ -676,19 +682,21 @@ public class SelectionCommands { return; } + // note: doing things like region.getArea is inaccurate for non-cuboids. + int size = distribution.stream().mapToInt(Countable::getAmount).sum(); player.print("# total blocks: " + size); for (Countable c : distribution) { String name = c.getID().getBlockType().getName(); String str; if (separateStates) { - str = String.format("%-7s (%.3f%%) %s #%s", + str = String.format("%-7s (%.3f%%) %s (%s)", String.valueOf(c.getAmount()), c.getAmount() / (double) size * 100, name, c.getID().getAsString()); } else { - str = String.format("%-7s (%.3f%%) %s #%s", + str = String.format("%-7s (%.3f%%) %s (%s)", String.valueOf(c.getAmount()), c.getAmount() / (double) size * 100, name,