Search in sources :

Example 1 with CommandManager

use of org.enginehub.piston.CommandManager in project FastAsyncWorldEdit by IntellectualSites.

the class WorldEditListener method onPlayerCommandSend.

// FAWE end
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommandSend(PlayerCommandSendEvent event) {
    InjectedValueStore store = MapBackedValueStore.create();
    store.injectValue(Key.of(Actor.class), context -> Optional.of(plugin.wrapCommandSender(event.getPlayer())));
    CommandManager commandManager = plugin.getWorldEdit().getPlatformManager().getPlatformCommandManager().getCommandManager();
    event.getCommands().removeIf(name -> commandManager.getCommand(name).filter(command -> !command.getCondition().satisfied(store)).isPresent());
}
Also used : InjectedValueStore(org.enginehub.piston.inject.InjectedValueStore) CommandManager(org.enginehub.piston.CommandManager) Actor(com.sk89q.worldedit.extension.platform.Actor) EventHandler(org.bukkit.event.EventHandler)

Example 2 with CommandManager

use of org.enginehub.piston.CommandManager in project FastAsyncWorldEdit by IntellectualSites.

the class ExpandCommands method register.

public static void register(CommandRegistrationHandler registration, CommandManager commandManager, CommandManagerService commandManagerService) {
    // Collect the general expand command
    CommandManager collect = commandManagerService.newCommandManager();
    registration.register(collect, ExpandCommandsRegistration.builder(), new ExpandCommands());
    Command expandBaseCommand = collect.getCommand("/expand").orElseThrow(() -> new IllegalStateException("No /expand command"));
    commandManager.register("/expand", command -> {
        command.condition(new PermissionCondition(ImmutableSet.of("worldedit.selection.expand")));
        command.addPart(SubCommandPart.builder(Caption.of("vert"), TextComponent.of("Vertical expansion sub-command")).withCommands(ImmutableSet.of(createVertCommand(commandManager))).optional().build());
        command.addParts(expandBaseCommand.getParts());
        command.action(expandBaseCommand.getAction());
        command.description(expandBaseCommand.getDescription());
    });
}
Also used : CommandManager(org.enginehub.piston.CommandManager) Command(org.enginehub.piston.Command) PermissionCondition(com.sk89q.worldedit.command.util.PermissionCondition)

Example 3 with CommandManager

use of org.enginehub.piston.CommandManager in project FastAsyncWorldEdit by IntellectualSites.

the class GeneralCommands 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, GeneralCommandsRegistration.builder(), new GeneralCommands(worldEdit));
    Set<org.enginehub.piston.Command> commands = collect.getAllCommands().collect(Collectors.toSet());
    for (org.enginehub.piston.Command command : commands) {
        /*FAWE start - if in FAWE, //fast will remain for now
             (command.getName().equals("/fast")) {

                // deprecate to `//perf`
                commandManager.register(CommandUtil.deprecate(
                    command, "//fast duplicates //perf " +
                        "and will be removed in WorldEdit 8",
                    GeneralCommands::replaceFastForPerf
                ));
                continue;
            }
            */
        commandManager.register(command);
    }
}
Also used : CommandManager(org.enginehub.piston.CommandManager) Command(org.enginehub.piston.annotation.Command)

Example 4 with CommandManager

use of org.enginehub.piston.CommandManager 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)

Example 5 with CommandManager

use of org.enginehub.piston.CommandManager in project FastAsyncWorldEdit by IntellectualSites.

the class PaintBrushCommands method register.

public static void register(CommandManagerService service, CommandManager commandManager, CommandRegistrationHandler registration) {
    commandManager.register("paint", builder -> {
        builder.description(Caption.of("worldedit.brush.paint.description"));
        builder.action(org.enginehub.piston.Command.Action.NULL_ACTION);
        CommandManager manager = service.newCommandManager();
        registration.register(manager, PaintBrushCommandsRegistration.builder(), new PaintBrushCommands());
        builder.condition(new PermissionCondition(ImmutableSet.of("worldedit.brush.paint")));
        builder.addParts(REGION_FACTORY, RADIUS, DENSITY);
        builder.addPart(SubCommandPart.builder(TranslatableComponent.of("type"), Caption.of("worldedit.brush.paint.type")).withCommands(manager.getAllCommands().collect(Collectors.toList())).required().build());
    });
}
Also used : CommandManager(org.enginehub.piston.CommandManager) PermissionCondition(com.sk89q.worldedit.command.util.PermissionCondition)

Aggregations

CommandManager (org.enginehub.piston.CommandManager)8 PermissionCondition (com.sk89q.worldedit.command.util.PermissionCondition)3 Command (org.enginehub.piston.Command)3 HelpGenerator (org.enginehub.piston.util.HelpGenerator)2 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