Update new commands with suggestion and help support.

This commit is contained in:
Albert Pham
2015-10-27 13:51:45 -07:00
parent 935de4c93d
commit f4bb5272e1
32 changed files with 1150 additions and 215 deletions

View File

@ -17,29 +17,49 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.command.composition;
package com.sk89q.worldedit.command.argument;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
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.util.command.argument.CommandArgs;
import com.sk89q.worldedit.util.command.composition.CommandExecutor;
public class PointGeneratorCommand extends CommandExecutor<Function<EditContext, ? extends RegionFunction>> {
import java.util.List;
public class BooleanFlag implements CommandExecutor<Boolean> {
private final char flag;
private final String description;
public BooleanFlag(char flag, String description) {
this.flag = flag;
this.description = description;
}
@Override
public Function<EditContext, ? extends RegionFunction> call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
String type = args.next();
public Boolean call(CommandArgs args, CommandLocals locals) throws CommandException {
return args.containsFlag(flag);
}
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<String> 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 true;
}
}

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<Deform> {
public class DeformArg extends SimpleCommand<Deform> {
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<Deform> {
return deform;
}
@Override
public String getDescription() {
return "Deforms an area by applying a math expression";
}
@Override
protected boolean testPermission0(CommandLocals locals) {
return true;
}
}

View File

@ -17,27 +17,39 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<BaseItem> {
public class ItemArg extends SimpleCommand<BaseItem> {
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<BaseItem> {
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<BaseItem> {
}
}
@Override
public String getDescription() {
return "Match an item";
}
@Override
protected boolean testPermission0(CommandLocals locals) {
return true;
}
}

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<Function<EditContext, RegionFunction>> {
public class ItemUserArg extends SimpleCommand<Function<EditContext, RegionFunction>> {
private final ItemArg itemArg = addParameter(new ItemArg("item", "minecraft:dye:15"));
@Override
public Function<EditContext, RegionFunction> call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
BaseItem item = new ItemCommand().call(args, locals, parentCommands);
public Function<EditContext, RegionFunction> 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<EditContext, RegionFunction> {
private final BaseItem item;

View File

@ -0,0 +1,83 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<Number> {
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<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
String value = args.next();
return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.<String>emptyList();
}
@Override
public String getUsage() {
return "<" + name + ">";
}
@Override
public String getDescription() {
return description;
}
@Override
public boolean testPermission(CommandLocals locals) {
return true;
}
}

View File

@ -17,12 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<Pattern> {
public class PatternArg extends SimpleCommand<Pattern> {
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<Pattern> {
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<Pattern> {
}
}
@Override
public String getDescription() {
return "Choose a pattern";
}
@Override
public boolean testPermission0(CommandLocals locals) {
return true;
}
}

View File

@ -17,7 +17,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.command.composition;
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<Function<EditContext, ? extends RegionFunction>> {
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";
}
public class ForestCommand {
}

View File

@ -0,0 +1,78 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<RegionFactory> {
@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<String> 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;
}
}

View File

@ -17,19 +17,43 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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.function.factory.RegionReplace;
import com.sk89q.worldedit.util.command.CommandExecutor;
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 RegionReplaceCommand extends CommandExecutor<RegionReplace> {
import java.util.Collections;
import java.util.List;
public class RegionReplaceArg implements CommandExecutor<RegionReplace> {
@Override
public RegionReplace call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
public RegionReplace call(CommandArgs args, CommandLocals locals) throws CommandException {
return new RegionReplace();
}
@Override
public List<String> 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;
}
}

View File

@ -0,0 +1,78 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<String> {
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<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
String value = args.next();
return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.<String>emptyList();
}
@Override
public String getUsage() {
return "<" + name + ">";
}
@Override
public String getDescription() {
return description;
}
@Override
public boolean testPermission(CommandLocals locals) {
return true;
}
}

View File

@ -17,9 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<Function<EditContext, ForestGenerator>> {
public class TreeGeneratorArg implements CommandExecutor<Function<EditContext, ForestGenerator>> {
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<EditContext, ForestGenerator> 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<EditContext, ForestGenerator> 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<String> 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<EditContext, ForestGenerator> {
private final TreeType type;
@ -64,4 +104,5 @@ public class TreeGeneratorCommand extends CommandExecutor<Function<EditContext,
return "tree of type " + type;
}
}
}

View File

@ -17,24 +17,44 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<RegionApply> {
import java.util.Collections;
import java.util.List;
public class ApplyCommand extends ParameterCommand<RegionApply> {
private final PointGeneratorArg pointGeneratorArg = addParameter(new PointGeneratorArg());
@Override
public RegionApply call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
Function<EditContext, ? extends RegionFunction> function = new PointGeneratorCommand().call(args, locals, parentCommands);
public RegionApply call(CommandArgs args, CommandLocals locals) throws CommandException {
Function<EditContext, ? extends RegionFunction> function = pointGeneratorArg.call(args, locals);
return new RegionApply(function);
}
@Override
public List<String> 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;
}
}

View File

@ -1,48 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<RegionFactory> {
@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);
}
}
}

View File

@ -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<T> extends CommandExecutor<T> {
public class ReplaceBrushCommand<T> extends SimpleCommand<T> {
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<T> extends CommandExecutor<T> {
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;
}
}

View File

@ -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<Scatter> {
public class ScatterCommand extends SimpleCommand<Scatter> {
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<EditContext, ? extends RegionFunction> 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<EditContext, ? extends RegionFunction> 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;
}
}

View File

@ -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<Object> {
public class ShapedBrushCommand extends SimpleCommand<Object> {
private final CommandExecutor<? extends OperationFactory> delegate;
private final String permission;
private final RegionFactoryArg regionFactoryArg = addParameter(new RegionFactoryArg());
private final NumberArg radiusCommand = addParameter(new NumberArg("size", "The size of the brush", "5"));
public ShapedBrushCommand(CommandExecutor<? extends OperationFactory> delegate, String permission) {
checkNotNull(delegate, "delegate");
this.permission = permission;
this.delegate = delegate;
addParameter(delegate);
}
@Override
public Object call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
public Object call(CommandArgs args, CommandLocals locals) throws CommandException {
if (!testPermission(locals)) {
throw new CommandPermissionsException();
}
RegionFactory regionFactory = new RegionFactoryCommand().call(args, locals, parentCommands);
int radius = args.nextInt();
OperationFactory factory = delegate.call(args, locals, parentCommands);
args.requireAllConsumed();
RegionFactory regionFactory = regionFactoryArg.call(args, locals);
int radius = radiusCommand.call(args, locals).intValue();
OperationFactory factory = delegate.call(args, locals);
Player player = (Player) locals.get(Actor.class);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(player);
@ -87,22 +85,12 @@ public class ShapedBrushCommand extends CommandExecutor<Object> {
}
@Override
public Description getDescription() {
List<Parameter> parameters = Lists.newArrayList();
parameters.add(new SimpleParameter("radius"));
parameters.add(new SimpleParameter("shape"));
parameters.add(new SimpleParameter("...shapeArgs...").setOptional(true));
parameters.add(new SimpleParameter("...brushArgs...").setOptional(true));
SimpleDescription desc = new SimpleDescription();
desc.setDescription(delegate.getDescription().getDescription());
desc.setHelp(delegate.getDescription().getHelp());
desc.setPermissions(Lists.newArrayList(permission));
return desc;
public String getDescription() {
return delegate.getDescription();
}
@Override
public boolean testPermission(CommandLocals locals) {
public boolean testPermission0(CommandLocals locals) {
Actor sender = locals.get(Actor.class);
if (sender == null) {
throw new RuntimeException("Uh oh! No 'Actor' specified so that we can check permissions");