From ba26d788af7274a9abba5543226d5bcfd558ba2d Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Mon, 9 Sep 2019 18:13:57 -0700 Subject: [PATCH] Add `/brush none` and unbind aliases --- .../sk89q/worldedit/command/BrushCommands.java | 9 +++++++++ .../sk89q/worldedit/command/ToolCommands.java | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 9b8e35dae..e15159af6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -82,6 +82,15 @@ public class BrushCommands { this.worldEdit = worldEdit; } + @Command( + name = "none", + aliases = "unbind", + desc = "Unbind a bound brush from your current item" + ) + void none(Player player, LocalSession session) throws WorldEditException { + ToolCommands.setToolNone(player, session, "Brush"); + } + @Command( name = "sphere", aliases = { "s" }, diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java index f3ef732b4..29c05676c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java @@ -30,6 +30,7 @@ import com.sk89q.worldedit.command.tool.BlockReplacer; import com.sk89q.worldedit.command.tool.DistanceWand; import com.sk89q.worldedit.command.tool.FloatingTreeRemover; import com.sk89q.worldedit.command.tool.FloodFillTool; +import com.sk89q.worldedit.command.tool.InvalidToolBindException; import com.sk89q.worldedit.command.tool.LongRangeBuildTool; import com.sk89q.worldedit.command.tool.NavigationWand; import com.sk89q.worldedit.command.tool.QueryTool; @@ -80,6 +81,12 @@ public class ToolCommands { Set commands = collect.getAllCommands() .collect(Collectors.toSet()); for (org.enginehub.piston.Command command : commands) { + if (command.getAliases().contains("unbind")) { + // Don't register new /tool unbind alias + command = command.toBuilder().aliases( + Collections2.filter(command.getAliases(), alias -> !"unbind".equals(alias)) + ).build(); + } commandManager.register(CommandUtil.deprecate( command, "Using global tool names is deprecated " + "and will be removed in WorldEdit 8", ToolCommands::asNonGlobal @@ -115,6 +122,12 @@ public class ToolCommands { return "/tool " + name; } + static void setToolNone(Player player, LocalSession session, String type) + throws InvalidToolBindException { + session.setTool(player.getItemInHand(HandSide.MAIN_HAND).getType(), null); + player.print(type + " unbound from your current item."); + } + private final WorldEdit we; public ToolCommands(WorldEdit we) { @@ -123,12 +136,11 @@ public class ToolCommands { @Command( name = "none", + aliases = "unbind", desc = "Unbind a bound tool from your current item" ) public void none(Player player, LocalSession session) throws WorldEditException { - - session.setTool(player.getItemInHand(HandSide.MAIN_HAND).getType(), null); - player.print("Tool unbound from your current item."); + setToolNone(player, session, "Tool"); } @Command(