Interface Command<S extends CommandSource>

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

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

    • create

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

      static <S extends CommandSource> Command.Builder<S> create(@NotNull @NotNull Imperat<S> imperat, String name, @Nullable @Nullable ParseElement<?> annotatedElement)
    • create

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

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

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

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

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

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

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

      @Nullable @Nullable ParseElement<?> getAnnotatedElement()
      Returns:
      the annotated element this object got extracted from, null if it was created from a ParseElement
    • isAnnotated

      default boolean isAnnotated()
      Specified by:
      isAnnotated in interface Argument<S extends CommandSource>
      Returns:
      Whether this usage parameter has been constructed using the annotations through methods or not
    • asAnnotatedArgument

      default AnnotatedArgument<S> asAnnotatedArgument()
      Description copied from interface: Argument
      Casts the parameter to a parameter with annotations
      Specified by:
      asAnnotatedArgument in interface Argument<S extends CommandSource>
      Returns:
      the parameter as annotated one
      See Also:
    • 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.
    • execute

      @NotNull @NotNull TreeExecutionResult<S> execute(ExecutionContext<S> context) throws CommandException
      Traverses the CommandTree linked to this command object, directly executing the most suitable pathway that matches the context input by the user.
      Parameters:
      context - the context of the execution
      Returns:
      the result of the direct tree execution
      Throws:
      CommandException - if an error occurs during execution
    • getDescription

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

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

      @Internal default void setPosition(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:
      setPosition in interface Argument<S extends CommandSource>
      Parameters:
      position - the position to set
    • getDefaultValueSupplier

      @NotNull default @NotNull DefaultValueProvider getDefaultValueSupplier()
      Specified by:
      getDefaultValueSupplier in interface Argument<S extends CommandSource>
      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 CommandContext<S> context) throws CommandException
      Executes the pre-processing instructions in CommandPreProcessor
      Parameters:
      context - the context
      Throws:
      CommandException
    • 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 ExecutionContext<S> context) throws CommandException
      Executes the post-processing instructions in CommandPostProcessor
      Parameters:
      context - the context
      Throws:
      CommandException
    • getDefaultPathway

      @NotNull @AvailableSince("1.9.0") @NotNull CommandPathway<S> getDefaultPathway()
      Returns:
      the default usage of the command without any args
    • setDefaultPathway

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

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

      default void addPathway(CommandPathway.Builder<S> builder)
    • getDedicatedPathways

      Collection<? extends CommandPathway<S>> getDedicatedPathways()
      Returns:
      the pathways that are directly attached to this command without being inherited from a parent command
    • autoCompleter

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

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

      @Nullable @Nullable Command<S> getSubCommand(String name, boolean recursive)
      Parameters:
      name - the name of the wanted sub-command
      recursive - whether to search for the subcommand deeply not just in the direct subcommands of this 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 CommandPathway<S> getUsage(Predicate<CommandPathway<S>> usagePredicate)
    • hasParent

      default boolean hasParent()
    • isSubCommand

      default boolean isSubCommand()
    • getShortcut

      @Nullable @Nullable Command<S> getShortcut(String shortcutName)
      Returns:
      the parent command of this command, null if it doesn't have a parent
    • getShortcuts

      @UnmodifiableView Collection<? extends Command<S>> getShortcuts()
      Returns:
      the shortcuts of this command
    • addShortcut

      void addShortcut(Command<S> shortcut)
      Adds a shortcut to this command. Shortcuts are alternative names for the same command, allowing users to execute the command using different aliases.
      Parameters:
      shortcut - the RootCommand instance representing the shortcut to be added
    • wrappedType

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

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

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

      default boolean isFlag()
      Specified by:
      isFlag in interface Argument<S extends CommandSource>
      Returns:
      checks whether this parameter is a flag
    • isSecret

      boolean isSecret()
      Returns:
      checks whether this parameter is secret, meaning it won't be displayed in the usage of the command, and it will be ignored in the auto-completion suggestions
    • setSecret

      void setSecret(boolean secret)
      Sets whether this parameter is secret, meaning it won't be displayed in the usage of the command, and it will be ignored in the auto-completion suggestions
      Parameters:
      secret - true if you want this parameter to be secret, false otherwise
    • asCommand

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

      default String format()
      Formats the usage parameter
      Specified by:
      format in interface Argument<S extends CommandSource>
      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
    • setIgnoreACPermissions

      void setIgnoreACPermissions(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
    • getPreProcessors

      PriorityList<CommandPreProcessor<S>> getPreProcessors()
    • getPostProcessors

      PriorityList<CommandPostProcessor<S>> getPostProcessors()
    • setPreProcessingChain

      void setPreProcessingChain(PriorityList<CommandPreProcessor<S>> chain)
    • setPostProcessingChain

      void setPostProcessingChain(PriorityList<CommandPostProcessor<S>> chain)
    • getAllShortcuts

      Collection<? extends Command<S>> getAllShortcuts()
    • getVisualizer

      CommandTreeVisualizer<S> getVisualizer()