Package studio.mevera.imperat.command
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
-
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 commandvoidaddPostProcessor(@NotNull CommandPostProcessor<S> postProcessor) Sets a post-processor for the commandvoidaddPreProcessor(@NotNull CommandPreProcessor<S> preProcessor) Sets a pre-processor for the commandvoidaddSubCommand(Command<S> command, AttachmentMode attachmentMode) Injects a created-subcommand directly into the parent's command usages.default voidaddSubCommandUsage(String subCommand, List<String> aliases, CommandUsage.Builder<S> usage) voidaddSubCommandUsage(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 theCommandUsageto the sub-commanddefault voidaddSubCommandUsage(String subCommand, CommandUsage.Builder<S> usage) Creates and adds a new sub-command (if it doesn't exist) then add theCommandUsageto the sub-commanddefault voidaddSubCommandUsage(String subCommand, CommandUsage.Builder<S> usage, AttachmentMode attachmentMode) default voidaddUsage(CommandUsage.Builder<S> builder) default voidaddUsage(CommandUsage.Builder<S> builder, boolean help) voidaddUsage(CommandUsage<S> usage) Adds a usage to the commandaliases()Casts the parameter to a subcommand/command@NotNull CommandPathSearch<S>contextMatch(Context<S> context) Traverses theCommandTreelinked to this command object, searching for the most suitable usage that best suites the context input by the userstatic <S extends Source>
Command.Builder<S>create(@NotNull Imperat<S> imperat, @Nullable Command<S> parent, int position, @NotNull String name) static <S extends Source>
Command.Builder<S>static <S extends Source>
Command.Builder<S>@NotNull DescriptionRetrieves the current description associated with this entity.default Stringformat()Formats the usage parameter@NotNull CommandUsage<S>default @NotNull OptionalValueSupplier@NotNull CommandUsage<S>Retrieves a usage with no args for this commanddefault @Nullable String@NotNull CommandUsage<S>getSubCommand(String name) @NotNull Collection<? extends Command<S>>default @Nullable CommandUsage<S>getUsage(Predicate<CommandUsage<S>> usagePredicate) default booleandefault booleanvoidignoreACPermissions(boolean ignore) if true, it will ignore permission checks on the auto-completion of command and sub commandsimperat()default booleanisFlag()default booleanisGreedy()booleanwhether to ignore permission checks on the auto-completion of command and sub commands or notdefault booleandefault booleanname()default voidposition(int position) Sets the position of this command in a syntax DO NOT USE THIS FOR ANY REASON unless it's necessary to do sovoidpostProcess(@NotNull Imperat<S> api, @NotNull ExecutionContext<S> context, @NotNull CommandUsage<S> usage) Executes the post-processing instructions inCommandPostProcessorvoidpreProcess(@NotNull Imperat<S> api, @NotNull Context<S> context, @NotNull CommandUsage<S> usage) Executes the pre-processing instructions inCommandPreProcessorvoidregisterSubCommand(Command<S> subCommand) voidsetDefaultUsage(@NotNull CommandUsage<S> usage) Sets the default command usage representation.voidvoidtree()default @NotNull ParameterType<S,?> type()Retrieves the parameter type associated with the current command, including its name and any aliases.Collection<? extends CommandUsage<S>>usages()voidDebugs or visualizes all tree nodes fromCommandTree.default TypeWrap<?>Methods inherited from interface studio.mevera.imperat.BaseThrowableHandler
handleExecutionThrowableMethods inherited from interface studio.mevera.imperat.command.parameters.CommandParameter
asAnnotated, asFlagParameter, asNumeric, copyWithDifferentPosition, getSinglePermission, getSuggestionResolver, isAnnotated, isCommand, isGreedyString, isNumeric, isRequired, parent, parent, position, setFormat, setSinglePermission, similarTo, valueTypeMethods inherited from interface studio.mevera.imperat.command.DescriptionHolder
describe, describeMethods inherited from interface studio.mevera.imperat.FlagRegistrar
getFlagFromRaw, getRegisteredFlags, registerFlagMethods inherited from interface studio.mevera.imperat.command.PermissionHolder
addPermission, getPermissions, hasPermissionMethods inherited from interface studio.mevera.imperat.ThrowableHandler
getThrowableResolver, setThrowableResolver
-
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
-
name
String name()- Specified by:
namein interfaceCommandParameter<S extends Source>- Returns:
- The name of the command
-
aliases
- Returns:
- The aliases for this commands
-
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. -
contextMatch
Traverses theCommandTreelinked 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
Description copied from interface:DescriptionHolderRetrieves the current description associated with this entity.- Specified by:
descriptionin 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 interfaceCommandParameter<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:
positionin interfaceCommandParameter<S extends Source>- Parameters:
position- the position to set
-
getDefaultValueSupplier
- Specified by:
getDefaultValueSupplierin interfaceCommandParameter<S extends Source>- 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
void preProcess(@NotNull @NotNull Imperat<S> api, @NotNull @NotNull Context<S> context, @NotNull @NotNull CommandUsage<S> usage) throws ImperatException Executes the pre-processing instructions inCommandPreProcessor- Parameters:
api- the apicontext- the contextusage- the usage detected being used- Throws:
ImperatException
-
addPostProcessor
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 inCommandPostProcessor- Parameters:
api- the apicontext- the contextusage- the usage detected being used- Throws:
ImperatException
-
getEmptyUsage
Retrieves a usage with no args for this command- Returns:
- A usage with empty parameters.
-
getDefaultUsage
- Returns:
- the default usage of the command without any args
-
setDefaultUsage
Sets the default command usage representation.- Parameters:
usage- the default command usage instance to be set, which must not be null
-
addUsage
Adds a usage to the command- Parameters:
usage- the usageCommandUsageof the command
-
addUsage
-
addUsage
-
usages
Collection<? extends CommandUsage<S>> usages()- Returns:
- All
CommandUsagethat were registered to this command by the user
-
getMainUsage
- Returns:
- the usage that doesn't include any subcommands, only required parameters
-
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 injectattachmentMode- seeAttachmentMode
-
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 theCommandUsageto the sub-command- Parameters:
subCommand- the sub-command's unique namealiases- of the subcommandusage- the usageattachmentMode- seeAttachmentMode
-
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
Creates and adds a new sub-command (if it doesn't exist) then add theCommandUsageto the sub-command- Parameters:
subCommand- the sub-command's unique nameusage- the usage
-
getSubCommand
- Parameters:
name- the name of the wanted sub-command- Returns:
- the sub-command of specific name
-
getSubCommands
- Returns:
- the subcommands of this command
-
getUsage
-
hasParent
default boolean hasParent() -
isSubCommand
default boolean isSubCommand() -
wrappedType
- Specified by:
wrappedTypein interfaceCommandParameter<S extends Source>- Returns:
- the value valueType of this parameter
-
isOptional
default boolean isOptional()- Specified by:
isOptionalin interfaceCommandParameter<S extends Source>- Returns:
- whether this is an optional argument
-
isGreedy
default boolean isGreedy()- Specified by:
isGreedyin interfaceCommandParameter<S extends Source>- Returns:
- checks whether this parameter consumes all the args input after it.
-
isFlag
default boolean isFlag()- Specified by:
isFlagin interfaceCommandParameter<S extends Source>- Returns:
- checks whether this parameter is a flag
-
asCommand
Description copied from interface:CommandParameterCasts the parameter to a subcommand/command- Specified by:
asCommandin interfaceCommandParameter<S extends Source>- Returns:
- the parameter as a command
-
format
Formats the usage parameter- Specified by:
formatin interfaceCommandParameter<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 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
-
registerSubCommand
-
getMainPermission
-
getPreProcessors
CommandProcessingChain<S,CommandPreProcessor<S>> getPreProcessors() -
getPostProcessors
CommandProcessingChain<S,CommandPostProcessor<S>> getPostProcessors() -
setPreProcessingChain
-
setPostProcessingChain
-