diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml
index 6d581e702..7a5600470 100644
--- a/config/checkstyle/import-control.xml
+++ b/config/checkstyle/import-control.xml
@@ -51,8 +51,9 @@
+
-
\ No newline at end of file
+
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/CommandExecutor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/BooleanFlag.java
similarity index 60%
rename from worldedit-core/src/main/java/com/sk89q/worldedit/util/command/CommandExecutor.java
rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/BooleanFlag.java
index f943a15b0..be96c0210 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/CommandExecutor.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/BooleanFlag.java
@@ -17,40 +17,49 @@
* along with this program. If not, see .
*/
-package com.sk89q.worldedit.util.command;
+package com.sk89q.worldedit.command.argument;
import com.google.common.collect.Lists;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
+import com.sk89q.worldedit.util.command.composition.CommandExecutor;
import java.util.List;
-public abstract class CommandExecutor implements CommandCallable {
+public class BooleanFlag implements CommandExecutor {
- @Override
- public final T call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException {
- CommandArgs args = new CommandArgs.Parser().parse(arguments);
- T ret = call(args, locals, parentCommands);
- args.requireAllConsumed();
- return ret;
+ private final char flag;
+ private final String description;
+
+ public BooleanFlag(char flag, String description) {
+ this.flag = flag;
+ this.description = description;
}
- public abstract T call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException;
+ @Override
+ public Boolean call(CommandArgs args, CommandLocals locals) throws CommandException {
+ return args.containsFlag(flag);
+ }
@Override
- public Description getDescription() {
- return new SimpleDescription();
+ public List getSuggestions(CommandArgs args, CommandLocals locals) {
+ return Lists.newArrayList("-" + flag);
+ }
+
+ @Override
+ public String getUsage() {
+ return "[-" + flag + "]";
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
}
@Override
public boolean testPermission(CommandLocals locals) {
- return false;
- }
-
- @Override
- public List getSuggestions(String arguments, CommandLocals locals) throws CommandException {
- return Lists.newArrayList();
+ return true;
}
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/DeformCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/DeformArg.java
similarity index 68%
rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/DeformCommand.java
rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/DeformArg.java
index daa6d7417..6c684f908 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/DeformCommand.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/DeformArg.java
@@ -17,7 +17,7 @@
* along with this program. If not, see .
*/
-package com.sk89q.worldedit.command.composition;
+package com.sk89q.worldedit.command.argument;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
@@ -29,16 +29,20 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.factory.Deform;
import com.sk89q.worldedit.function.factory.Deform.Mode;
-import com.sk89q.worldedit.util.command.CommandExecutor;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
+import com.sk89q.worldedit.util.command.composition.SimpleCommand;
-public class DeformCommand extends CommandExecutor {
+public class DeformArg extends SimpleCommand {
+
+ private final BooleanFlag rawCoordsFlag = addParameter(new BooleanFlag('r', "Raw coords mode"));
+ private final BooleanFlag offsetFlag = addParameter(new BooleanFlag('o', "Offset mode"));
+ private final StringArg expressionParser = addParameter(new StringArg("expression", "Expression to apply"));
@Override
- public Deform call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
- String expression = args.next();
- boolean rawCoords = args.containsFlag('r');
- boolean offset = args.containsFlag('o');
+ public Deform call(CommandArgs args, CommandLocals locals) throws CommandException {
+ String expression = expressionParser.call(args, locals);
+ boolean rawCoords = rawCoordsFlag.call(args, locals);
+ boolean offset = offsetFlag.call(args, locals);
Deform deform = new Deform(expression);
@@ -60,4 +64,14 @@ public class DeformCommand extends CommandExecutor {
return deform;
}
+ @Override
+ public String getDescription() {
+ return "Deforms an area by applying a math expression";
+ }
+
+ @Override
+ protected boolean testPermission0(CommandLocals locals) {
+ return true;
+ }
+
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ItemCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemArg.java
similarity index 72%
rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ItemCommand.java
rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemArg.java
index 4335ec94f..e6eb8d1ed 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ItemCommand.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemArg.java
@@ -17,27 +17,39 @@
* along with this program. If not, see .
*/
-package com.sk89q.worldedit.command.composition;
+package com.sk89q.worldedit.command.argument;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem;
+import com.sk89q.worldedit.util.command.composition.SimpleCommand;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;
-import com.sk89q.worldedit.util.command.CommandExecutor;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
import com.sk89q.worldedit.world.World;
-public class ItemCommand extends CommandExecutor {
+public class ItemArg extends SimpleCommand {
+
+ private final StringArg stringArg;
+
+ public ItemArg(String name) {
+ stringArg = addParameter(new StringArg(name, "The item name", null));
+ }
+
+ public ItemArg(String name, String defaultSuggestion) {
+ stringArg = addParameter(new StringArg(name, "The item name", defaultSuggestion));
+ }
@Override
- public BaseItem call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
+ public BaseItem call(CommandArgs args, CommandLocals locals) throws CommandException {
+ String itemString = stringArg.call(args, locals);
+
Actor actor = locals.get(Actor.class);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
@@ -52,7 +64,7 @@ public class ItemCommand extends CommandExecutor {
parserContext.setSession(session);
try {
- return WorldEdit.getInstance().getItemFactory().parseFromInput(args.next(), parserContext);
+ return WorldEdit.getInstance().getItemFactory().parseFromInput(itemString, parserContext);
} catch (NoMatchException e) {
throw new CommandException(e.getMessage(), e);
} catch (InputParseException e) {
@@ -60,4 +72,14 @@ public class ItemCommand extends CommandExecutor {
}
}
+ @Override
+ public String getDescription() {
+ return "Match an item";
+ }
+
+ @Override
+ protected boolean testPermission0(CommandLocals locals) {
+ return true;
+ }
+
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ItemUseCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUserArg.java
similarity index 81%
rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ItemUseCommand.java
rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUserArg.java
index 1c0558bb1..252838b91 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ItemUseCommand.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUserArg.java
@@ -17,7 +17,7 @@
* along with this program. If not, see .
*/
-package com.sk89q.worldedit.command.composition;
+package com.sk89q.worldedit.command.argument;
import com.google.common.base.Function;
import com.sk89q.minecraft.util.commands.CommandException;
@@ -29,20 +29,32 @@ import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.function.EditContext;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.util.Direction;
-import com.sk89q.worldedit.util.command.CommandExecutor;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
+import com.sk89q.worldedit.util.command.composition.SimpleCommand;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
-public class ItemUseCommand extends CommandExecutor> {
+public class ItemUserArg extends SimpleCommand> {
+
+ private final ItemArg itemArg = addParameter(new ItemArg("item", "minecraft:dye:15"));
@Override
- public Function call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
- BaseItem item = new ItemCommand().call(args, locals, parentCommands);
+ public Function call(CommandArgs args, CommandLocals locals) throws CommandException {
+ BaseItem item = itemArg.call(args, locals);
return new ItemUseFactory(item);
}
+ @Override
+ public String getDescription() {
+ return "Applies an item";
+ }
+
+ @Override
+ protected boolean testPermission0(CommandLocals locals) {
+ return true;
+ }
+
private static final class ItemUseFactory implements Function {
private final BaseItem item;
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberArg.java
new file mode 100644
index 000000000..54ccb7bc5
--- /dev/null
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberArg.java
@@ -0,0 +1,83 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q
+ * Copyright (C) WorldEdit team and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.worldedit.command.argument;
+
+import com.google.common.collect.Lists;
+import com.sk89q.minecraft.util.commands.CommandException;
+import com.sk89q.minecraft.util.commands.CommandLocals;
+import com.sk89q.worldedit.util.command.argument.CommandArgs;
+import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
+import com.sk89q.worldedit.util.command.composition.CommandExecutor;
+
+import java.util.Collections;
+import java.util.List;
+
+public class NumberArg implements CommandExecutor {
+
+ private final String name;
+ private final String description;
+ private final String defaultSuggestion;
+
+ public NumberArg(String name, String description) {
+ this(name, description, null);
+ }
+
+ public NumberArg(String name, String description, String defaultSuggestion) {
+ this.name = name;
+ this.description = description;
+ this.defaultSuggestion = defaultSuggestion;
+ }
+
+ @Override
+ public Number call(CommandArgs args, CommandLocals locals) throws CommandException {
+ try {
+ String next = args.next();
+ try {
+ return Double.parseDouble(next);
+ } catch (NumberFormatException ignored) {
+ throw new CommandException("The value for <" + name + "> should be a number. '" + next + "' is not a number.");
+ }
+ } catch (MissingArgumentException e) {
+ throw new CommandException("Missing value for <" + name + "> (try a number).");
+ }
+ }
+
+ @Override
+ public List getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
+ String value = args.next();
+ return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.emptyList();
+ }
+
+ @Override
+ public String getUsage() {
+ return "<" + name + ">";
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public boolean testPermission(CommandLocals locals) {
+ return true;
+ }
+
+}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/PatternCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternArg.java
similarity index 76%
rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/PatternCommand.java
rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternArg.java
index 258dd5f09..ac4f57d79 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/PatternCommand.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternArg.java
@@ -17,12 +17,13 @@
* along with this program. If not, see .
*/
-package com.sk89q.worldedit.command.composition;
+package com.sk89q.worldedit.command.argument;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
+import com.sk89q.worldedit.util.command.composition.SimpleCommand;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;
@@ -30,14 +31,21 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.Pattern;
-import com.sk89q.worldedit.util.command.CommandExecutor;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
import com.sk89q.worldedit.world.World;
-public class PatternCommand extends CommandExecutor {
+public class PatternArg extends SimpleCommand {
+
+ private final StringArg stringArg;
+
+ public PatternArg(String name) {
+ stringArg = addParameter(new StringArg(name, "The pattern"));
+ }
@Override
- public Pattern call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
+ public Pattern call(CommandArgs args, CommandLocals locals) throws CommandException {
+ String patternString = stringArg.call(args, locals);
+
Actor actor = locals.get(Actor.class);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
@@ -52,7 +60,7 @@ public class PatternCommand extends CommandExecutor {
parserContext.setSession(session);
try {
- return WorldEdit.getInstance().getPatternFactory().parseFromInput(args.next(), parserContext);
+ return WorldEdit.getInstance().getPatternFactory().parseFromInput(patternString, parserContext);
} catch (NoMatchException e) {
throw new CommandException(e.getMessage(), e);
} catch (InputParseException e) {
@@ -60,4 +68,14 @@ public class PatternCommand extends CommandExecutor {
}
}
+ @Override
+ public String getDescription() {
+ return "Choose a pattern";
+ }
+
+ @Override
+ public boolean testPermission0(CommandLocals locals) {
+ return true;
+ }
+
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PointGeneratorArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PointGeneratorArg.java
new file mode 100644
index 000000000..f7057595b
--- /dev/null
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PointGeneratorArg.java
@@ -0,0 +1,40 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q
+ * Copyright (C) WorldEdit team and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.worldedit.command.argument;
+
+import com.google.common.base.Function;
+import com.sk89q.worldedit.function.EditContext;
+import com.sk89q.worldedit.function.RegionFunction;
+import com.sk89q.worldedit.util.command.composition.BranchingCommand;
+
+public class PointGeneratorArg extends BranchingCommand> {
+
+ public PointGeneratorArg() {
+ super("generatorType");
+ putOption(new TreeGeneratorArg("treeType"), "tree", "forest");
+ putOption(new ItemUserArg(), "item", "itemstack", "use");
+ }
+
+ @Override
+ public String getDescription() {
+ return "Choose a point generator function";
+ }
+
+}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryArg.java
new file mode 100644
index 000000000..3b73142cf
--- /dev/null
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryArg.java
@@ -0,0 +1,78 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q
+ * Copyright (C) WorldEdit team and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.worldedit.command.argument;
+
+import com.google.common.collect.Lists;
+import com.sk89q.minecraft.util.commands.CommandException;
+import com.sk89q.minecraft.util.commands.CommandLocals;
+import com.sk89q.worldedit.regions.factory.CuboidRegionFactory;
+import com.sk89q.worldedit.regions.factory.CylinderRegionFactory;
+import com.sk89q.worldedit.regions.factory.RegionFactory;
+import com.sk89q.worldedit.regions.factory.SphereRegionFactory;
+import com.sk89q.worldedit.util.command.argument.ArgumentUtils;
+import com.sk89q.worldedit.util.command.argument.CommandArgs;
+import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
+import com.sk89q.worldedit.util.command.composition.CommandExecutor;
+
+import java.util.List;
+
+public class RegionFactoryArg implements CommandExecutor {
+
+ @Override
+ public RegionFactory call(CommandArgs args, CommandLocals locals) throws CommandException {
+ try {
+ String type = args.next();
+
+ if (type.equals("cuboid")) {
+ return new CuboidRegionFactory();
+ } else if (type.equals("sphere")) {
+ return new SphereRegionFactory();
+ } else if (type.equals("cyl") || type.equals("cylinder")) {
+ return new CylinderRegionFactory(1); // TODO: Adjustable height
+ } else {
+ throw new CommandException("Unknown shape type: " + type + " (try one of " + getUsage() + ")");
+ }
+ } catch (MissingArgumentException e) {
+ throw new CommandException("Missing shape type (try one of " + getUsage() + ")");
+
+ }
+ }
+
+ @Override
+ public List getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
+ return ArgumentUtils.getMatchingSuggestions(Lists.newArrayList("cuboid", "sphere", "cyl"), args.next());
+ }
+
+ @Override
+ public String getUsage() {
+ return "(cuboid | sphere | cyl)";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Defines a region";
+ }
+
+ @Override
+ public boolean testPermission(CommandLocals locals) {
+ return true;
+ }
+
+}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/PointGeneratorCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionReplaceArg.java
similarity index 51%
rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/PointGeneratorCommand.java
rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionReplaceArg.java
index d618db25d..793e0d8ba 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/PointGeneratorCommand.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionReplaceArg.java
@@ -17,29 +17,43 @@
* along with this program. If not, see .
*/
-package com.sk89q.worldedit.command.composition;
+package com.sk89q.worldedit.command.argument;
-import com.google.common.base.Function;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
-import com.sk89q.worldedit.function.EditContext;
-import com.sk89q.worldedit.function.RegionFunction;
-import com.sk89q.worldedit.util.command.CommandExecutor;
+import com.sk89q.worldedit.function.factory.RegionReplace;
+import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
+import com.sk89q.worldedit.util.command.composition.CommandExecutor;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
-public class PointGeneratorCommand extends CommandExecutor> {
+import java.util.Collections;
+import java.util.List;
+
+public class RegionReplaceArg implements CommandExecutor {
@Override
- public Function call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
- String type = args.next();
+ public RegionReplace call(CommandArgs args, CommandLocals locals) throws CommandException {
+ return new RegionReplace();
+ }
- if (type.equalsIgnoreCase("forest") || type.equalsIgnoreCase("tree")) {
- return new TreeGeneratorCommand().call(args, locals, parentCommands);
- } else if (type.equalsIgnoreCase("item") || type.equalsIgnoreCase("itemstack")) {
- return new ItemUseCommand().call(args, locals, parentCommands);
- } else {
- throw new CommandException("Unknown type of generator: " + type);
- }
+ @Override
+ public List getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String getUsage() {
+ return "";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Replaces a region";
+ }
+
+ @Override
+ public boolean testPermission(CommandLocals locals) {
+ return true;
}
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringArg.java
new file mode 100644
index 000000000..5f76f5bb2
--- /dev/null
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringArg.java
@@ -0,0 +1,78 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q
+ * Copyright (C) WorldEdit team and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.worldedit.command.argument;
+
+import com.google.common.collect.Lists;
+import com.sk89q.minecraft.util.commands.CommandException;
+import com.sk89q.minecraft.util.commands.CommandLocals;
+import com.sk89q.worldedit.util.command.argument.CommandArgs;
+import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
+import com.sk89q.worldedit.util.command.composition.CommandExecutor;
+
+import java.util.Collections;
+import java.util.List;
+
+public class StringArg implements CommandExecutor {
+
+ private final String name;
+ private final String description;
+ private final String defaultSuggestion;
+
+ public StringArg(String name, String description) {
+ this(name, description, null);
+ }
+
+ public StringArg(String name, String description, String defaultSuggestion) {
+ this.name = name;
+ this.description = description;
+ this.defaultSuggestion = defaultSuggestion;
+ }
+
+ @Override
+ public String call(CommandArgs args, CommandLocals locals) throws CommandException {
+ try {
+ return args.next();
+ } catch (MissingArgumentException e) {
+ throw new CommandException("Missing value for <" + name + ">.");
+ }
+ }
+
+ @Override
+ public List getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
+ String value = args.next();
+ return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.emptyList();
+ }
+
+ @Override
+ public String getUsage() {
+ return "<" + name + ">";
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public boolean testPermission(CommandLocals locals) {
+ return true;
+ }
+
+}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/TreeGeneratorCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/TreeGeneratorArg.java
similarity index 52%
rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/TreeGeneratorCommand.java
rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/TreeGeneratorArg.java
index e8e740076..091364d0a 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/TreeGeneratorCommand.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/TreeGeneratorArg.java
@@ -17,9 +17,11 @@
* along with this program. If not, see .
*/
-package com.sk89q.worldedit.command.composition;
+package com.sk89q.worldedit.command.argument;
import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.collect.Lists;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.worldedit.EditSession;
@@ -27,25 +29,63 @@ import com.sk89q.worldedit.function.EditContext;
import com.sk89q.worldedit.function.generator.ForestGenerator;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
-import com.sk89q.worldedit.util.command.CommandExecutor;
+import com.sk89q.worldedit.util.command.argument.ArgumentUtils;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
+import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
+import com.sk89q.worldedit.util.command.composition.CommandExecutor;
import javax.annotation.Nullable;
import java.util.Arrays;
+import java.util.List;
-public class TreeGeneratorCommand extends CommandExecutor> {
+public class TreeGeneratorArg implements CommandExecutor> {
+
+ private final String name;
+
+ public TreeGeneratorArg(String name) {
+ this.name = name;
+ }
+
+ private String getOptionsList() {
+ return Joiner.on(" | ").join(Arrays.asList(TreeType.values()));
+ }
@Override
- public Function call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
- String input = args.next();
- TreeType type = TreeGenerator.lookup(input);
- if (type != null) {
- return new GeneratorFactory(type);
- } else {
- throw new CommandException(String.format("Can't recognize tree type '%s' -- choose from: %s", input, Arrays.toString(TreeType.values())));
+ public Function call(CommandArgs args, CommandLocals locals) throws CommandException {
+ try {
+ String input = args.next();
+ TreeType type = TreeGenerator.lookup(input);
+ if (type != null) {
+ return new GeneratorFactory(type);
+ } else {
+ throw new CommandException("Unknown value for <" + name + "> (try one of " + getOptionsList() + ").");
+ }
+ } catch (MissingArgumentException e) {
+ throw new CommandException("Missing value for <" + name + "> (try one of " + getOptionsList() + ").");
}
}
+ @Override
+ public List getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
+ String s = args.next();
+ return s.isEmpty() ? Lists.newArrayList(TreeType.getPrimaryAliases()) : ArgumentUtils.getMatchingSuggestions(TreeType.getAliases(), s);
+ }
+
+ @Override
+ public String getUsage() {
+ return "<" + name + ">";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Choose a tree generator";
+ }
+
+ @Override
+ public boolean testPermission(CommandLocals locals) {
+ return true;
+ }
+
private static class GeneratorFactory implements Function {
private final TreeType type;
@@ -64,4 +104,5 @@ public class TreeGeneratorCommand extends CommandExecutor.
*/
-package com.sk89q.worldedit.command.tool.brush;
+package com.sk89q.worldedit.command.composition;
import com.google.common.base.Function;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
-import com.sk89q.worldedit.command.composition.PointGeneratorCommand;
+import com.sk89q.worldedit.command.argument.PointGeneratorArg;
import com.sk89q.worldedit.function.EditContext;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.factory.RegionApply;
-import com.sk89q.worldedit.util.command.CommandExecutor;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
+import com.sk89q.worldedit.util.command.composition.ParameterCommand;
-public class ApplyCommand extends CommandExecutor {
+import java.util.Collections;
+import java.util.List;
+
+public class ApplyCommand extends ParameterCommand {
+
+ private final PointGeneratorArg pointGeneratorArg = addParameter(new PointGeneratorArg());
@Override
- public RegionApply call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
- Function function = new PointGeneratorCommand().call(args, locals, parentCommands);
+ public RegionApply call(CommandArgs args, CommandLocals locals) throws CommandException {
+ Function function = pointGeneratorArg.call(args, locals);
return new RegionApply(function);
}
+ @Override
+ public List getSuggestions(CommandArgs args, CommandLocals locals) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String getDescription() {
+ return "Applies a point generator to an area";
+ }
+
+ @Override
+ protected boolean testPermission0(CommandLocals locals) {
+ return true;
+ }
+
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/RegionFactoryCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/RegionFactoryCommand.java
deleted file mode 100644
index 4b152d14e..000000000
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/RegionFactoryCommand.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * Copyright (C) WorldEdit team and contributors
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.sk89q.worldedit.command.composition;
-
-import com.sk89q.minecraft.util.commands.CommandException;
-import com.sk89q.minecraft.util.commands.CommandLocals;
-import com.sk89q.worldedit.regions.factory.CuboidRegionFactory;
-import com.sk89q.worldedit.regions.factory.CylinderRegionFactory;
-import com.sk89q.worldedit.regions.factory.RegionFactory;
-import com.sk89q.worldedit.regions.factory.SphereRegionFactory;
-import com.sk89q.worldedit.util.command.CommandExecutor;
-import com.sk89q.worldedit.util.command.argument.CommandArgs;
-
-public class RegionFactoryCommand extends CommandExecutor {
-
- @Override
- public RegionFactory call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
- String type = args.next();
-
- if (type.equals("cuboid")) {
- return new CuboidRegionFactory();
- } else if (type.equals("sphere")) {
- return new SphereRegionFactory();
- } else if (type.equals("cyl") || type.equals("cylinder")) {
- return new CylinderRegionFactory(1); // TODO: Adjustable height
- } else {
- throw new CommandException("Unknown shape type: " + type);
- }
- }
-
-}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/FillBrushCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ReplaceBrushCommand.java
similarity index 70%
rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/FillBrushCommand.java
rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ReplaceBrushCommand.java
index 276d7d30f..7a583da0a 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/FillBrushCommand.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ReplaceBrushCommand.java
@@ -23,28 +23,31 @@ import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
+import com.sk89q.worldedit.command.argument.PatternArg;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.pattern.Pattern;
-import com.sk89q.worldedit.util.command.CommandExecutor;
+import com.sk89q.worldedit.util.command.composition.CommandExecutor;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
+import com.sk89q.worldedit.util.command.composition.SimpleCommand;
import static com.google.common.base.Preconditions.checkNotNull;
-public class FillBrushCommand extends CommandExecutor {
+public class ReplaceBrushCommand extends SimpleCommand {
+ private final PatternArg patternArg = addParameter(new PatternArg("fillPattern"));
private final CommandExecutor extends T> delegate;
- public FillBrushCommand(CommandExecutor extends T> delegate) {
+ public ReplaceBrushCommand(CommandExecutor extends T> delegate) {
checkNotNull(delegate, "delegate");
- this.delegate = delegate;
+ this.delegate = addParameter(delegate);
}
@Override
- public T call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
- Pattern pattern = new PatternCommand().call(args, locals, parentCommands);
+ public T call(CommandArgs args, CommandLocals locals) throws CommandException {
+ Pattern pattern = patternArg.call(args, locals);
Player player = (Player) locals.get(Actor.class);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(player);
@@ -56,6 +59,17 @@ public class FillBrushCommand extends CommandExecutor {
WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter().convert(e);
}
- return delegate.call(args, locals, parentCommands);
+ return delegate.call(args, locals);
}
+
+ @Override
+ public String getDescription() {
+ return "Replaces an area with a pattern";
+ }
+
+ @Override
+ protected boolean testPermission0(CommandLocals locals) {
+ return true;
+ }
+
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ScatterCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ScatterCommand.java
index 8dbc86483..a5667fe07 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ScatterCommand.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ScatterCommand.java
@@ -22,19 +22,34 @@ package com.sk89q.worldedit.command.composition;
import com.google.common.base.Function;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
+import com.sk89q.worldedit.command.argument.NumberArg;
+import com.sk89q.worldedit.command.argument.PointGeneratorArg;
import com.sk89q.worldedit.function.EditContext;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.factory.Scatter;
-import com.sk89q.worldedit.util.command.CommandExecutor;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
+import com.sk89q.worldedit.util.command.composition.SimpleCommand;
-public class ScatterCommand extends CommandExecutor {
+public class ScatterCommand extends SimpleCommand {
+
+ private final NumberArg densityCommand = addParameter(new NumberArg("density", "0-100", "20"));
+ private final PointGeneratorArg pointGeneratorArg = addParameter(new PointGeneratorArg());
@Override
- public Scatter call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
- double density = args.nextDouble() / 100.0;
- Function function = new PointGeneratorCommand().call(args, locals, parentCommands);
+ public Scatter call(CommandArgs args, CommandLocals locals) throws CommandException {
+ double density = densityCommand.call(args, locals).doubleValue() / 100.0;
+ Function function = pointGeneratorArg.call(args, locals);
return new Scatter(function, density);
}
+ @Override
+ public String getDescription() {
+ return "Scatters a function over an area";
+ }
+
+ @Override
+ protected boolean testPermission0(CommandLocals locals) {
+ return true;
+ }
+
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java
index 62bb338bf..f99e4e543 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java
@@ -19,13 +19,14 @@
package com.sk89q.worldedit.command.composition;
-import com.google.common.collect.Lists;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxBrushRadiusException;
import com.sk89q.worldedit.WorldEdit;
+import com.sk89q.worldedit.command.argument.NumberArg;
+import com.sk89q.worldedit.command.argument.RegionFactoryArg;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
import com.sk89q.worldedit.command.tool.brush.OperationFactoryBrush;
@@ -33,39 +34,36 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.factory.OperationFactory;
import com.sk89q.worldedit.regions.factory.RegionFactory;
-import com.sk89q.worldedit.util.command.CommandExecutor;
-import com.sk89q.worldedit.util.command.Description;
-import com.sk89q.worldedit.util.command.Parameter;
-import com.sk89q.worldedit.util.command.SimpleDescription;
-import com.sk89q.worldedit.util.command.SimpleParameter;
+import com.sk89q.worldedit.util.command.composition.CommandExecutor;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
-
-import java.util.List;
+import com.sk89q.worldedit.util.command.composition.SimpleCommand;
import static com.google.common.base.Preconditions.checkNotNull;
-public class ShapedBrushCommand extends CommandExecutor