Navigation Menu

Skip to content

Commit

Permalink
Add /brush none and unbind aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal committed Sep 10, 2019
1 parent 0e9fee3 commit ba26d78
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Expand Up @@ -82,6 +82,15 @@ public BrushCommands(WorldEdit worldEdit) {
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" },
Expand Down
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -80,6 +81,12 @@ public static void register(CommandRegistrationHandler registration,
Set<org.enginehub.piston.Command> 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
Expand Down Expand Up @@ -115,6 +122,12 @@ private static String asNonGlobal(org.enginehub.piston.Command oldCommand,
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) {
Expand All @@ -123,12 +136,11 @@ public ToolCommands(WorldEdit we) {

@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(
Expand Down

0 comments on commit ba26d78

Please sign in to comment.