Search in sources :

Example 1 with BaseCommand

use of dev.rosewood.rosegarden.command.command.BaseCommand in project RoseGarden by Rosewood-Development.

the class RoseCommandWrapper method execute.

@Override
public boolean execute(CommandSender sender, String label, String[] args) {
    try {
        RoseCommand command = this.getCommand(args.length == 0 ? "" : args[0]);
        if (command == null) {
            this.localeManager.sendCommandMessage(sender, "unknown-command", StringPlaceholders.single("cmd", this.getName()));
            return true;
        }
        boolean isOverridden = false;
        if (command instanceof BaseCommand) {
            BaseCommand baseCommand = (BaseCommand) command;
            String override = baseCommand.getOverrideCommand();
            if (override != null) {
                RoseCommand overrideCommand = this.getCommand(override);
                if (overrideCommand != null) {
                    command = overrideCommand;
                    isOverridden = true;
                }
            }
        }
        String[] cmdArgs;
        if (args.length > 0) {
            cmdArgs = new String[args.length - 1];
            System.arraycopy(args, 1, cmdArgs, 0, cmdArgs.length);
        } else {
            cmdArgs = new String[0];
        }
        CommandContext context = new CommandContext(sender, cmdArgs);
        ArgumentParser argumentParser = new ArgumentParser(context, new LinkedList<>(Arrays.asList(cmdArgs)));
        this.runCommand(sender, command, argumentParser, new ArrayList<>(), 0, isOverridden);
    } catch (Exception e) {
        e.printStackTrace();
        this.localeManager.sendCommandMessage(sender, "unknown-command-error");
    }
    return true;
}
Also used : BaseCommand(dev.rosewood.rosegarden.command.command.BaseCommand)

Aggregations

BaseCommand (dev.rosewood.rosegarden.command.command.BaseCommand)1