From cba32732a3eaad40d6c73e3d8559e298ca5b946b Mon Sep 17 00:00:00 2001 From: Albert Pham Date: Wed, 28 Oct 2015 13:50:07 -0700 Subject: [PATCH] Add /br raise and /br lower as shortcuts for /br deform. --- .../extension/platform/CommandManager.java | 19 +++-- .../worldedit/function/factory/Deform.java | 8 +++ .../composition/LegacyCommandAdapter.java | 7 +- .../command/composition/ProvidedValue.java | 69 +++++++++++++++++++ 4 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/ProvidedValue.java diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java index 75f64cba9..0218b4b76 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java @@ -48,13 +48,15 @@ import com.sk89q.worldedit.command.ToolUtilCommands; import com.sk89q.worldedit.command.UtilityCommands; import com.sk89q.worldedit.command.WorldEditCommands; import com.sk89q.worldedit.command.argument.DeformArg; -import com.sk89q.worldedit.command.composition.ReplaceBrushCommand; import com.sk89q.worldedit.command.argument.RegionReplaceArg; +import com.sk89q.worldedit.command.composition.ApplyCommand; +import com.sk89q.worldedit.command.composition.ReplaceBrushCommand; import com.sk89q.worldedit.command.composition.ScatterCommand; import com.sk89q.worldedit.command.composition.ShapedBrushCommand; -import com.sk89q.worldedit.command.composition.ApplyCommand; import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.event.platform.CommandSuggestionEvent; +import com.sk89q.worldedit.function.factory.Deform; +import com.sk89q.worldedit.function.factory.Deform.Mode; import com.sk89q.worldedit.function.factory.OperationFactory; import com.sk89q.worldedit.internal.command.ActorAuthorizer; import com.sk89q.worldedit.internal.command.CommandLoggingHandler; @@ -64,7 +66,7 @@ import com.sk89q.worldedit.internal.command.WorldEditExceptionConverter; import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.util.command.InvalidUsageException; -import com.sk89q.worldedit.util.command.composition.LegacyCommandAdapter; +import com.sk89q.worldedit.util.command.composition.ProvidedValue; import com.sk89q.worldedit.util.command.fluent.CommandGraph; import com.sk89q.worldedit.util.command.parametric.ExceptionConverter; import com.sk89q.worldedit.util.command.parametric.LegacyCommandsHandler; @@ -83,6 +85,7 @@ import java.util.logging.Logger; import java.util.regex.Pattern; import static com.google.common.base.Preconditions.checkNotNull; +import static com.sk89q.worldedit.util.command.composition.LegacyCommandAdapter.adapt; /** * Handles the registration and invocation of commands. @@ -162,10 +165,12 @@ public final class CommandManager { .group("brush", "br") .describeAs("Brushing commands") .registerMethods(new BrushCommands(worldEdit)) - .register(new LegacyCommandAdapter(new ShapedBrushCommand(new DeformArg(), "worldedit.brush.deform")), "deform") - .register(new LegacyCommandAdapter(new ShapedBrushCommand(new ReplaceBrushCommand(new RegionReplaceArg()), "worldedit.brush.set")), "set") - .register(new LegacyCommandAdapter(new ShapedBrushCommand(new ScatterCommand(), "worldedit.brush.scatter")), "scatter") - .register(new LegacyCommandAdapter(new ShapedBrushCommand(new ApplyCommand(), "worldedit.brush.apply")), "apply") + .register(adapt(new ShapedBrushCommand(new DeformArg(), "worldedit.brush.deform")), "deform") + .register(adapt(new ShapedBrushCommand(ProvidedValue.create(new Deform("y-=1", Mode.RAW_COORD), "Raise one block"), "worldedit.brush.raise")), "raise") + .register(adapt(new ShapedBrushCommand(ProvidedValue.create(new Deform("y+=1", Mode.RAW_COORD), "Lower one block"), "worldedit.brush.lower")), "lower") + .register(adapt(new ShapedBrushCommand(new ReplaceBrushCommand(new RegionReplaceArg()), "worldedit.brush.set")), "set") + .register(adapt(new ShapedBrushCommand(new ScatterCommand(), "worldedit.brush.scatter")), "scatter") + .register(adapt(new ShapedBrushCommand(new ApplyCommand(), "worldedit.brush.apply")), "apply") .parent() .group("superpickaxe", "pickaxe", "sp") .describeAs("Super-pickaxe commands") diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java index db9a4694b..f1c35c318 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.function.factory; +import com.google.common.base.Preconditions; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; @@ -42,6 +43,13 @@ public class Deform implements OperationFactory { this.expression = expression; } + public Deform(String expression, Mode mode) { + checkNotNull(expression, "expression"); + checkNotNull(mode, "mode"); + this.expression = expression; + this.mode = mode; + } + public String getExpression() { return expression; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/LegacyCommandAdapter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/LegacyCommandAdapter.java index 79c569a71..f3470b67b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/LegacyCommandAdapter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/LegacyCommandAdapter.java @@ -35,7 +35,7 @@ public class LegacyCommandAdapter implements CommandCallable { private final CommandExecutor executor; - public LegacyCommandAdapter(CommandExecutor executor) { + private LegacyCommandAdapter(CommandExecutor executor) { this.executor = executor; } @@ -79,4 +79,9 @@ public class LegacyCommandAdapter implements CommandCallable { return Lists.newArrayList(); } } + + public static LegacyCommandAdapter adapt(CommandExecutor executor) { + return new LegacyCommandAdapter(executor); + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/ProvidedValue.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/ProvidedValue.java new file mode 100644 index 000000000..7620bc7c3 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/ProvidedValue.java @@ -0,0 +1,69 @@ +/* + * 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.util.command.composition; + +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 java.util.Collections; +import java.util.List; + +public class ProvidedValue implements CommandExecutor { + + private final T value; + private final String description; + + private ProvidedValue(T value, String description) { + this.value = value; + this.description = description; + } + + @Override + public T call(CommandArgs args, CommandLocals locals) throws CommandException { + return value; + } + + @Override + public List getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException { + return Collections.emptyList(); + } + + @Override + public String getUsage() { + return ""; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public boolean testPermission(CommandLocals locals) { + return true; + } + + public static ProvidedValue create(T value, String description) { + return new ProvidedValue(value, description); + } + +}