Class CommandBuilder<T,B extends CommandBuilder<T,B>>

java.lang.Object
redempt.ordinate.builder.CommandBuilder<T,B>
Type Parameters:
T - The sender type
B - The type of the builder itself

public class CommandBuilder<T,B extends CommandBuilder<T,B>> extends Object
Builds a command, provided by CommandManager
  • Field Details

  • Constructor Details

  • Method Details

    • help

      public B help(String help)
      Sets the help message of the command
      Parameters:
      help - The help message
      Returns:
      Itself
    • arg

      public B arg(Class<?> type, String name)
      Adds a new argument to the command
      Parameters:
      type - The type of the argument
      name - The name of the argument
      Returns:
      Itself
    • consumingArg

      public <V> B consumingArg(Class<V> type, String name, boolean optional, Function<CommandContext<T>,V> defaultValue)
      Adds a new consuming argument to the command. Consuming arguments take all the remaining arguments in the command and parse them as a single string.
      Type Parameters:
      V - The argument type
      Parameters:
      type - The type of the argument
      name - The name of the argument
      optional - Whether the argument should be optional
      defaultValue - The default value if no value is provided
      Returns:
      Itself
    • consumingArg

      public <V> B consumingArg(Class<V> type, String name)
      Adds a new consuming argument to the command. Consuming arguments take all the remaining arguments in the command and parse them as a single string.
      Type Parameters:
      V - The argument type
      Parameters:
      type - The type of the argument
      name - The name of the argument
      Returns:
      Itself
    • optionalArg

      public <V> B optionalArg(Class<V> type, String name, Function<CommandContext<T>,V> defaultValue)
      Adds a new optional argument to the command
      Type Parameters:
      V - The argument type
      Parameters:
      type - The type of the argument
      name - The name of the argument
      defaultValue - The default value of the argument, pass null for no default
      Returns:
      Itself
    • subcommand

      public B subcommand(String[] names, Consumer<B> consumer)
      Creates a subcommand for the command
      Parameters:
      names - The names of the subcommand
      consumer - A function which will mutate the created builder, after which its command will be added as a child of this one
      Returns:
      Itself
    • subcommand

      public B subcommand(String name, Consumer<B> consumer)
      Creates a subcommand for the command
      Parameters:
      name - The names of the subcommand
      consumer - A function which will mutate the created builder, after which its command will be added as a child of this one
      Returns:
      Itself
    • noHelpSubcommand

      public B noHelpSubcommand()
      Removes the auto-generated help subcommand
      Returns:
      Itself
    • handler

      public B handler(Consumer<CommandArguments<T>> handler)
      Assigns a handler that will be run when the command is executed
      Parameters:
      handler - The handler
      Returns:
      Itself
    • boolFlag

      public B boolFlag(String... names)
      Adds a new boolean flag to the command, which will be passed as true if present in the command when run and false otherwise
      Parameters:
      names - The names of the flag, must all start with a dash
      Returns:
      Itself
    • postArgument

      public B postArgument()
      Marks the command as post-argument, meaning it will be positioned after the arguments of its parent and will be able to access those arguments
      Returns:
      Itself
    • build

      protected Command<T> build()
    • register

      public CommandBase<T> register()
      Registers the command. Do not call on subcommands.
      Returns:
      The built command