Пример #1
0
 /**
  * Get the map with all the registered arguments.
  *
  * @return Map with registered arguments.
  */
 public LinkedHashMap<String, Argument> getArguments() {
   LinkedHashMap<String, Argument> clone = new LinkedHashMap<>();
   for (Map.Entry<String, Argument> entry : arguments.entrySet()) {
     clone.put(entry.getKey(), entry.getValue().clone());
   }
   return clone;
 }
Пример #2
0
  /**
   * Register a regular command argument/parameter for this command.
   *
   * <p>When adding multiple arguments the order you add them in determines the indexing of the
   * argument!
   *
   * @param name The argument name/key used to identify the argument. This name must be used with
   *     the {@link CmdData} result to get the argument value.
   * @param requirement The requirement for this argument. (See {@link ArgRequirement} for more
   *     info)
   * @param option The {@link SingleOption} used for parsing the argument. This option determines
   *     the argument value and everything else. For example if it's a {@link PlayerO} the argument
   *     value must be a player and the result value would be a player.
   * @return The added {@link Argument}
   * @throws IllegalArgumentException if an argument with the specified name is already registered
   *     for this command if the argument option is a sub command option and the command already has
   *     an sub command argument or if the argument option is a sub command option and the command
   *     is a sub command.
   */
  public Argument addArgument(String name, ArgRequirement requirement, SingleOption option) {
    Argument argument = new Argument(name, requirement, option);

    if (getAllArguments().containsKey(name.toLowerCase())) {
      throw new IllegalArgumentException(
          "The command already has an argument with the name '" + name + "'!");
    }

    if (argument.option() instanceof SubCmdO) {
      if (isSub()) {
        throw new IllegalArgumentException(
            "Sub commands can not have sub command arguments. [argument=" + name + "]");
      }
      for (Argument arg : arguments.values()) {
        if (arg.option() instanceof SubCmdO) {
          throw new IllegalArgumentException(
              "The command already has a sub command argument."
                  + "Commands can only have one sub command option. [argument="
                  + name
                  + "]");
        }
      }
    }

    arguments.put(name.toLowerCase(), argument);
    return argument;
  }