Make //count take a mask. Also doc updates, perm fixes.

This commit is contained in:
wizjany 2019-06-30 00:38:17 -04:00
parent 1d1c38887f
commit 625cbe5e3d
6 changed files with 23 additions and 22 deletions

View File

@ -54,7 +54,7 @@ public class BukkitImplLoader {
"** will be blank, and so on. There will be no support for entity\n" +
"** and block property-related functions.\n" +
"**\n" +
"** Please see http://wiki.sk89q.com/wiki/WorldEdit/Bukkit_adapters\n" +
"** Please see https://worldedit.rtfd.io/en/latest/faq/#bukkit-adapters\n" +
"**********************************************\n";
/**

View File

@ -786,12 +786,23 @@ public class EditSession implements Extent, AutoCloseable {
*
* @param region the region
* @param searchBlocks the list of blocks to search
* @return the number of blocks that matched the pattern
* @return the number of blocks that matched the block
*/
public int countBlocks(Region region, Set<BaseBlock> searchBlocks) {
BlockMask mask = new BlockMask(this, searchBlocks);
return countBlocks(region, mask);
}
/**
* Count the number of blocks of a list of types in a region.
*
* @param region the region
* @param searchMask mask to match
* @return the number of blocks that matched the mask
*/
public int countBlocks(Region region, Mask searchMask) {
Counter count = new Counter();
RegionMaskingFilter filter = new RegionMaskingFilter(mask, count);
RegionMaskingFilter filter = new RegionMaskingFilter(searchMask, count);
RegionVisitor visitor = new RegionVisitor(region, filter);
Operations.completeBlindly(visitor); // We can't throw exceptions, nor do we expect any
return count.getCount();

View File

@ -264,7 +264,7 @@ public class GenerationCommands {
name = "/generate",
aliases = { "/gen", "/g" },
desc = "Generates a shape according to a formula.",
descFooter = "See also https://tinyurl.com/wesyntax."
descFooter = "See also https://tinyurl.com/weexpr."
)
@CommandPermissions("worldedit.generation.shape")
@Logging(ALL)
@ -325,7 +325,7 @@ public class GenerationCommands {
name = "/generatebiome",
aliases = { "/genbiome", "/gb" },
desc = "Sets biome according to a formula.",
descFooter = "See also https://tinyurl.com/wesyntax."
descFooter = "See also https://tinyurl.com/weexpr."
)
@CommandPermissions("worldedit.generation.shape.biome")
@Logging(ALL)

View File

@ -374,7 +374,7 @@ public class RegionCommands {
desc = "Deforms a selected region with an expression",
descFooter = "The expression is executed for each block and is expected\n" +
"to modify the variables x, y and z to point to a new block\n" +
"to fetch. See also tinyurl.com/wesyntax."
"to fetch. See also https://tinyurl.com/weexpr"
)
@CommandPermissions("worldedit.region.deform")
@Logging(ALL)

View File

@ -35,6 +35,7 @@ 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.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.internal.annotation.Direction;
@ -452,24 +453,13 @@ public class SelectionCommands {
@Command(
name = "/count",
desc = "Counts the number of a certain type of block"
desc = "Counts the number of blocks matching a mask"
)
@CommandPermissions("worldedit.analysis.count")
public void count(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The block type(s) to count")
String blocks,
@Switch(name = 'f', desc = "Fuzzy, match states using a wildcard")
boolean fuzzy) throws WorldEditException {
ParserContext context = new ParserContext();
context.setActor(player);
context.setExtent(player.getExtent());
context.setWorld(player.getWorld());
context.setSession(session);
context.setRestricted(false);
context.setPreferringWildcard(fuzzy);
Set<BaseBlock> searchBlocks = we.getBlockFactory().parseFromListInput(blocks, context);
int count = editSession.countBlocks(session.getSelection(player.getWorld()), searchBlocks);
@Arg(desc = "The mask of blocks to match")
Mask mask) throws WorldEditException {
int count = editSession.countBlocks(session.getSelection(player.getWorld()), mask);
player.print("Counted: " + count);
}

View File

@ -169,7 +169,7 @@ public class SessionManager {
if (owner.hasPermission("worldedit.selection.pos")) {
setDefaultWand(session.getWandItem(), config.wandItem, session, new SelectionWand());
}
if (owner.hasPermission("worldedit.nagivation.jumpto.tool") || owner.hasPermission("worldedit.nagivation.thru.tool")) {
if (owner.hasPermission("worldedit.navigation.jumpto.tool") || owner.hasPermission("worldedit.navigation.thru.tool")) {
setDefaultWand(session.getNavWandItem(), config.navigationWand, session, new NavigationWand());
}
} catch (InvalidToolBindException e) {