Search in sources :

Example 1 with CommandNotFoundException

use of net.minecraft.command.CommandNotFoundException in project watson by totemo.

the class ClientCommandManager method executeCommand.

// --------------------------------------------------------------------------
/**
   * @see net.minecraft.src.ICommandManager#executeCommand(net.minecraft.src.ICommandSender,
   *      java.lang.String)
   * 
   *      The JavaDocs for the interface don't currently describe the exact
   *      meaning of the return value. Looking at the code for
   *      {@link net.minecraft.src.CommandHandler} it contains a loop that
   *      applies a command for all players who match a particular name pattern.
   *      The returned value is the number of times that the command was
   *      successfully executed by that loop. Therefore in the case of this
   *      class, it returns 1 on success and 0 on error.
   */
@Override
public int executeCommand(ICommandSender sender, String commandLine) {
    try {
        String[] tokens = getTokens(commandLine);
        String verb = tokens[0];
        ICommand command = getCommand(verb);
        if (command == null) {
            throw new CommandNotFoundException();
        }
        tokens = Arrays.copyOfRange(tokens, 1, tokens.length);
        if (command.canCommandSenderUseCommand(sender)) {
            command.processCommand(sender, tokens);
            return 1;
        } else {
            sendError(sender, new ChatComponentTranslation("commands.generic.permission", new Object[0]));
        }
    } catch (WrongUsageException ex) {
        sendError(sender, new ChatComponentTranslation("commands.generic.usage", new Object[] { new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()) }));
    } catch (CommandException ex) {
        sendError(sender, new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()));
    } catch (Throwable throwable) {
        sendError(sender, new ChatComponentTranslation("commands.generic.exception", new Object[0]));
        Log.exception(Level.WARNING, "error processing command", throwable);
    }
    return 0;
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) ICommand(net.minecraft.command.ICommand) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) CommandException(net.minecraft.command.CommandException) CommandNotFoundException(net.minecraft.command.CommandNotFoundException)

Aggregations

CommandException (net.minecraft.command.CommandException)1 CommandNotFoundException (net.minecraft.command.CommandNotFoundException)1 ICommand (net.minecraft.command.ICommand)1 WrongUsageException (net.minecraft.command.WrongUsageException)1 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)1