3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-04 18:40:06 +01:00

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

Dieser Commit ist enthalten in:
wizjany 2019-06-30 00:38:17 -04:00
Ursprung 1d1c38887f
Commit 625cbe5e3d
6 geänderte Dateien mit 23 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -54,7 +54,7 @@ public class BukkitImplLoader {
"** will be blank, and so on. There will be no support for entity\n" + "** will be blank, and so on. There will be no support for entity\n" +
"** and block property-related functions.\n" + "** and block property-related functions.\n" +
"**\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"; "**********************************************\n";
/** /**

Datei anzeigen

@ -786,12 +786,23 @@ public class EditSession implements Extent, AutoCloseable {
* *
* @param region the region * @param region the region
* @param searchBlocks the list of blocks to search * @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) { public int countBlocks(Region region, Set<BaseBlock> searchBlocks) {
BlockMask mask = new BlockMask(this, 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(); Counter count = new Counter();
RegionMaskingFilter filter = new RegionMaskingFilter(mask, count); RegionMaskingFilter filter = new RegionMaskingFilter(searchMask, count);
RegionVisitor visitor = new RegionVisitor(region, filter); RegionVisitor visitor = new RegionVisitor(region, filter);
Operations.completeBlindly(visitor); // We can't throw exceptions, nor do we expect any Operations.completeBlindly(visitor); // We can't throw exceptions, nor do we expect any
return count.getCount(); return count.getCount();

Datei anzeigen

@ -264,7 +264,7 @@ public class GenerationCommands {
name = "/generate", name = "/generate",
aliases = { "/gen", "/g" }, aliases = { "/gen", "/g" },
desc = "Generates a shape according to a formula.", 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") @CommandPermissions("worldedit.generation.shape")
@Logging(ALL) @Logging(ALL)
@ -325,7 +325,7 @@ public class GenerationCommands {
name = "/generatebiome", name = "/generatebiome",
aliases = { "/genbiome", "/gb" }, aliases = { "/genbiome", "/gb" },
desc = "Sets biome according to a formula.", 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") @CommandPermissions("worldedit.generation.shape.biome")
@Logging(ALL) @Logging(ALL)

Datei anzeigen

@ -374,7 +374,7 @@ public class RegionCommands {
desc = "Deforms a selected region with an expression", desc = "Deforms a selected region with an expression",
descFooter = "The expression is executed for each block and is expected\n" + 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 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") @CommandPermissions("worldedit.region.deform")
@Logging(ALL) @Logging(ALL)

Datei anzeigen

@ -35,6 +35,7 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.block.BlockDistributionCounter; 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.operation.Operations;
import com.sk89q.worldedit.function.visitor.RegionVisitor; import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.internal.annotation.Direction; import com.sk89q.worldedit.internal.annotation.Direction;
@ -452,24 +453,13 @@ public class SelectionCommands {
@Command( @Command(
name = "/count", 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") @CommandPermissions("worldedit.analysis.count")
public void count(Player player, LocalSession session, EditSession editSession, public void count(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The block type(s) to count") @Arg(desc = "The mask of blocks to match")
String blocks, Mask mask) throws WorldEditException {
@Switch(name = 'f', desc = "Fuzzy, match states using a wildcard") int count = editSession.countBlocks(session.getSelection(player.getWorld()), mask);
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);
player.print("Counted: " + count); player.print("Counted: " + count);
} }

Datei anzeigen

@ -169,7 +169,7 @@ public class SessionManager {
if (owner.hasPermission("worldedit.selection.pos")) { if (owner.hasPermission("worldedit.selection.pos")) {
setDefaultWand(session.getWandItem(), config.wandItem, session, new SelectionWand()); 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()); setDefaultWand(session.getNavWandItem(), config.navigationWand, session, new NavigationWand());
} }
} catch (InvalidToolBindException e) { } catch (InvalidToolBindException e) {