use of org.enginehub.piston.CommandManagerService in project FastAsyncWorldEdit by IntellectualSites.
the class ToolCommands method register.
public static void register(CommandRegistrationHandler registration, CommandManager commandManager, CommandManagerService commandManagerService, WorldEdit worldEdit) {
// Collect the tool commands
CommandManager collect = commandManagerService.newCommandManager();
registration.register(collect, ToolCommandsRegistration.builder(), 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());
commandManager.register("tool", command -> {
command.addPart(SubCommandPart.builder(Caption.of("tool"), TextComponent.of("The tool to bind")).withCommands(nonGlobalCommands).required().build());
command.description(TextComponent.of("Binds a tool to the item in your hand"));
command.condition(new SubCommandPermissionCondition.Generator(nonGlobalCommands).build());
});
}
Aggregations