Port region commands

This commit is contained in:
Kenzie Togami 2019-04-23 18:46:46 -07:00
parent f2283e8ad0
commit f81ffdde0c
No known key found for this signature in database
GPG Key ID: 5D200B325E157A81
3 changed files with 183 additions and 198 deletions

View File

@ -19,20 +19,11 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
import static com.sk89q.worldedit.command.util.Logging.LogMode.ORIENTATION_REGION;
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
import static com.sk89q.worldedit.regions.Regions.asFlatRegion;
import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
import static com.sk89q.worldedit.regions.Regions.minimumBlockY;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.function.GroundFunction; import com.sk89q.worldedit.function.GroundFunction;
@ -57,56 +48,54 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.util.TreeGenerator.TreeType; import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.util.command.binding.Range; import org.enginehub.piston.annotation.Command;
import com.sk89q.worldedit.util.command.binding.Switch; import org.enginehub.piston.annotation.CommandContainer;
import com.sk89q.worldedit.util.command.binding.Text; import org.enginehub.piston.annotation.param.Arg;
import com.sk89q.worldedit.util.command.parametric.Optional; import org.enginehub.piston.annotation.param.Switch;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
import static com.sk89q.worldedit.command.util.Logging.LogMode.ORIENTATION_REGION;
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
import static com.sk89q.worldedit.regions.Regions.asFlatRegion;
import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
import static com.sk89q.worldedit.regions.Regions.minimumBlockY;
/** /**
* Commands that operate on regions. * Commands that operate on regions.
*/ */
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class RegionCommands { public class RegionCommands {
private final WorldEdit worldEdit;
/** /**
* Create a new instance. * Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/ */
public RegionCommands(WorldEdit worldEdit) { public RegionCommands() {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
aliases = { "/line" }, name = "/line",
usage = "<pattern> [thickness]",
desc = "Draws a line segment between cuboid selection corners", desc = "Draws a line segment between cuboid selection corners",
help = descFooter = "Can only be used with a cuboid selection"
"Draws a line segment between cuboid selection corners.\n" +
"Can only be used with cuboid selections.\n" +
"Flags:\n" +
" -h generates only a shell",
flags = "h",
min = 1,
max = 2
) )
@CommandPermissions("worldedit.region.line") @CommandPermissions("worldedit.region.line")
@Logging(REGION) @Logging(REGION)
public void line(Player player, EditSession editSession, public int line(Player player, EditSession editSession,
@Selection Region region, @Selection Region region,
@Arg(desc = "The pattern of blocks to place")
Pattern pattern, Pattern pattern,
@Optional("0") @Range(min = 0) int thickness, @Arg(desc = "The thickness of the line", def = "0")
@Switch('h') boolean shell) throws WorldEditException { int thickness,
@Switch(name = 'h', desc = "Generate only a shell")
boolean shell) throws WorldEditException {
if (!(region instanceof CuboidRegion)) { if (!(region instanceof CuboidRegion)) {
player.printError("//line only works with cuboid selections"); player.printError("//line only works with cuboid selections");
return; return 0;
} }
checkArgument(thickness >= 0, "Thickness must be >= 0");
CuboidRegion cuboidregion = (CuboidRegion) region; CuboidRegion cuboidregion = (CuboidRegion) region;
BlockVector3 pos1 = cuboidregion.getPos1(); BlockVector3 pos1 = cuboidregion.getPos1();
@ -114,32 +103,29 @@ public class RegionCommands {
int blocksChanged = editSession.drawLine(pattern, pos1, pos2, thickness, !shell); int blocksChanged = editSession.drawLine(pattern, pos1, pos2, thickness, !shell);
player.print(blocksChanged + " block(s) have been changed."); player.print(blocksChanged + " block(s) have been changed.");
return blocksChanged;
} }
@Command( @Command(
aliases = { "/curve" }, name = "/curve",
usage = "<pattern> [thickness]",
desc = "Draws a spline through selected points", desc = "Draws a spline through selected points",
help = descFooter = "Can only be used with a convex polyhedral selection"
"Draws a spline through selected points.\n" +
"Can only be used with convex polyhedral selections.\n" +
"Flags:\n" +
" -h generates only a shell",
flags = "h",
min = 1,
max = 2
) )
@CommandPermissions("worldedit.region.curve") @CommandPermissions("worldedit.region.curve")
@Logging(REGION) @Logging(REGION)
public void curve(Player player, EditSession editSession, public int curve(Player player, EditSession editSession,
@Selection Region region, @Selection Region region,
@Arg(desc = "The pattern of blocks to place")
Pattern pattern, Pattern pattern,
@Optional("0") @Range(min = 0) int thickness, @Arg(desc = "The thickness of the curve", def = "0")
@Switch('h') boolean shell) throws WorldEditException { int thickness,
@Switch(name = 'h', desc = "Generate only a shell")
boolean shell) throws WorldEditException {
if (!(region instanceof ConvexPolyhedralRegion)) { if (!(region instanceof ConvexPolyhedralRegion)) {
player.printError("//curve only works with convex polyhedral selections"); player.printError("//curve only works with convex polyhedral selections");
return; return 0;
} }
checkArgument(thickness >= 0, "Thickness must be >= 0");
ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region; ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region;
List<BlockVector3> vectors = new ArrayList<>(cpregion.getVertices()); List<BlockVector3> vectors = new ArrayList<>(cpregion.getVertices());
@ -147,139 +133,140 @@ public class RegionCommands {
int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, thickness, !shell); int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, thickness, !shell);
player.print(blocksChanged + " block(s) have been changed."); player.print(blocksChanged + " block(s) have been changed.");
return blocksChanged;
} }
@Command( @Command(
aliases = { "/replace", "/re", "/rep" }, name = "/replace",
usage = "[from-block] <to-block>", aliases = { "/re", "/rep" },
desc = "Replace all blocks in the selection with another", desc = "Replace all blocks in the selection with another"
flags = "f",
min = 1,
max = 2
) )
@CommandPermissions("worldedit.region.replace") @CommandPermissions("worldedit.region.replace")
@Logging(REGION) @Logging(REGION)
public void replace(Player player, EditSession editSession, @Selection Region region, @Optional Mask from, Pattern to) throws WorldEditException { public int replace(Player player, EditSession editSession, @Selection Region region,
@Arg(desc = "The mask representing blocks to replace", def = "")
Mask from,
@Arg(desc = "The pattern of blocks to replace with")
Pattern to) throws WorldEditException {
if (from == null) { if (from == null) {
from = new ExistingBlockMask(editSession); from = new ExistingBlockMask(editSession);
} }
int affected = editSession.replaceBlocks(region, from, to); int affected = editSession.replaceBlocks(region, from, to);
player.print(affected + " block(s) have been replaced."); player.print(affected + " block(s) have been replaced.");
return affected;
} }
@Command( @Command(
aliases = { "/overlay" }, name = "/overlay",
usage = "<pattern>", desc = "Set a block on top of blocks in the region"
desc = "Set a block on top of blocks in the region",
min = 1,
max = 1
) )
@CommandPermissions("worldedit.region.overlay") @CommandPermissions("worldedit.region.overlay")
@Logging(REGION) @Logging(REGION)
public void overlay(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException { public int overlay(Player player, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to overlay")
Pattern pattern) throws WorldEditException {
int affected = editSession.overlayCuboidBlocks(region, pattern); int affected = editSession.overlayCuboidBlocks(region, pattern);
player.print(affected + " block(s) have been overlaid."); player.print(affected + " block(s) have been overlaid.");
return affected;
} }
@Command( @Command(
aliases = { "/center", "/middle" }, name = "/center",
usage = "<pattern>", aliases = { "/middle" },
desc = "Set the center block(s)", desc = "Set the center block(s)"
min = 1,
max = 1
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.region.center") @CommandPermissions("worldedit.region.center")
public void center(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException { public int center(Player player, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to set")
Pattern pattern) throws WorldEditException {
int affected = editSession.center(region, pattern); int affected = editSession.center(region, pattern);
player.print("Center set ("+ affected + " blocks changed)"); player.print("Center set (" + affected + " block(s) changed)");
return affected;
} }
@Command( @Command(
aliases = { "/naturalize" }, name = "/naturalize",
usage = "", desc = "3 layers of dirt on top then rock below"
desc = "3 layers of dirt on top then rock below",
min = 0,
max = 0
) )
@CommandPermissions("worldedit.region.naturalize") @CommandPermissions("worldedit.region.naturalize")
@Logging(REGION) @Logging(REGION)
public void naturalize(Player player, EditSession editSession, @Selection Region region) throws WorldEditException { public int naturalize(Player player, EditSession editSession, @Selection Region region) throws WorldEditException {
int affected = editSession.naturalizeCuboidBlocks(region); int affected = editSession.naturalizeCuboidBlocks(region);
player.print(affected + " block(s) have been made to look more natural."); player.print(affected + " block(s) have been made to look more natural.");
return affected;
} }
@Command( @Command(
aliases = { "/walls" }, name = "/walls",
usage = "<pattern>", desc = "Build the four sides of the selection"
desc = "Build the four sides of the selection",
min = 1,
max = 1
) )
@CommandPermissions("worldedit.region.walls") @CommandPermissions("worldedit.region.walls")
@Logging(REGION) @Logging(REGION)
public void walls(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException { public int walls(Player player, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to set")
Pattern pattern) throws WorldEditException {
int affected = editSession.makeWalls(region, pattern); int affected = editSession.makeWalls(region, pattern);
player.print(affected + " block(s) have been changed."); player.print(affected + " block(s) have been changed.");
return affected;
} }
@Command( @Command(
aliases = { "/faces", "/outline" }, name = "/faces",
usage = "<pattern>", aliases = { "/outline" },
desc = "Build the walls, ceiling, and floor of a selection", desc = "Build the walls, ceiling, and floor of a selection"
min = 1,
max = 1
) )
@CommandPermissions("worldedit.region.faces") @CommandPermissions("worldedit.region.faces")
@Logging(REGION) @Logging(REGION)
public void faces(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException { public int faces(Player player, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to set")
Pattern pattern) throws WorldEditException {
int affected = editSession.makeCuboidFaces(region, pattern); int affected = editSession.makeCuboidFaces(region, pattern);
player.print(affected + " block(s) have been changed."); player.print(affected + " block(s) have been changed.");
return affected;
} }
@Command( @Command(
aliases = { "/smooth" }, name = "/smooth",
usage = "[iterations] [filter]",
desc = "Smooth the elevation in the selection", desc = "Smooth the elevation in the selection",
help = descFooter = "Example: '//smooth 1 grass_block,dirt,stone' would only smooth natural surface terrain."
"Smooths the elevation in the selection.\n" +
"Optionally, restricts the height map to a set of blocks specified with mask syntax.\n" +
"For example, '//smooth 1 grass_block,dirt,stone' would only smooth natural surface terrain.",
min = 0,
max = 2
) )
@CommandPermissions("worldedit.region.smooth") @CommandPermissions("worldedit.region.smooth")
@Logging(REGION) @Logging(REGION)
public void smooth(Player player, EditSession editSession, @Selection Region region, @Optional("1") int iterations, @Optional Mask mask) throws WorldEditException { public int smooth(Player player, EditSession editSession, @Selection Region region,
@Arg(desc = "# of iterations to perform", def = "1")
int iterations,
@Arg(desc = "The mask of blocks to use as the height map", def = "")
Mask mask) throws WorldEditException {
HeightMap heightMap = new HeightMap(editSession, region, mask); HeightMap heightMap = new HeightMap(editSession, region, mask);
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0)); HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
int affected = heightMap.applyFilter(filter, iterations); int affected = heightMap.applyFilter(filter, iterations);
player.print("Terrain's height map smoothed. " + affected + " block(s) changed."); player.print("Terrain's height map smoothed. " + affected + " block(s) changed.");
return affected;
} }
@Command( @Command(
aliases = { "/move" }, name = "/move",
usage = "[count] [direction] [leave-id]", desc = "Move the contents of the selection"
flags = "sa",
desc = "Move the contents of the selection",
help =
"Moves the contents of the selection.\n" +
"The -s flag shifts the selection to the target location.\n" +
"The -a flag skips air blocks.\n" +
"Optionally fills the old location with <leave-id>.",
min = 0,
max = 3
) )
@CommandPermissions("worldedit.region.move") @CommandPermissions("worldedit.region.move")
@Logging(ORIENTATION_REGION) @Logging(ORIENTATION_REGION)
public void move(Player player, EditSession editSession, LocalSession session, public int move(Player player, EditSession editSession, LocalSession session,
@Selection Region region, @Selection Region region,
@Optional("1") @Range(min = 1) int count, @Arg(desc = "# of blocks to move", def = "1")
@Optional(Direction.AIM) @Direction(includeDiagonals = true) BlockVector3 direction, int count,
@Optional("air") Pattern replace, @Arg(desc = "The direction to move", def = Direction.AIM)
@Switch('s') boolean moveSelection, @Direction(includeDiagonals = true)
@Switch('a') boolean ignoreAirBlocks) throws WorldEditException { BlockVector3 direction,
@Arg(desc = "The pattern of blocks to leave", def = "air")
Pattern replace,
@Switch(name = 's', desc = "Shift the selection to the target location")
boolean moveSelection,
@Switch(name = 'a', desc = "Ignore air blocks")
boolean ignoreAirBlocks) throws WorldEditException {
if (count < 1) {
throw new IllegalArgumentException("Count must be >= 1");
}
int affected = editSession.moveRegion(region, direction, count, !ignoreAirBlocks, replace); int affected = editSession.moveRegion(region, direction, count, !ignoreAirBlocks, replace);
@ -294,30 +281,27 @@ public class RegionCommands {
} }
} }
player.print(affected + " blocks moved."); player.print(affected + " block(s) moved.");
return affected;
} }
@Command( @Command(
aliases = { "/stack" }, name = "/stack",
usage = "[count] [direction]", desc = "Repeat the contents of the selection"
flags = "sa",
desc = "Repeat the contents of the selection",
help =
"Repeats the contents of the selection.\n" +
"Flags:\n" +
" -s shifts the selection to the last stacked copy\n" +
" -a skips air blocks",
min = 0,
max = 2
) )
@CommandPermissions("worldedit.region.stack") @CommandPermissions("worldedit.region.stack")
@Logging(ORIENTATION_REGION) @Logging(ORIENTATION_REGION)
public void stack(Player player, EditSession editSession, LocalSession session, public int stack(Player player, EditSession editSession, LocalSession session,
@Selection Region region, @Selection Region region,
@Optional("1") @Range(min = 1) int count, @Arg(desc = "# of copies to stack", def = "1")
@Optional(Direction.AIM) @Direction(includeDiagonals = true) BlockVector3 direction, int count,
@Switch('s') boolean moveSelection, @Arg(desc = "The direction to stack", def = Direction.AIM)
@Switch('a') boolean ignoreAirBlocks) throws WorldEditException { @Direction(includeDiagonals = true)
BlockVector3 direction,
@Switch(name = 's', desc = "Shift the selection to the last stacked copy")
boolean moveSelection,
@Switch(name = 'a', desc = "Ignore air blocks")
boolean ignoreAirBlocks) throws WorldEditException {
int affected = editSession.stackCuboidRegion(region, direction, count, !ignoreAirBlocks); int affected = editSession.stackCuboidRegion(region, direction, count, !ignoreAirBlocks);
if (moveSelection) { if (moveSelection) {
@ -334,26 +318,22 @@ public class RegionCommands {
} }
} }
player.print(affected + " blocks changed. Undo with //undo"); player.print(affected + " block(s) changed. Undo with //undo");
return affected;
} }
@Command( @Command(
aliases = { "/regen" }, name = "/regen",
usage = "",
desc = "Regenerates the contents of the selection", desc = "Regenerates the contents of the selection",
help = descFooter = "This command might affect things outside the selection,\n" +
"Regenerates the contents of the current selection.\n" + "if they are within the same chunk."
"This command might affect things outside the selection,\n" +
"if they are within the same chunk.",
min = 0,
max = 0
) )
@CommandPermissions("worldedit.regen") @CommandPermissions("worldedit.regen")
@Logging(REGION) @Logging(REGION)
public void regenerateChunk(Player player, LocalSession session, EditSession editSession, @Selection Region region) throws WorldEditException { public void regenerateChunk(Player player, LocalSession session, EditSession editSession, @Selection Region region) throws WorldEditException {
Mask mask = session.getMask(); Mask mask = session.getMask();
try { try {
session.setMask((Mask) null); session.setMask(null);
player.getWorld().regenerate(region, editSession); player.getWorld().regenerate(region, editSession);
} finally { } finally {
session.setMask(mask); session.setMask(mask);
@ -362,25 +342,22 @@ public class RegionCommands {
} }
@Command( @Command(
aliases = { "/deform" }, name = "/deform",
usage = "<expression>",
desc = "Deforms a selected region with an expression", desc = "Deforms a selected region with an expression",
help = descFooter = "The expression is executed for each block and is expected\n" +
"Deforms a selected region with an expression\n" +
"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 tinyurl.com/wesyntax."
flags = "ro",
min = 1,
max = -1
) )
@CommandPermissions("worldedit.region.deform") @CommandPermissions("worldedit.region.deform")
@Logging(ALL) @Logging(ALL)
public void deform(Player player, LocalSession session, EditSession editSession, public int deform(Player player, LocalSession session, EditSession editSession,
@Selection Region region, @Selection Region region,
@Text String expression, @Arg(desc = "The expression to use")
@Switch('r') boolean useRawCoords, String expression,
@Switch('o') boolean offset) throws WorldEditException { @Switch(name = 'r', desc = "Use the game's coordinate origin")
boolean useRawCoords,
@Switch(name = 'o', desc = "Use the selection's center as origin")
boolean offset) throws WorldEditException {
final Vector3 zero; final Vector3 zero;
Vector3 unit; Vector3 unit;
@ -406,58 +383,60 @@ public class RegionCommands {
final int affected = editSession.deformRegion(region, zero, unit, expression, session.getTimeout()); final int affected = editSession.deformRegion(region, zero, unit, expression, session.getTimeout());
player.findFreePosition(); player.findFreePosition();
player.print(affected + " block(s) have been deformed."); player.print(affected + " block(s) have been deformed.");
return affected;
} catch (ExpressionException e) { } catch (ExpressionException e) {
player.printError(e.getMessage()); player.printError(e.getMessage());
return 0;
} }
} }
@Command( @Command(
aliases = { "/hollow" }, name = "/hollow",
usage = "[<thickness>[ <pattern>]]",
desc = "Hollows out the object contained in this selection", desc = "Hollows out the object contained in this selection",
help = descFooter = "Thickness is measured in manhattan distance."
"Hollows out the object contained in this selection.\n" +
"Optionally fills the hollowed out part with the given block.\n" +
"Thickness is measured in manhattan distance.",
min = 0,
max = 2
) )
@CommandPermissions("worldedit.region.hollow") @CommandPermissions("worldedit.region.hollow")
@Logging(REGION) @Logging(REGION)
public void hollow(Player player, EditSession editSession, public int hollow(Player player, EditSession editSession,
@Selection Region region, @Selection Region region,
@Optional("0") @Range(min = 0) int thickness, @Arg(desc = "Thickness of the shell to leave", def = "0")
@Optional("air") Pattern pattern) throws WorldEditException { int thickness,
@Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air")
Pattern pattern) throws WorldEditException {
checkArgument(thickness >= 0, "Thickness must be >= 0");
int affected = editSession.hollowOutRegion(region, thickness, pattern); int affected = editSession.hollowOutRegion(region, thickness, pattern);
player.print(affected + " block(s) have been changed."); player.print(affected + " block(s) have been changed.");
return affected;
} }
@Command( @Command(
aliases = { "/forest" }, name = "/forest",
usage = "[type] [density]", desc = "Make a forest within the region"
desc = "Make a forest within the region",
min = 0,
max = 2
) )
@CommandPermissions("worldedit.region.forest") @CommandPermissions("worldedit.region.forest")
@Logging(REGION) @Logging(REGION)
public void forest(Player player, EditSession editSession, @Selection Region region, @Optional("tree") TreeType type, public int forest(Player player, EditSession editSession, @Selection Region region,
@Optional("5") @Range(min = 0, max = 100) double density) throws WorldEditException { @Arg(desc = "The type of tree to place", def = "tree")
TreeType type,
@Arg(desc = "The density of the forest", def = "5")
double density) throws WorldEditException {
checkArgument(0 <= density && density <= 100, "Density must be in [0, 100]");
int affected = editSession.makeForest(region, density / 100, type); int affected = editSession.makeForest(region, density / 100, type);
player.print(affected + " trees created."); player.print(affected + " trees created.");
return affected;
} }
@Command( @Command(
aliases = { "/flora" }, name = "/flora",
usage = "[density]", desc = "Make flora within the region"
desc = "Make flora within the region",
min = 0,
max = 1
) )
@CommandPermissions("worldedit.region.flora") @CommandPermissions("worldedit.region.flora")
@Logging(REGION) @Logging(REGION)
public void flora(Player player, EditSession editSession, @Selection Region region, @Optional("10") @Range(min = 0, max = 100) double density) throws WorldEditException { public int flora(Player player, EditSession editSession, @Selection Region region,
@Arg(desc = "The density of the forest", def = "5")
double density) throws WorldEditException {
checkArgument(0 <= density && density <= 100, "Density must be in [0, 100]");
density = density / 100; density = density / 100;
FloraGenerator generator = new FloraGenerator(editSession); FloraGenerator generator = new FloraGenerator(editSession);
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator); GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
@ -465,7 +444,9 @@ public class RegionCommands {
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density)); visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
Operations.completeLegacy(visitor); Operations.completeLegacy(visitor);
player.print(ground.getAffected() + " flora created."); int affected = ground.getAffected();
player.print(affected + " flora created.");
return affected;
} }
} }

View File

@ -42,6 +42,8 @@ import com.sk89q.worldedit.command.HistoryCommands;
import com.sk89q.worldedit.command.HistoryCommandsRegistration; import com.sk89q.worldedit.command.HistoryCommandsRegistration;
import com.sk89q.worldedit.command.NavigationCommands; import com.sk89q.worldedit.command.NavigationCommands;
import com.sk89q.worldedit.command.NavigationCommandsRegistration; import com.sk89q.worldedit.command.NavigationCommandsRegistration;
import com.sk89q.worldedit.command.RegionCommands;
import com.sk89q.worldedit.command.RegionCommandsRegistration;
import com.sk89q.worldedit.command.SchematicCommands; import com.sk89q.worldedit.command.SchematicCommands;
import com.sk89q.worldedit.command.SchematicCommandsRegistration; import com.sk89q.worldedit.command.SchematicCommandsRegistration;
import com.sk89q.worldedit.command.argument.Arguments; import com.sk89q.worldedit.command.argument.Arguments;
@ -291,13 +293,17 @@ public final class PlatformCommandMananger {
NavigationCommandsRegistration.builder(), NavigationCommandsRegistration.builder(),
new NavigationCommands(worldEdit) new NavigationCommands(worldEdit)
); );
register(
commandManager,
RegionCommandsRegistration.builder(),
new RegionCommands()
);
// Unported commands are below. Delete once they're added to the main manager above. // Unported commands are below. Delete once they're added to the main manager above.
/* /*
dispatcher = new CommandGraph() dispatcher = new CommandGraph()
.builder(builder) .builder(builder)
.commands() .commands()
.registerMethods(new RegionCommands(worldEdit))
.registerMethods(new ScriptingCommands(worldEdit)) .registerMethods(new ScriptingCommands(worldEdit))
.registerMethods(new SelectionCommands(worldEdit)) .registerMethods(new SelectionCommands(worldEdit))
.registerMethods(new SnapshotUtilCommands(worldEdit)) .registerMethods(new SnapshotUtilCommands(worldEdit))

View File

@ -163,10 +163,8 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
} }
@ExceptionMatch @ExceptionMatch
public void convert(ConditionFailedException e) throws CommandException { public void convert(IllegalArgumentException e) throws CommandException {
if (e.getCondition() instanceof PermissionCondition) { throw new CommandException(e.getMessage(), e, null);
throw new CommandException("You are not permitted to do that. Are you in the right mode?", e, null);
}
} }
} }