Interface Command<S extends Source>

Type Parameters:
S - the command sender valueType
All Superinterfaces:
BaseThrowableHandler<S>, CommandParameter<S>, DescriptionHolder, FlagRegistrar<S>, PermissionHolder, ThrowableHandler<S>

@AvailableSince("1.0.0") public interface Command<S extends Source> extends CommandParameter<S>, FlagRegistrar<S>, BaseThrowableHandler<S>
Represents a wrapper for the actual command's data
  • Method Details

    • create

      static <S extends Source> Command.Builder<S> create(@NotNull @NotNull Imperat<S> imperat, String name)
    • create

      static <S extends Source> Command.Builder<S> create(@NotNull @NotNull Imperat<S> imperat, @Nullable @Nullable Command<S> parent, @NotNull @NotNull String name)
    • create

      static <S extends Source> Command.Builder<S> create(@NotNull @NotNull Imperat<S> imperat, @Nullable @Nullable Command<S> parent, int position, @NotNull @NotNull String name)
    • imperat

      @NotNull @NotNull Imperat<S> imperat()
    • name

      String name()
      Specified by:
      name in interface CommandParameter<S extends Source>
      Returns:
      The name of the command
    • aliases

      @UnmodifiableView List<String> aliases()
      Returns:
      The aliases for this commands
    • addAliases

      void addAliases(List<String> aliases)
      Sets the aliases of a command
      Parameters:
      aliases - the aliases for te command to set
    • addAliases

      default void addAliases(String... aliases)
      Adds aliases for the command using an array of alias strings.

      This method internally converts the array to a list and calls the addAliases(List<String> aliases) method to set the aliases.

      Parameters:
      aliases - the array of alias strings to be added
    • hasName

      default boolean hasName(String name)
      Parameters:
      name - the name used
      Returns:
      Whether this command has this name/alias
    • tree

      CommandTree<S> tree()
      Returns:
      The tree for the command
    • visualizeTree

      void visualizeTree()
      Debugs or visualizes all tree nodes from CommandTree. If the command is not a root command, nothing will be visualized.
    • contextMatch

      @NotNull @NotNull CommandPathSearch<S> contextMatch(Context<S> context)
      Traverses the CommandTree linked to this command object, searching for the most suitable usage that best suites the context input by the user
      Parameters:
      context - the context of the execution
    • description

      @NotNull @NotNull Description description()
      Description copied from interface: DescriptionHolder
      Retrieves the current description associated with this entity.
      Specified by:
      description in interface DescriptionHolder
      Returns:
      The description of a command
    • type

      @NotNull default @NotNull ParameterType<S,?> type()
      Retrieves the parameter type associated with the current command, including its name and any aliases.
      Specified by:
      type in interface CommandParameter<S extends Source>
      Returns:
      a ParameterType instance representing the command's parameter type, encapsulating its name and aliases
    • position

      @Internal default void position(int position)
      Sets the position of this command in a syntax DO NOT USE THIS FOR ANY REASON unless it's necessary to do so
      Specified by:
      position in interface CommandParameter<S extends Source>
      Parameters:
      position - the position to set
    • getDefaultValueSupplier

      @NotNull default @NotNull OptionalValueSupplier getDefaultValueSupplier()
      Specified by:
      getDefaultValueSupplier in interface CommandParameter<S extends Source>
      Returns:
      the default value if it's input is not present in case of the parameter being optional
    • addPreProcessor

      void addPreProcessor(@NotNull @NotNull CommandPreProcessor<S> preProcessor)
      Sets a pre-processor for the command
      Parameters:
      preProcessor - the pre-processor for the command
    • preProcess

      void preProcess(@NotNull @NotNull Imperat<S> api, @NotNull @NotNull Context<S> context, @NotNull @NotNull CommandUsage<S> usage) throws ImperatException
      Executes the pre-processing instructions in CommandPreProcessor
      Parameters:
      api - the api
      context - the context
      usage - the usage detected being used
      Throws:
      ImperatException
    • addPostProcessor

      void addPostProcessor(@NotNull @NotNull CommandPostProcessor<S> postProcessor)
      Sets a post-processor for the command
      Parameters:
      postProcessor - the post-processor for the command
    • postProcess

      void postProcess(@NotNull @NotNull Imperat<S> api, @NotNull @NotNull ExecutionContext<S> context, @NotNull @NotNull CommandUsage<S> usage) throws ImperatException
      Executes the post-processing instructions in CommandPostProcessor
      Parameters:
      api - the api
      context - the context
      usage - the usage detected being used
      Throws:
      ImperatException
    • getEmptyUsage

      @NotNull @AvailableSince("1.9.0") @NotNull CommandUsage<S> getEmptyUsage()
      Retrieves a usage with no args for this command
      Returns:
      A usage with empty parameters.
    • getDefaultUsage

      @NotNull @AvailableSince("1.9.0") @NotNull CommandUsage<S> getDefaultUsage()
      Returns:
      the default usage of the command without any args
    • setDefaultUsage

      @AvailableSince("1.9.0") void setDefaultUsage(@NotNull @NotNull CommandUsage<S> usage)
      Sets the default command usage representation.
      Parameters:
      usage - the default command usage instance to be set, which must not be null
    • addUsage

      void addUsage(CommandUsage<S> usage)
      Adds a usage to the command
      Parameters:
      usage - the usage CommandUsage of the command
    • addUsage

      default void addUsage(CommandUsage.Builder<S> builder, boolean help)
    • addUsage

      default void addUsage(CommandUsage.Builder<S> builder)
    • usages

      Collection<? extends CommandUsage<S>> usages()
      Returns:
      All CommandUsage that were registered to this command by the user
    • getMainUsage

      @NotNull @NotNull CommandUsage<S> getMainUsage()
      Returns:
      the usage that doesn't include any subcommands, only required parameters
    • autoCompleter

      AutoCompleter<S> autoCompleter()
      Returns:
      Returns AutoCompleter that handles all auto-completes for this command
    • addSubCommand

      void addSubCommand(Command<S> command, AttachmentMode attachmentMode)
      Injects a created-subcommand directly into the parent's command usages.
      Parameters:
      command - the subcommand to inject
      attachmentMode - see AttachmentMode
    • addSubCommandUsage

      void addSubCommandUsage(String subCommand, List<String> aliases, CommandUsage.Builder<S> usage, AttachmentMode attachmentMode)
      Creates and adds a new sub-command (if it doesn't exist) then add the CommandUsage to the sub-command
      Parameters:
      subCommand - the sub-command's unique name
      aliases - of the subcommand
      usage - the usage
      attachmentMode - see AttachmentMode
    • addSubCommandUsage

      default void addSubCommandUsage(String subCommand, List<String> aliases, CommandUsage.Builder<S> usage)
    • addSubCommandUsage

      default void addSubCommandUsage(String subCommand, CommandUsage.Builder<S> usage, AttachmentMode attachmentMode)
    • addSubCommandUsage

      default void addSubCommandUsage(String subCommand, CommandUsage.Builder<S> usage)
      Creates and adds a new sub-command (if it doesn't exist) then add the CommandUsage to the sub-command
      Parameters:
      subCommand - the sub-command's unique name
      usage - the usage
    • getSubCommand

      @Nullable @Nullable Command<S> getSubCommand(String name)
      Parameters:
      name - the name of the wanted sub-command
      Returns:
      the sub-command of specific name
    • getSubCommands

      @NotNull @NotNull Collection<? extends Command<S>> getSubCommands()
      Returns:
      the subcommands of this command
    • getUsage

      @Nullable default @Nullable CommandUsage<S> getUsage(Predicate<CommandUsage<S>> usagePredicate)
    • hasParent

      default boolean hasParent()
    • isSubCommand

      default boolean isSubCommand()
    • wrappedType

      default TypeWrap<?> wrappedType()
      Specified by:
      wrappedType in interface CommandParameter<S extends Source>
      Returns:
      the value valueType of this parameter
    • isOptional

      default boolean isOptional()
      Specified by:
      isOptional in interface CommandParameter<S extends Source>
      Returns:
      whether this is an optional argument
    • isGreedy

      default boolean isGreedy()
      Specified by:
      isGreedy in interface CommandParameter<S extends Source>
      Returns:
      checks whether this parameter consumes all the args input after it.
    • isFlag

      default boolean isFlag()
      Specified by:
      isFlag in interface CommandParameter<S extends Source>
      Returns:
      checks whether this parameter is a flag
    • asCommand

      default Command<S> asCommand()
      Description copied from interface: CommandParameter
      Casts the parameter to a subcommand/command
      Specified by:
      asCommand in interface CommandParameter<S extends Source>
      Returns:
      the parameter as a command
    • format

      default String format()
      Formats the usage parameter
      Specified by:
      format in interface CommandParameter<S extends Source>
      Returns:
      the formatted parameter
      See Also:
    • isIgnoringACPerms

      boolean isIgnoringACPerms()
      whether to ignore permission checks on the auto-completion of command and sub commands or not
      Returns:
      whether to ignore permission checks on the auto-completion of command and sub commands or not
    • ignoreACPermissions

      void ignoreACPermissions(boolean ignore)
      if true, it will ignore permission checks on the auto-completion of command and sub commands

      otherwise, it will perform permission checks and only tab-completes the usages/subcommands that you have permission for

      Parameters:
      ignore - true if you want to ignore the permission checks on tab completion of args
    • registerSubCommand

      @Internal @AvailableSince("1.9.0") void registerSubCommand(Command<S> subCommand)
    • getMainPermission

      @Nullable default @Nullable String getMainPermission()
    • getPreProcessors

    • getPostProcessors

    • setPreProcessingChain

      void setPreProcessingChain(CommandProcessingChain<S,CommandPreProcessor<S>> chain)
    • setPostProcessingChain

      void setPostProcessingChain(CommandProcessingChain<S,CommandPostProcessor<S>> chain)