/** * Internally calls {@link #executeCommand(CommandOperationContext, CommandIssuer, String[], RegisteredCommand)} * and gets through {@link #getCommandBySubcommand(String)}. * * @param commandContext * The command context to use. * @param subcommand * The subcommand to find the executor of. * @param issuer * The issuer who executed the subcommand. * @param args * All arguments given by the issuer. * * @return Whether it found a command or not. * * @see #executeCommand(CommandOperationContext, CommandIssuer, String[], RegisteredCommand) * @see #getCommandBySubcommand(String) * @see RegisteredCommand#invoke(CommandIssuer, List, CommandOperationContext) */ private boolean findAndExecuteCommand(CommandOperationContext commandContext, String subcommand, CommandIssuer issuer, String... args) { final RegisteredCommand cmd = this.getCommandBySubcommand(subcommand); if (cmd != null) { executeCommand(commandContext, issuer, args, cmd); return true; } return false; }
public void execute(CommandIssuer issuer, String commandLabel, String[] args) { commandLabel = commandLabel.toLowerCase(); try { CommandOperationContext commandContext = preCommandOperation(issuer, commandLabel, args, false); if (args.length > 0) { CommandSearch cmd = findSubCommand(args); if (cmd != null) { execSubcommand = cmd.getCheckSub(); final String[] execargs = Arrays.copyOfRange(args, cmd.argIndex, args.length); executeCommand(commandContext, issuer, execargs, cmd.cmd); return; } } if (subCommands.get(DEFAULT) != null && args.length == 0) { findAndExecuteCommand(commandContext, DEFAULT, issuer, args); } else if (subCommands.get(CATCHUNKNOWN) != null) { if (!findAndExecuteCommand(commandContext, CATCHUNKNOWN, issuer, args)) { help(issuer, args); } } else if (subCommands.get(DEFAULT) != null) { findAndExecuteCommand(commandContext, DEFAULT, issuer, args); } } finally { postCommandOperation(); } }