Search in sources :

Example 1 with CommandEvent

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

the class ToolUtilCommands method secondary.

@Command(name = "secondary", aliases = { "/secondary" }, desc = "Set the left click brush", descFooter = "Set the left click brush")
@CommandPermissions("worldedit.brush.secondary")
public void secondary(Player player, LocalSession session, @Arg(desc = "The brush command", variable = true) List<String> commandStr) throws WorldEditException {
    BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
    BrushTool tool = session.getBrushTool(player, false);
    session.setTool(item, null, player);
    String cmd = "brush " + StringMan.join(commandStr, " ");
    CommandEvent event = new CommandEvent(player, cmd);
    PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event);
    BrushTool newTool = session.getBrushTool(item, player, false);
    if (newTool != null && tool != null) {
        newTool.setPrimary(tool.getPrimary());
    }
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) CommandEvent(com.sk89q.worldedit.event.platform.CommandEvent) BaseItem(com.sk89q.worldedit.blocks.BaseItem) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 2 with CommandEvent

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

the class PlatformCommandManager method initializeInjectedValues.

// FAWE end
// FAWE start - Event & suggestions, make method public
public MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor actor, Event event, boolean isSuggestions) {
    // FAWE end
    InjectedValueStore store = MapBackedValueStore.create();
    store.injectValue(Key.of(Actor.class), ValueProvider.constant(actor));
    if (actor instanceof Player) {
        store.injectValue(Key.of(Player.class), ValueProvider.constant((Player) actor));
    } else {
        store.injectValue(Key.of(Player.class), context -> {
            throw new CommandException(Caption.of("worldedit.command.player-only"), ImmutableList.of());
        });
    }
    store.injectValue(Key.of(Arguments.class), ValueProvider.constant(arguments));
    store.injectValue(Key.of(LocalSession.class), context -> {
        LocalSession localSession = worldEdit.getSessionManager().get(actor);
        localSession.tellVersion(actor);
        return Optional.of(localSession);
    });
    store.injectValue(Key.of(boolean.class), context -> Optional.of(isSuggestions));
    store.injectValue(Key.of(InjectedValueStore.class), ValueProvider.constant(store));
    store.injectValue(Key.of(Event.class), ValueProvider.constant(event));
    // FAWE start - allow giving editsessions
    if (event instanceof CommandEvent) {
        EditSession session = ((CommandEvent) event).getSession();
        if (session != null) {
            store.injectValue(Key.of(EditSession.class), context -> Optional.of(session));
        }
    }
    // FAWE end
    return MemoizingValueAccess.wrap(MergedValueAccess.of(store, globalInjectedValues));
}
Also used : InjectedValueStore(org.enginehub.piston.inject.InjectedValueStore) Player(com.sk89q.worldedit.entity.Player) Arguments(com.sk89q.worldedit.command.argument.Arguments) LocalSession(com.sk89q.worldedit.LocalSession) CommandEvent(com.sk89q.worldedit.event.platform.CommandEvent) CommandSuggestionEvent(com.sk89q.worldedit.event.platform.CommandSuggestionEvent) Event(com.sk89q.worldedit.event.Event) CommandEvent(com.sk89q.worldedit.event.platform.CommandEvent) CommandException(org.enginehub.piston.exception.CommandException) EditSession(com.sk89q.worldedit.EditSession)

Example 3 with CommandEvent

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

the class CLIWorldEdit method run.

public void run(InputStream inputStream) {
    try (Scanner scanner = new Scanner(inputStream)) {
        while (true) {
            System.err.print("> ");
            if (!scanner.hasNextLine()) {
                break;
            }
            String line = scanner.nextLine();
            if (line.isEmpty()) {
                continue;
            }
            if (line.equals("stop")) {
                commandSender.print(Caption.of("worldedit.cli.stopping"));
                break;
            }
            CommandEvent event = new CommandEvent(commandSender, line);
            WorldEdit.getInstance().getEventBus().post(event);
            if (!event.isCancelled()) {
                commandSender.print(Caption.of("worldedit.cli.unknown-command"));
            } else {
                saveAllWorlds(false);
            }
        }
    } finally {
        saveAllWorlds(false);
    }
}
Also used : Scanner(java.util.Scanner) CommandEvent(com.sk89q.worldedit.event.platform.CommandEvent)

Example 4 with CommandEvent

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

the class WorldEditPlugin method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    // Add the command to the array because the underlying command handling
    // code of WorldEdit expects it
    String[] split = new String[args.length + 1];
    System.arraycopy(args, 0, split, 1, args.length);
    split[0] = commandLabel.startsWith("fastasyncworldedit:") ? commandLabel.replace("fastasyncworldedit:", "") : commandLabel;
    CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split));
    getWorldEdit().getEventBus().post(event);
    return true;
}
Also used : CommandEvent(com.sk89q.worldedit.event.platform.CommandEvent)

Example 5 with CommandEvent

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

the class ToolUtilCommands method primary.

// FAWE start
@Command(name = "primary", aliases = { "/primary" }, desc = "Set the right click brush", descFooter = "Set the right click brush")
@CommandPermissions("worldedit.brush.primary")
public void primary(Player player, LocalSession session, @Arg(desc = "The brush command", variable = true) List<String> commandStr) throws WorldEditException {
    BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
    BrushTool tool = session.getBrushTool(player, false);
    session.setTool(item, null, player);
    String cmd = "brush " + StringMan.join(commandStr, " ");
    CommandEvent event = new CommandEvent(player, cmd);
    PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event);
    BrushTool newTool = session.getBrushTool(item, player, false);
    if (newTool != null && tool != null) {
        newTool.setSecondary(tool.getSecondary());
    }
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) CommandEvent(com.sk89q.worldedit.event.platform.CommandEvent) BaseItem(com.sk89q.worldedit.blocks.BaseItem) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

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