Search in sources :

Example 6 with CommandEvent

use of com.sk89q.worldedit.event.platform.CommandEvent in project FastAsyncWorldEdit by IntellectualSites.

the class SpongePlatform method registerCommands.

@Override
public void registerCommands(CommandManager manager) {
    for (Command command : manager.getAllCommands().collect(toList())) {
        CommandAdapter adapter = new CommandAdapter(command) {

            @Override
            public CommandResult process(CommandSource source, String arguments) throws org.spongepowered.api.command.CommandException {
                CommandEvent weEvent = new CommandEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getName() + " " + arguments);
                WorldEdit.getInstance().getEventBus().post(weEvent);
                return weEvent.isCancelled() ? CommandResult.success() : CommandResult.empty();
            }

            @Override
            public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<org.spongepowered.api.world.World> targetPosition) throws CommandException {
                CommandSuggestionEvent weEvent = new CommandSuggestionEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getName() + " " + arguments);
                WorldEdit.getInstance().getEventBus().post(weEvent);
                return CommandUtil.fixSuggestions(arguments, weEvent.getSuggestions());
            }
        };
        ImmutableList.Builder<String> aliases = ImmutableList.builder();
        aliases.add(command.getName()).addAll(command.getAliases());
        Sponge.getCommandManager().register(SpongeWorldEdit.inst(), adapter, aliases.build());
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) CommandSource(org.spongepowered.api.command.CommandSource) CommandSuggestionEvent(com.sk89q.worldedit.event.platform.CommandSuggestionEvent) Command(org.enginehub.piston.Command) CommandEvent(com.sk89q.worldedit.event.platform.CommandEvent) Nullable(javax.annotation.Nullable) Location(org.spongepowered.api.world.Location)

Aggregations

CommandEvent (com.sk89q.worldedit.event.platform.CommandEvent)6 BaseItem (com.sk89q.worldedit.blocks.BaseItem)2 BrushTool (com.sk89q.worldedit.command.tool.BrushTool)2 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 CommandSuggestionEvent (com.sk89q.worldedit.event.platform.CommandSuggestionEvent)2 Command (org.enginehub.piston.annotation.Command)2 ImmutableList (com.google.common.collect.ImmutableList)1 EditSession (com.sk89q.worldedit.EditSession)1 LocalSession (com.sk89q.worldedit.LocalSession)1 Arguments (com.sk89q.worldedit.command.argument.Arguments)1 Player (com.sk89q.worldedit.entity.Player)1 Event (com.sk89q.worldedit.event.Event)1 Scanner (java.util.Scanner)1 Nullable (javax.annotation.Nullable)1 Command (org.enginehub.piston.Command)1 CommandException (org.enginehub.piston.exception.CommandException)1 InjectedValueStore (org.enginehub.piston.inject.InjectedValueStore)1 CommandSource (org.spongepowered.api.command.CommandSource)1 Location (org.spongepowered.api.world.Location)1