Package studio.mevera.imperat.command
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
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiondefault voidaddAliases(String... aliases) Adds aliases for the command using an array of alias strings.voidaddAliases(List<String> aliases) Sets the aliases of a commanddefault voidaddPathway(CommandPathway.Builder<S> builder) voidaddPathway(CommandPathway<S> usage) Adds a usage to the commandvoidaddPostProcessor(@NotNull CommandPostProcessor<S> postProcessor) Sets a post-processor for the commandvoidaddPreProcessor(@NotNull CommandPreProcessor<S> preProcessor) Sets a pre-processor for the commandvoidaddShortcut(Command<S> shortcut) Adds a shortcut to this command.voidaddSubCommand(Command<S> command, String attachTo) Injects a created-subcommand directly into the parent's command usages.aliases()default AnnotatedArgument<S>Casts the parameter to a parameter with annotationsCasts the parameter to a subcommand/commandstatic <S extends CommandSource>
Command.Builder<S>create(@NotNull Imperat<S> imperat, @Nullable Command<S> parent, int position, @NotNull String name) static <S extends CommandSource>
Command.Builder<S>create(@NotNull Imperat<S> imperat, @Nullable Command<S> parent, int position, @NotNull String name, @Nullable ParseElement<?> annotatedElement) static <S extends CommandSource>
Command.Builder<S>static <S extends CommandSource>
Command.Builder<S>create(@NotNull Imperat<S> imperat, @Nullable Command<S> parent, @NotNull String name, @Nullable ParseElement<?> annotatedElement) static <S extends CommandSource>
Command.Builder<S>static <S extends CommandSource>
Command.Builder<S>create(@NotNull Imperat<S> imperat, String name, @Nullable ParseElement<?> annotatedElement) @NotNull TreeExecutionResult<S>execute(ExecutionContext<S> context) Traverses theCommandTreelinked to this command object, directly executing the most suitable pathway that matches the context input by the user.default Stringformat()Formats the usage parameterCollection<? extends Command<S>>@Nullable ParseElement<?>Collection<? extends CommandPathway<S>>@NotNull CommandPathway<S>default @NotNull DefaultValueProvider@NotNull DescriptionRetrieves the current description associated with this entity.getName()getShortcut(String shortcutName) @UnmodifiableView Collection<? extends Command<S>>getSubCommand(String name, boolean recursive) @NotNull Collection<? extends Command<S>>default @Nullable CommandPathway<S>getUsage(Predicate<CommandPathway<S>> usagePredicate) default booleandefault booleanimperat()default booleandefault booleanisFlag()default booleanisGreedy()booleanwhether to ignore permission checks on the auto-completion of command and sub commands or notdefault booleanbooleanisSecret()default booleanvoidpostProcess(@NotNull ExecutionContext<S> context) Executes the post-processing instructions inCommandPostProcessorvoidpreProcess(@NotNull CommandContext<S> context) Executes the pre-processing instructions inCommandPreProcessorvoidsetDefaultPathway(@NotNull CommandPathway<S> usage) Sets the default command usage representation.voidsetIgnoreACPermissions(boolean ignore) if true, it will ignore permission checks on the auto-completion of command and sub commandsdefault voidsetPosition(int position) Sets the position of this command in a syntax DO NOT USE THIS FOR ANY REASON unless it's necessary to do sovoidvoidvoidsetSecret(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 suggestionstree()default @NotNull ArgumentType<S,?> type()Retrieves the parameter type associated with the current command, including its name and any aliases.voidDebugs or visualizes all tree nodes fromCommandTree.default TypeWrap<?>Methods inherited from interface studio.mevera.imperat.command.arguments.Argument
addValidator, asFlagParameter, asNumeric, getParent, getPosition, getSuggestionResolver, getValidators, greedyLimit, isCommand, isGreedyString, isNumeric, isRequired, setFormat, setParent, similarTo, validate, valueTypeMethods inherited from interface studio.mevera.imperat.BaseThrowableHandler
handleExecutionErrorMethods inherited from interface studio.mevera.imperat.command.DescriptionHolder
describe, describeMethods inherited from interface studio.mevera.imperat.permissions.PermissionHolder
getPermissionsData, getPrimaryPermission, setPermissionDataMethods inherited from interface studio.mevera.imperat.ThrowableHandler
getErrorHandlerFor, setErrorHandler
-
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
-
getName
String getName()- Specified by:
getNamein interfaceArgument<S extends CommandSource>- Returns:
- The name of the command
-
aliases
- Returns:
- The aliases for this commands
-
getAnnotatedElement
- Returns:
- the annotated element this object got extracted from, null if it was created from a
ParseElement
-
isAnnotated
default boolean isAnnotated()- Specified by:
isAnnotatedin interfaceArgument<S extends CommandSource>- Returns:
- Whether this usage parameter has been constructed using the annotations through methods or not
-
asAnnotatedArgument
Description copied from interface:ArgumentCasts the parameter to a parameter with annotations- Specified by:
asAnnotatedArgumentin interfaceArgument<S extends CommandSource>- Returns:
- the parameter as annotated one
- See Also:
-
addAliases
Sets the aliases of a command- Parameters:
aliases- the aliases for te command to set
-
addAliases
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
- 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 fromCommandTree. If the command is not a root command, nothing will be visualized. -
execute
@NotNull @NotNull TreeExecutionResult<S> execute(ExecutionContext<S> context) throws CommandException Traverses theCommandTreelinked 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
Description copied from interface:DescriptionHolderRetrieves the current description associated with this entity.- Specified by:
getDescriptionin interfaceDescriptionHolder- Returns:
- The description of a command
-
type
Retrieves the parameter type associated with the current command, including its name and any aliases.- Specified by:
typein interfaceArgument<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:
setPositionin interfaceArgument<S extends CommandSource>- Parameters:
position- the position to set
-
getDefaultValueSupplier
- Specified by:
getDefaultValueSupplierin interfaceArgument<S extends CommandSource>- Returns:
- the default value if it's input is not present in case of the parameter being optional
-
addPreProcessor
Sets a pre-processor for the command- Parameters:
preProcessor- the pre-processor for the command
-
preProcess
Executes the pre-processing instructions inCommandPreProcessor- Parameters:
context- the context- Throws:
CommandException
-
addPostProcessor
Sets a post-processor for the command- Parameters:
postProcessor- the post-processor for the command
-
postProcess
Executes the post-processing instructions inCommandPostProcessor- Parameters:
context- the context- Throws:
CommandException
-
getDefaultPathway
- Returns:
- the default usage of the command without any args
-
setDefaultPathway
Sets the default command usage representation.- Parameters:
usage- the default command usage instance to be set, which must not be null
-
addPathway
Adds a usage to the command- Parameters:
usage- the usageCommandPathwayof the command
-
addPathway
-
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
AutoCompleterthat handles all auto-completes for this command
-
addSubCommand
Injects a created-subcommand directly into the parent's command usages.- Parameters:
command- the subcommand to inject
-
getSubCommand
- Parameters:
name- the name of the wanted sub-commandrecursive- whether to search for the subcommand deeply not just in the direct subcommands of this command- Returns:
- the sub-command of specific name
-
getSubCommands
- Returns:
- the subcommands of this command
-
getUsage
-
hasParent
default boolean hasParent() -
isSubCommand
default boolean isSubCommand() -
getShortcut
- 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
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
- Specified by:
wrappedTypein interfaceArgument<S extends CommandSource>- Returns:
- the value valueType of this parameter
-
isOptional
default boolean isOptional()- Specified by:
isOptionalin interfaceArgument<S extends CommandSource>- Returns:
- whether this is an optional argument
-
isGreedy
default boolean isGreedy()- Specified by:
isGreedyin interfaceArgument<S extends CommandSource>- Returns:
- checks whether this parameter consumes all the args input after it.
-
isFlag
default boolean isFlag()- Specified by:
isFlagin interfaceArgument<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
Description copied from interface:ArgumentCasts the parameter to a subcommand/command- Specified by:
asCommandin interfaceArgument<S extends CommandSource>- Returns:
- the parameter as a command
-
format
Formats the usage parameter- Specified by:
formatin interfaceArgument<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 commandsotherwise, 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
-
setPostProcessingChain
-
getAllShortcuts
Collection<? extends Command<S>> getAllShortcuts() -
getVisualizer
CommandTreeVisualizer<S> getVisualizer()
-