Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package com.sk89q.worldedit.command;

import com.google.common.collect.Collections2;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
Expand All @@ -45,7 +44,6 @@
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
import com.sk89q.worldedit.internal.command.CommandUtil;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
Expand All @@ -57,14 +55,11 @@
import com.sk89q.worldedit.world.item.ItemType;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.CommandManagerService;
import org.enginehub.piston.CommandMetadata;
import org.enginehub.piston.CommandParameters;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.part.SubCommandPart;

import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -88,58 +83,21 @@ public static void register(CommandRegistrationHandler registration,
new ToolCommands(worldEdit)
);

// Register deprecated global commands
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 <whatever> alias
command = command.toBuilder().aliases(
Collections2.filter(command.getAliases(), alias -> !"unbind".equals(alias))
).build();
}
if (command.getName().equals("stacker")) {
// Don't register /stacker
continue;
}
commandManager.register(CommandUtil.deprecate(
command, "Global tool names cause conflicts "
+ "and will be removed in WorldEdit 8",
CommandUtil.ReplacementMessageGenerator.forNewCommand(ToolCommands::asNonGlobal)
));
}

// Remove aliases with / in them, since it doesn't make sense for sub-commands.
Set<org.enginehub.piston.Command> nonGlobalCommands = commands.stream()
.map(command ->
command.toBuilder().aliases(
Collections2.filter(command.getAliases(), alias -> !alias.startsWith("/"))
).build()
)
.collect(Collectors.toSet());
Set<org.enginehub.piston.Command> commands = collect.getAllCommands().collect(Collectors.toSet());
commandManager.register("tool", command -> {
command.addPart(SubCommandPart.builder(
TranslatableComponent.of("tool"),
TextComponent.of("The tool to bind")
)
.withCommands(nonGlobalCommands)
.withCommands(commands)
.required()
.build());
command.description(TextComponent.of("Binds a tool to the item in your hand"));

command.condition(new SubCommandPermissionCondition.Generator(nonGlobalCommands).build());
command.condition(new SubCommandPermissionCondition.Generator(commands).build());
});
}

private static String asNonGlobal(org.enginehub.piston.Command oldCommand,
CommandParameters oldParameters) {
String name = Optional.ofNullable(oldParameters.getMetadata())
.map(CommandMetadata::getCalledName)
.filter(n -> !n.startsWith("/"))
.orElseGet(oldCommand::getName);
return "/tool " + name;
}

static void setToolNone(Player player, LocalSession session, boolean isBrush)
throws InvalidToolBindException {
ItemType type = player.getItemInHand(HandSide.MAIN_HAND).getType();
Expand Down Expand Up @@ -183,7 +141,6 @@ public void none(Player player, LocalSession session) throws WorldEditException

@Command(
name = "selwand",
aliases = "/selwand",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question of whether we want to keep these three global aliases. I assume not to try making navwand/selwand less "special"

desc = "Selection wand tool"
)
@CommandPermissions("worldedit.setwand")
Expand All @@ -193,7 +150,6 @@ public void selwand(Player player, LocalSession session) throws WorldEditExcepti

@Command(
name = "navwand",
aliases = "/navwand",
desc = "Navigation wand tool"
)
@CommandPermissions("worldedit.setwand")
Expand Down Expand Up @@ -295,7 +251,6 @@ public void farwand(Player player, LocalSession session) throws WorldEditExcepti

@Command(
name = "lrbuild",
aliases = { "/lrbuild" },
desc = "Long-range building tool"
)
@CommandPermissions("worldedit.tool.lrbuild")
Expand Down
Loading