Class Command.Builder<C>

  • Type Parameters:
    C - Command sender type
    Enclosing class:
    Command<C>

    public static final class Command.Builder<C>
    extends java.lang.Object
    Builder for Command instances. The builder is immutable, and each setter method will return a new builder instance.
    • Method Summary

      Modifier and Type Method Description
      <T> @NonNull Command.Builder<C> argument​(@NonNull CommandArgument.Builder<C,​T> builder)
      Add a new command argument with an empty description to the command
      <T> @NonNull Command.Builder<C> argument​(@NonNull CommandArgument.Builder<C,​T> builder, @NonNull Description description)
      Add a new command argument to the command
      <T> @NonNull Command.Builder<C> argument​(@NonNull CommandArgument<C,​T> argument)
      Add a new command argument with an empty description to the command
      <T> @NonNull Command.Builder<C> argument​(@NonNull CommandArgument<C,​T> argument, @NonNull Description description)
      Add a new command argument to the command
      <T> @NonNull Command.Builder<C> argument​(@NonNull java.lang.Class<T> clazz, @NonNull java.lang.String name, @NonNull java.util.function.Consumer<CommandArgument.Builder<C,​T>> builderConsumer)
      Add a new command argument by interacting with a constructed command argument builder
      <U,​V>
      @NonNull Command.Builder<C>
      argumentPair​(@NonNull java.lang.String name, @NonNull Pair<@NonNull java.lang.String,​@NonNull java.lang.String> names, @NonNull Pair<@NonNull java.lang.Class<U>,​@NonNull java.lang.Class<V>> parserPair, @NonNull Description description)
      Create a new argument pair that maps to Pair
      <U,​V,​O>
      @NonNull Command.Builder<C>
      argumentPair​(@NonNull java.lang.String name, @NonNull io.leangen.geantyref.TypeToken<O> outputType, @NonNull Pair<java.lang.String,​java.lang.String> names, @NonNull Pair<java.lang.Class<U>,​java.lang.Class<V>> parserPair, @NonNull java.util.function.BiFunction<C,​Pair<U,​V>,​O> mapper, @NonNull Description description)
      Create a new argument pair that maps to a custom type.
      <U,​V,​W>
      @NonNull Command.Builder<C>
      argumentTriplet​(@NonNull java.lang.String name, @NonNull Triplet<java.lang.String,​java.lang.String,​java.lang.String> names, @NonNull Triplet<java.lang.Class<U>,​java.lang.Class<V>,​java.lang.Class<W>> parserTriplet, @NonNull Description description)
      Create a new argument pair that maps to Triplet
      <U,​V,​W,​O>
      @NonNull Command.Builder<C>
      argumentTriplet​(@NonNull java.lang.String name, @NonNull io.leangen.geantyref.TypeToken<O> outputType, @NonNull Triplet<java.lang.String,​java.lang.String,​java.lang.String> names, @NonNull Triplet<java.lang.Class<U>,​java.lang.Class<V>,​java.lang.Class<W>> parserTriplet, @NonNull java.util.function.BiFunction<C,​Triplet<U,​V,​W>,​O> mapper, @NonNull Description description)
      Create a new argument triplet that maps to a custom type.
      @NonNull Command<C> build()
      Build a command using the builder instance
      <T> @NonNull Command.Builder<C> flag​(@NonNull CommandFlag.Builder<T> builder)
      Register a new command flag
      <T> @NonNull Command.Builder<C> flag​(@NonNull CommandFlag<T> flag)
      Register a new command flag
      @NonNull Command.Builder<C> handler​(@NonNull CommandExecutionHandler<C> commandExecutionHandler)
      Specify the command execution handler
      @NonNull Command.Builder<C> hidden()
      Indicate that the command should be hidden from help menus and other places where commands are exposed to users
      @NonNull Command.Builder<C> literal​(@NonNull java.lang.String main, @NonNull Description description, @NonNull java.lang.String... aliases)
      Inserts a required StaticArgument into the command chain
      @NonNull Command.Builder<C> literal​(@NonNull java.lang.String main, @NonNull java.lang.String... aliases)
      Inserts a required StaticArgument into the command chain
      @NonNull Command.Builder<C> manager​(@Nullable CommandManager<C> commandManager)
      Supply a command manager instance to the builder.
      @NonNull Command.Builder<C> meta​(@NonNull java.lang.String key, @NonNull java.lang.String value)
      Add command meta to the internal command meta map
      @NonNull Command.Builder<C> permission​(@NonNull CommandPermission permission)
      Specify a command permission
      @NonNull Command.Builder<C> permission​(@NonNull java.lang.String permission)
      Specify a command permission
      @NonNull Command.Builder<C> proxies​(@NonNull Command<C> command)
      Make the current command be a proxy of the supplied command.
      @NonNull Command.Builder<C> senderType​(@NonNull java.lang.Class<? extends C> senderType)
      Specify a required sender type
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • meta

        public @NonNull Command.Builder<C> meta​(@NonNull java.lang.String key,
                                                @NonNull java.lang.String value)
        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
      • 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 java.lang.String main,
                                                   @NonNull java.lang.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

        public @NonNull Command.Builder<C> literal​(@NonNull java.lang.String main,
                                                   @NonNull Description description,
                                                   @NonNull java.lang.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
      • 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

        public <T> @NonNull Command.Builder<C> argument​(@NonNull CommandArgument<C,​T> argument,
                                                        @NonNull Description 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
      • argument

        public <T> @NonNull Command.Builder<C> argument​(@NonNull CommandArgument.Builder<C,​T> builder,
                                                        @NonNull Description 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
      • argument

        public <T> @NonNull Command.Builder<C> argument​(@NonNull java.lang.Class<T> clazz,
                                                        @NonNull java.lang.String name,
                                                        @NonNull java.util.function.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

        public <U,​V> @NonNull Command.Builder<C> argumentPair​(@NonNull java.lang.String name,
                                                                    @NonNull Pair<@NonNull java.lang.String,​@NonNull java.lang.String> names,
                                                                    @NonNull Pair<@NonNull java.lang.Class<U>,​@NonNull java.lang.Class<V>> parserPair,
                                                                    @NonNull Description 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
      • argumentPair

        public <U,​V,​O> @NonNull Command.Builder<C> argumentPair​(@NonNull java.lang.String name,
                                                                            @NonNull io.leangen.geantyref.TypeToken<O> outputType,
                                                                            @NonNull Pair<java.lang.String,​java.lang.String> names,
                                                                            @NonNull Pair<java.lang.Class<U>,​java.lang.Class<V>> parserPair,
                                                                            @NonNull java.util.function.BiFunction<C,​Pair<U,​V>,​O> mapper,
                                                                            @NonNull Description 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
      • argumentTriplet

        public <U,​V,​W> @NonNull Command.Builder<C> argumentTriplet​(@NonNull java.lang.String name,
                                                                               @NonNull Triplet<java.lang.String,​java.lang.String,​java.lang.String> names,
                                                                               @NonNull Triplet<java.lang.Class<U>,​java.lang.Class<V>,​java.lang.Class<W>> parserTriplet,
                                                                               @NonNull Description 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
      • argumentTriplet

        public <U,​V,​W,​O> @NonNull Command.Builder<C> argumentTriplet​(@NonNull java.lang.String name,
                                                                                       @NonNull io.leangen.geantyref.TypeToken<O> outputType,
                                                                                       @NonNull Triplet<java.lang.String,​java.lang.String,​java.lang.String> names,
                                                                                       @NonNull Triplet<java.lang.Class<U>,​java.lang.Class<V>,​java.lang.Class<W>> parserTriplet,
                                                                                       @NonNull java.util.function.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
      • 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
      • senderType

        public @NonNull Command.Builder<C> senderType​(@NonNull java.lang.Class<? extends C> senderType)
        Specify a required sender type
        Parameters:
        senderType - Required sender type
        Returns:
        New builder instance using the command execution handler
      • 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 java.lang.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 commands variable command arguments will be inserted into this builder instance, in the order they are declared in the proxied command. Furthermore, the proxied commands command handler will be showed 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
      • build

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