Search in sources :

Example 1 with CommandRegistrationHandler

use of com.sk89q.worldedit.internal.command.CommandRegistrationHandler 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());
    });
}
Also used : SubCommandPart(org.enginehub.piston.part.SubCommandPart) CommandParameters(org.enginehub.piston.CommandParameters) BlockDataCyler(com.sk89q.worldedit.command.tool.BlockDataCyler) Player(com.sk89q.worldedit.entity.Player) StackTool(com.sk89q.worldedit.command.tool.StackTool) Caption(com.fastasyncworldedit.core.configuration.Caption) Collections2(com.google.common.collect.Collections2) BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) FloodFillTool(com.sk89q.worldedit.command.tool.FloodFillTool) Arg(org.enginehub.piston.annotation.param.Arg) SubCommandPermissionCondition(com.sk89q.worldedit.command.util.SubCommandPermissionCondition) Component(com.sk89q.worldedit.util.formatting.text.Component) WorldEditException(com.sk89q.worldedit.WorldEditException) SelectionWand(com.sk89q.worldedit.command.tool.SelectionWand) CommandContainer(org.enginehub.piston.annotation.CommandContainer) TreeGenerator(com.sk89q.worldedit.util.TreeGenerator) TextColor(com.sk89q.worldedit.util.formatting.text.format.TextColor) InspectBrush(com.fastasyncworldedit.core.command.tool.brush.InspectBrush) ClickEvent(com.sk89q.worldedit.util.formatting.text.event.ClickEvent) NavigationWand(com.sk89q.worldedit.command.tool.NavigationWand) QueryTool(com.sk89q.worldedit.command.tool.QueryTool) WorldEdit(com.sk89q.worldedit.WorldEdit) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) FloatingTreeRemover(com.sk89q.worldedit.command.tool.FloatingTreeRemover) HandSide(com.sk89q.worldedit.util.HandSide) CommandManager(org.enginehub.piston.CommandManager) CommandMetadata(org.enginehub.piston.CommandMetadata) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) InvalidToolBindException(com.sk89q.worldedit.command.tool.InvalidToolBindException) BrushTool(com.sk89q.worldedit.command.tool.BrushTool) Set(java.util.Set) CommandUtil(com.sk89q.worldedit.internal.command.CommandUtil) BlockReplacer(com.sk89q.worldedit.command.tool.BlockReplacer) Collectors(java.util.stream.Collectors) Tool(com.sk89q.worldedit.command.tool.Tool) CommandManagerService(org.enginehub.piston.CommandManagerService) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) DistanceWand(com.sk89q.worldedit.command.tool.DistanceWand) Command(org.enginehub.piston.annotation.Command) CommandPermissionsConditionGenerator(com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator) TreePlanter(com.sk89q.worldedit.command.tool.TreePlanter) LongRangeBuildTool(com.sk89q.worldedit.command.tool.LongRangeBuildTool) Optional(java.util.Optional) LocalSession(com.sk89q.worldedit.LocalSession) Mask(com.sk89q.worldedit.function.mask.Mask) Pattern(com.sk89q.worldedit.function.pattern.Pattern) CommandRegistrationHandler(com.sk89q.worldedit.internal.command.CommandRegistrationHandler) CommandManager(org.enginehub.piston.CommandManager) Command(org.enginehub.piston.annotation.Command) TreeGenerator(com.sk89q.worldedit.util.TreeGenerator) CommandPermissionsConditionGenerator(com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator)

Aggregations

InspectBrush (com.fastasyncworldedit.core.command.tool.brush.InspectBrush)1 Caption (com.fastasyncworldedit.core.configuration.Caption)1 Collections2 (com.google.common.collect.Collections2)1 LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)1 LocalSession (com.sk89q.worldedit.LocalSession)1 WorldEdit (com.sk89q.worldedit.WorldEdit)1 WorldEditException (com.sk89q.worldedit.WorldEditException)1 BaseItemStack (com.sk89q.worldedit.blocks.BaseItemStack)1 BlockDataCyler (com.sk89q.worldedit.command.tool.BlockDataCyler)1 BlockReplacer (com.sk89q.worldedit.command.tool.BlockReplacer)1 BrushTool (com.sk89q.worldedit.command.tool.BrushTool)1 DistanceWand (com.sk89q.worldedit.command.tool.DistanceWand)1 FloatingTreeRemover (com.sk89q.worldedit.command.tool.FloatingTreeRemover)1 FloodFillTool (com.sk89q.worldedit.command.tool.FloodFillTool)1 InvalidToolBindException (com.sk89q.worldedit.command.tool.InvalidToolBindException)1 LongRangeBuildTool (com.sk89q.worldedit.command.tool.LongRangeBuildTool)1 NavigationWand (com.sk89q.worldedit.command.tool.NavigationWand)1 QueryTool (com.sk89q.worldedit.command.tool.QueryTool)1 SelectionWand (com.sk89q.worldedit.command.tool.SelectionWand)1 StackTool (com.sk89q.worldedit.command.tool.StackTool)1