Search in sources :

Example 1 with Command

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

the class FabricPlatform method registerCommands.

@Override
public void registerCommands(CommandManager manager) {
    if (server == null)
        return;
    net.minecraft.server.command.CommandManager mcMan = server.getCommandManager();
    for (Command command : manager.getAllCommands().collect(toList())) {
        CommandWrapper.register(mcMan.getDispatcher(), command);
        Set<String> perms = command.getCondition().as(PermissionCondition.class).map(PermissionCondition::getPermissions).orElseGet(Collections::emptySet);
        if (!perms.isEmpty()) {
            perms.forEach(FabricWorldEdit.inst.getPermissionsProvider()::registerPermission);
        }
    }
}
Also used : Command(org.enginehub.piston.Command) Collections(java.util.Collections)

Example 2 with Command

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

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

the class PlatformCommandManager method registerSubCommands.

private <CI> void registerSubCommands(String name, List<String> aliases, String desc, Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance, @Nonnull Consumer<CommandManager> additionalConfig) {
    commandManager.register(name, cmd -> {
        cmd.aliases(aliases);
        cmd.description(TextComponent.of(desc));
        cmd.action(Command.Action.NULL_ACTION);
        CommandManager manager = commandManagerService.newCommandManager();
        // FAWE start
        handlerInstance.accept((handler, instance) -> this.registration.register(manager, handler, instance));
        // FAWE end
        additionalConfig.accept(manager);
        final List<Command> subCommands = manager.getAllCommands().collect(Collectors.toList());
        cmd.addPart(SubCommandPart.builder(Caption.of("worldedit.argument.action"), TextComponent.of("Sub-command to run.")).withCommands(subCommands).required().build());
        cmd.condition(new SubCommandPermissionCondition.Generator(subCommands).build());
    });
}
Also used : CommandManager(org.enginehub.piston.CommandManager) Command(org.enginehub.piston.Command) HelpGenerator(org.enginehub.piston.util.HelpGenerator)

Example 4 with Command

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

the class PlatformCommandManager method handleCommand.

@Subscribe
public void handleCommand(CommandEvent event) {
    Request.reset();
    Actor actor = event.getActor();
    String args = event.getArguments();
    TaskManager.taskManager().taskNow(() -> {
        if (!Fawe.isMainThread()) {
            Thread.currentThread().setName("FAWE Thread for player: " + actor.getName());
        }
        int space0 = args.indexOf(' ');
        String arg0 = space0 == -1 ? args : args.substring(0, space0);
        Optional<Command> optional = commandManager.getCommand(arg0);
        if (!optional.isPresent()) {
            return;
        }
        Command cmd = optional.get();
        PermissionCondition queued = cmd.getCondition().as(PermissionCondition.class).orElse(null);
        if (queued != null && !queued.isQueued()) {
            handleCommandOnCurrentThread(event);
            return;
        } else {
            actor.decline();
        }
        actor.runAction(() -> {
            SessionKey key = actor.getSessionKey();
            if (key.isActive()) {
                PlatformCommandManager.this.handleCommandOnCurrentThread(event);
            }
        }, false, true);
    }, Fawe.isMainThread());
}
Also used : Command(org.enginehub.piston.Command) PermissionCondition(com.sk89q.worldedit.command.util.PermissionCondition) SubCommandPermissionCondition(com.sk89q.worldedit.command.util.SubCommandPermissionCondition) SessionKey(com.sk89q.worldedit.session.SessionKey) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 5 with Command

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

the class PlatformCommandManager method registerSubCommands.

private <CI> void registerSubCommands(String name, List<String> aliases, String desc, CommandRegistration<CI> registration, CI instance, Consumer<CommandManager> additionalConfig) {
    commandManager.register(name, cmd -> {
        cmd.aliases(aliases);
        cmd.description(TextComponent.of(desc));
        cmd.action(Command.Action.NULL_ACTION);
        CommandManager manager = commandManagerService.newCommandManager();
        this.registration.register(manager, registration, instance);
        additionalConfig.accept(manager);
        final List<Command> subCommands = manager.getAllCommands().collect(Collectors.toList());
        cmd.addPart(SubCommandPart.builder(Caption.of("worldedit.argument.action"), TextComponent.of("Sub-command to run.")).withCommands(subCommands).required().build());
        cmd.condition(new SubCommandPermissionCondition.Generator(subCommands).build());
    });
}
Also used : CommandManager(org.enginehub.piston.CommandManager) Command(org.enginehub.piston.Command) HelpGenerator(org.enginehub.piston.util.HelpGenerator)

Aggregations

Command (org.enginehub.piston.Command)8 CommandManager (org.enginehub.piston.CommandManager)3 PermissionCondition (com.sk89q.worldedit.command.util.PermissionCondition)2 HelpGenerator (org.enginehub.piston.util.HelpGenerator)2 ImmutableList (com.google.common.collect.ImmutableList)1 SubCommandPermissionCondition (com.sk89q.worldedit.command.util.SubCommandPermissionCondition)1 CommandEvent (com.sk89q.worldedit.event.platform.CommandEvent)1 CommandSuggestionEvent (com.sk89q.worldedit.event.platform.CommandSuggestionEvent)1 Actor (com.sk89q.worldedit.extension.platform.Actor)1 SessionKey (com.sk89q.worldedit.session.SessionKey)1 Subscribe (com.sk89q.worldedit.util.eventbus.Subscribe)1 CommandListBox (com.sk89q.worldedit.util.formatting.component.CommandListBox)1 CommandUsageBox (com.sk89q.worldedit.util.formatting.component.CommandUsageBox)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Nullable (javax.annotation.Nullable)1 InjectedValueStore (org.enginehub.piston.inject.InjectedValueStore)1 CommandSource (org.spongepowered.api.command.CommandSource)1 Location (org.spongepowered.api.world.Location)1