Example #1
0
  /**
   * Executes the command in the executor it is currently set to.
   *
   * @param source that sent the command
   * @param args command arguments
   * @throws CommandException if the command executor is null or if {@link
   *     Executor#execute(CommandSource, Command, CommandArguments)} throws a CommandException.
   */
  public void process(CommandSource source, CommandArguments args) throws CommandException {

    // check permissions
    if (permission != null && !source.hasPermission(permission)) {
      throw new CommandException("You do not have permission to execute this command.");
    }

    args.flags().registerFlags(this.flags);

    // no child found, try to execute
    for (CommandFilter filter : filters) {
      filter.validate(this, source, args);
    }

    // execute a child if applicable
    if (children.size() > 0) {
      Command child = getChild(args.popString("child"), false);
      if (child != null) {
        if (executor != null) {
          executor.execute(source, this, args);
        }
        child.process(source, args);
      } else {
        throw args.failure("child", "Unknown child!", false);
      }
    } else {
      if (executor == null) {
        throw new CommandException("CommandDescription exists but has no set executor.");
      }
      args.flags().parse();
      executor.execute(source, this, args);
    }
  }