Class Command.Builder<C>

java.lang.Object
cloud.commandframework.Command.Builder<C>
Type Parameters:
C - Command sender type
Enclosing class:
Command<C>

@API(status=STABLE) public static final class Command.Builder<C> extends Object
Builder for Command instances. The builder is immutable, and each setter method will return a new builder instance.
  • Method Details

    • senderType

      @API(status=STABLE, since="1.3.0") public @Nullable Class<? extends C> senderType()
      Get the required sender type for this builder

      Returns null when there is not a specific required sender type

      Returns:
      required sender type
      Since:
      1.3.0
    • commandPermission

      @API(status=STABLE, since="1.3.0") public @NonNull CommandPermission commandPermission()
      Get the required command permission for this builder

      Will return Permission.empty() if there is no required permission

      Returns:
      required permission
      Since:
      1.3.0
    • meta

      @Deprecated @API(status=DEPRECATED, since="1.2.0") public @NonNull Command.Builder<C> meta(@NonNull String key, @NonNull String value)
      Deprecated.
      for removal since 1.2.0, use the typesafe variant at meta(CommandMeta.Key, Object) instead.
      Add command meta to the internal command meta map
      Parameters:
      key - Meta key
      value - Meta value
      Returns:
      New builder instance using the inserted meta key-value pair
    • meta

      @API(status=STABLE, since="1.3.0") public <V> @NonNull Command.Builder<C> meta(@NonNull CommandMeta.Key<V> key, @NonNull V value)
      Add command meta to the internal command meta map
      Type Parameters:
      V - Meta value type
      Parameters:
      key - Meta key
      value - Meta value
      Returns:
      New builder instance using the inserted meta key-value pair
      Since:
      1.3.0
    • manager

      public @NonNull Command.Builder<C> manager(@Nullable CommandManager<C> commandManager)
      Supply a command manager instance to the builder. This will be used when attempting to retrieve command argument parsers, in the case that they're needed. This is optional
      Parameters:
      commandManager - Command manager
      Returns:
      New builder instance using the provided command manager
    • literal

      public @NonNull Command.Builder<C> literal(@NonNull String main, @NonNull String... aliases)
      Inserts a required StaticArgument into the command chain
      Parameters:
      main - Main argument name
      aliases - Argument aliases
      Returns:
      New builder instance with the modified command chain
    • literal

      @Deprecated @API(status=DEPRECATED, since="1.4.0") public @NonNull Command.Builder<C> literal(@NonNull String main, @NonNull Description description, @NonNull String... aliases)
      Deprecated.
      for removal since 1.4.0. Use literal(String, ArgumentDescription, String...) instead.
      Inserts a required StaticArgument into the command chain
      Parameters:
      main - Main argument name
      description - Literal description
      aliases - Argument aliases
      Returns:
      New builder instance with the modified command chain
    • literal

      @API(status=STABLE, since="1.4.0") public @NonNull Command.Builder<C> literal(@NonNull String main, @NonNull ArgumentDescription description, @NonNull String... aliases)
      Inserts a required StaticArgument into the command chain
      Parameters:
      main - Main argument name
      description - Literal description
      aliases - Argument aliases
      Returns:
      New builder instance with the modified command chain
      Since:
      1.4.0
    • argument

      public <T> @NonNull Command.Builder<C> argument(@NonNull CommandArgument.Builder<C,T> builder)
      Add a new command argument with an empty description to the command
      Type Parameters:
      T - Argument type
      Parameters:
      builder - Argument to add. CommandArgument.Builder.build() will be invoked and the result will be registered in the command.
      Returns:
      New builder instance with the command argument inserted into the argument list
    • argument

      public <T> @NonNull Command.Builder<C> argument(@NonNull CommandArgument<C,T> argument)
      Add a new command argument with an empty description to the command
      Type Parameters:
      T - Argument type
      Parameters:
      argument - Argument to add
      Returns:
      New builder instance with the command argument inserted into the argument list
    • argument

      @Deprecated @API(status=DEPRECATED, since="1.4.0") public <T> @NonNull Command.Builder<C> argument(@NonNull CommandArgument<C,T> argument, @NonNull Description description)
      Deprecated.
      for removal since 1.4.0. Use argument(CommandArgument, ArgumentDescription) instead.
      Add a new command argument to the command
      Type Parameters:
      T - Argument type
      Parameters:
      argument - Argument to add
      description - Argument description
      Returns:
      New builder instance with the command argument inserted into the argument list
    • argument

      @API(status=STABLE, since="1.4.0") public <T> @NonNull Command.Builder<C> argument(@NonNull CommandArgument<C,T> argument, @NonNull ArgumentDescription description)
      Add a new command argument to the command
      Type Parameters:
      T - Argument type
      Parameters:
      argument - Argument to add
      description - Argument description
      Returns:
      New builder instance with the command argument inserted into the argument list
      Since:
      1.4.0
    • argument

      @Deprecated @API(status=DEPRECATED, since="1.4.0") public <T> @NonNull Command.Builder<C> argument(@NonNull CommandArgument.Builder<C,T> builder, @NonNull Description description)
      Deprecated.
      for removal since 1.4.0. Use argument(CommandArgument.Builder, ArgumentDescription) instead.
      Add a new command argument to the command
      Type Parameters:
      T - Argument type
      Parameters:
      builder - Argument to add. CommandArgument.Builder.build() will be invoked and the result will be registered in the command.
      description - Argument description
      Returns:
      New builder instance with the command argument inserted into the argument list
    • argument

      @API(status=STABLE, since="1.4.0") public <T> @NonNull Command.Builder<C> argument(@NonNull CommandArgument.Builder<C,T> builder, @NonNull ArgumentDescription description)
      Add a new command argument to the command
      Type Parameters:
      T - Argument type
      Parameters:
      builder - Argument to add. CommandArgument.Builder.build() will be invoked and the result will be registered in the command.
      description - Argument description
      Returns:
      New builder instance with the command argument inserted into the argument list
      Since:
      1.4.0
    • argument

      public <T> @NonNull Command.Builder<C> argument(@NonNull Class<T> clazz, @NonNull String name, @NonNull Consumer<CommandArgument.Builder<C,T>> builderConsumer)
      Add a new command argument by interacting with a constructed command argument builder
      Type Parameters:
      T - Argument type
      Parameters:
      clazz - Argument class
      name - Argument name
      builderConsumer - Builder consumer
      Returns:
      New builder instance with the command argument inserted into the argument list
    • argumentPair

      @Deprecated @API(status=DEPRECATED, since="1.4.0") public <U, V> @NonNull Command.Builder<C> argumentPair(@NonNull String name, @NonNull Pair<@NonNull String,@NonNull String> names, @NonNull Pair<@NonNull Class<U>,@NonNull Class<V>> parserPair, @NonNull Description description)
      Deprecated.
      for removal since 1.4.0. Use argumentPair(String, Pair, Pair, ArgumentDescription) instead.
      Create a new argument pair that maps to Pair

      For this to work, there must be a CommandManager attached to the command builder. To guarantee this, it is recommended to get the command builder instance using CommandManager.commandBuilder(String, String...)

      Type Parameters:
      U - First type
      V - Second type
      Parameters:
      name - Name of the argument
      names - Pair containing the names of the sub-arguments
      parserPair - Pair containing the types of the sub-arguments. There must be parsers for these types registered in the ParserRegistry used by the CommandManager attached to this command
      description - Description of the argument
      Returns:
      Builder instance with the argument inserted
    • argumentPair

      @API(status=STABLE, since="1.4.0") public <U, V> @NonNull Command.Builder<C> argumentPair(@NonNull String name, @NonNull Pair<@NonNull String,@NonNull String> names, @NonNull Pair<@NonNull Class<U>,@NonNull Class<V>> parserPair, @NonNull ArgumentDescription description)
      Create a new argument pair that maps to Pair

      For this to work, there must be a CommandManager attached to the command builder. To guarantee this, it is recommended to get the command builder instance using CommandManager.commandBuilder(String, String...)

      Type Parameters:
      U - First type
      V - Second type
      Parameters:
      name - Name of the argument
      names - Pair containing the names of the sub-arguments
      parserPair - Pair containing the types of the sub-arguments. There must be parsers for these types registered in the ParserRegistry used by the CommandManager attached to this command
      description - Description of the argument
      Returns:
      Builder instance with the argument inserted
      Since:
      1.4.0
    • argumentPair

      @Deprecated @API(status=DEPRECATED, since="1.4.0") public <U, V, O> @NonNull Command.Builder<C> argumentPair(@NonNull String name, @NonNull io.leangen.geantyref.TypeToken<O> outputType, @NonNull Pair<String,String> names, @NonNull Pair<Class<U>,Class<V>> parserPair, @NonNull BiFunction<C,Pair<U,V>,O> mapper, @NonNull Description description)
      Deprecated.
      Create a new argument pair that maps to a custom type.

      For this to work, there must be a CommandManager attached to the command builder. To guarantee this, it is recommended to get the command builder instance using CommandManager.commandBuilder(String, String...)

      Type Parameters:
      U - First type
      V - Second type
      O - Output type
      Parameters:
      name - Name of the argument
      outputType - The output type
      names - Pair containing the names of the sub-arguments
      parserPair - Pair containing the types of the sub-arguments. There must be parsers for these types registered in the ParserRegistry used by the CommandManager attached to this command
      mapper - Mapper that maps from Pair to the custom type
      description - Description of the argument
      Returns:
      Builder instance with the argument inserted
    • argumentPair

      @API(status=STABLE, since="1.4.0") public <U, V, O> @NonNull Command.Builder<C> argumentPair(@NonNull String name, @NonNull io.leangen.geantyref.TypeToken<O> outputType, @NonNull Pair<String,String> names, @NonNull Pair<Class<U>,Class<V>> parserPair, @NonNull BiFunction<C,Pair<U,V>,O> mapper, @NonNull ArgumentDescription description)
      Create a new argument pair that maps to a custom type.

      For this to work, there must be a CommandManager attached to the command builder. To guarantee this, it is recommended to get the command builder instance using CommandManager.commandBuilder(String, String...)

      Type Parameters:
      U - First type
      V - Second type
      O - Output type
      Parameters:
      name - Name of the argument
      outputType - The output type
      names - Pair containing the names of the sub-arguments
      parserPair - Pair containing the types of the sub-arguments. There must be parsers for these types registered in the ParserRegistry used by the CommandManager attached to this command
      mapper - Mapper that maps from Pair to the custom type
      description - Description of the argument
      Returns:
      Builder instance with the argument inserted
      Since:
      1.4.0
    • argumentTriplet

      @Deprecated @API(status=DEPRECATED, since="1.4.0") public <U, V, W> @NonNull Command.Builder<C> argumentTriplet(@NonNull String name, @NonNull Triplet<String,String,String> names, @NonNull Triplet<Class<U>,Class<V>,Class<W>> parserTriplet, @NonNull Description description)
      Deprecated.
      Create a new argument pair that maps to Triplet

      For this to work, there must be a CommandManager attached to the command builder. To guarantee this, it is recommended to get the command builder instance using CommandManager.commandBuilder(String, String...)

      Type Parameters:
      U - First type
      V - Second type
      W - Third type
      Parameters:
      name - Name of the argument
      names - Triplet containing the names of the sub-arguments
      parserTriplet - Triplet containing the types of the sub-arguments. There must be parsers for these types registered in the ParserRegistry used by the CommandManager attached to this command
      description - Description of the argument
      Returns:
      Builder instance with the argument inserted
    • argumentTriplet

      @API(status=STABLE, since="1.4.0") public <U, V, W> @NonNull Command.Builder<C> argumentTriplet(@NonNull String name, @NonNull Triplet<String,String,String> names, @NonNull Triplet<Class<U>,Class<V>,Class<W>> parserTriplet, @NonNull ArgumentDescription description)
      Create a new argument pair that maps to Triplet

      For this to work, there must be a CommandManager attached to the command builder. To guarantee this, it is recommended to get the command builder instance using CommandManager.commandBuilder(String, String...)

      Type Parameters:
      U - First type
      V - Second type
      W - Third type
      Parameters:
      name - Name of the argument
      names - Triplet containing the names of the sub-arguments
      parserTriplet - Triplet containing the types of the sub-arguments. There must be parsers for these types registered in the ParserRegistry used by the CommandManager attached to this command
      description - Description of the argument
      Returns:
      Builder instance with the argument inserted
      Since:
      1.4.0
    • argumentTriplet

      @Deprecated @API(status=DEPRECATED, since="1.4.0") public <U, V, W, O> @NonNull Command.Builder<C> argumentTriplet(@NonNull String name, @NonNull io.leangen.geantyref.TypeToken<O> outputType, @NonNull Triplet<String,String,String> names, @NonNull Triplet<Class<U>,Class<V>,Class<W>> parserTriplet, @NonNull BiFunction<C,Triplet<U,V,W>,O> mapper, @NonNull Description description)
      Create a new argument triplet that maps to a custom type.

      For this to work, there must be a CommandManager attached to the command builder. To guarantee this, it is recommended to get the command builder instance using CommandManager.commandBuilder(String, String...)

      Type Parameters:
      U - First type
      V - Second type
      W - Third type
      O - Output type
      Parameters:
      name - Name of the argument
      outputType - The output type
      names - Triplet containing the names of the sub-arguments
      parserTriplet - Triplet containing the types of the sub-arguments. There must be parsers for these types registered in the ParserRegistry used by the CommandManager attached to this command
      mapper - Mapper that maps from Triplet to the custom type
      description - Description of the argument
      Returns:
      Builder instance with the argument inserted
    • argumentTriplet

      @API(status=STABLE, since="1.4.0") public <U, V, W, O> @NonNull Command.Builder<C> argumentTriplet(@NonNull String name, @NonNull io.leangen.geantyref.TypeToken<O> outputType, @NonNull Triplet<String,String,String> names, @NonNull Triplet<Class<U>,Class<V>,Class<W>> parserTriplet, @NonNull BiFunction<C,Triplet<U,V,W>,O> mapper, @NonNull ArgumentDescription description)
      Create a new argument triplet that maps to a custom type.

      For this to work, there must be a CommandManager attached to the command builder. To guarantee this, it is recommended to get the command builder instance using CommandManager.commandBuilder(String, String...)

      Type Parameters:
      U - First type
      V - Second type
      W - Third type
      O - Output type
      Parameters:
      name - Name of the argument
      outputType - The output type
      names - Triplet containing the names of the sub-arguments
      parserTriplet - Triplet containing the types of the sub-arguments. There must be parsers for these types registered in the ParserRegistry used by the CommandManager attached to this command
      mapper - Mapper that maps from Triplet to the custom type
      description - Description of the argument
      Returns:
      Builder instance with the argument inserted
      Since:
      1.4.0
    • handler

      public @NonNull Command.Builder<C> handler(@NonNull CommandExecutionHandler<C> commandExecutionHandler)
      Specify the command execution handler
      Parameters:
      commandExecutionHandler - New execution handler
      Returns:
      New builder instance using the command execution handler
    • handler

      @API(status=STABLE, since="1.7.0") public @NonNull CommandExecutionHandler<C> handler()
      Returns the current command execution handler.
      Returns:
      the current handler
      Since:
      1.7.0
    • senderType

      public @NonNull Command.Builder<C> senderType(@NonNull Class<? extends C> senderType)
      Specify a required sender type
      Parameters:
      senderType - Required sender type
      Returns:
      New builder instance using the required sender type
    • permission

      public @NonNull Command.Builder<C> permission(@NonNull CommandPermission permission)
      Specify a command permission
      Parameters:
      permission - Command permission
      Returns:
      New builder instance using the command permission
    • permission

      public @NonNull Command.Builder<C> permission(@NonNull PredicatePermission<C> permission)
      Specify a command permission
      Parameters:
      permission - Command permission
      Returns:
      New builder instance using the command permission
    • permission

      public @NonNull Command.Builder<C> permission(@NonNull String permission)
      Specify a command permission
      Parameters:
      permission - Command permission
      Returns:
      New builder instance using the command permission
    • proxies

      public @NonNull Command.Builder<C> proxies(@NonNull Command<C> command)
      Make the current command be a proxy of the supplied command. This means that all of the proxied command's variable command arguments will be inserted into this builder instance, in the order they are declared in the proxied command. Furthermore, the proxied command's command handler will be shown by the command that is currently being built. If the current command builder does not have a permission node set, this too will be copied.
      Parameters:
      command - Command to proxy
      Returns:
      New builder that proxies the given command
    • hidden

      public @NonNull Command.Builder<C> hidden()
      Indicate that the command should be hidden from help menus and other places where commands are exposed to users
      Returns:
      New builder instance that indicates that the constructed command should be hidden
    • flag

      public <T> @NonNull Command.Builder<C> flag(@NonNull CommandFlag<T> flag)
      Register a new command flag
      Type Parameters:
      T - Flag value type
      Parameters:
      flag - Flag
      Returns:
      New builder instance that uses the provided flag
    • flag

      public <T> @NonNull Command.Builder<C> flag(@NonNull CommandFlag.Builder<T> builder)
      Register a new command flag
      Type Parameters:
      T - Flag value type
      Parameters:
      builder - Flag builder. CommandFlag.Builder.build() will be invoked.
      Returns:
      New builder instance that uses the provided flag
    • build

      public @NonNull Command<C> build()
      Build a command using the builder instance
      Returns:
      Built command