Ejemplo n.º 1
0
  public boolean matches(CommandExecutor sender, String command, String[] args)
      throws CommandSyntaxException, SyntaxResponseException, ExecutorIncompatibleException {
    if (!this.command.equalsIgnoreCase(command)) return false;

    switch (commandExecutor) {
      case CONSOLE:
        if (sender != CommandExecutor.CONSOLE)
          throw new ExecutorIncompatibleException(Message.ONLY_CONSOLE.get(TextMode.COLOR));
        break;
      case PLAYER:
        if (sender != CommandExecutor.PLAYER)
          throw new ExecutorIncompatibleException(Message.ONLY_INGAME.get(TextMode.COLOR));
        break;
    }

    if (args == null || args.length == 0) {
      if (this.args.size() != args.length) return false;
    }

    int i = 0;
    Argument unlimitedArg = null;
    while (i < args.length) {
      Argument exArg = null;
      try {
        exArg = this.args.get(i);
      } catch (IndexOutOfBoundsException e) {
        if (unlimitedArg == null) {
        } else {
          exArg = unlimitedArg;
        }
      }
      if (exArg.isUnlimited()) {
        unlimitedArg = (Argument) exArg.clone();
      }
      String arg = args[i];
      try {
        exArg.getHandler().check(exArg.getParameter(), arg);
      } catch (SyntaxResponseException e) {
        throw e;
      }
      i++;
    }
    if (unlimitedArg != null) return true;
    if (this.args.size() == i) return true;
    return false;
  }