Interface CommandRegistrar<T>
-
- Type Parameters:
T- The type of command interface this handles.
@DoNotStore public interface CommandRegistrar<T>
CommandRegistrars are the entry point for plugins wishing to provide their own command framework. TheCommandManagerwill proxy calls to the correct registrar and will handle the finalCommandResult.This interface defines a way to register commands. This registration method must call
CommandManager.Mutable.registerAlias(CommandRegistrar, PluginContainer, CommandTreeNode.Root, String, String...)to indicate that they wish to take control of certain aliases. Beyond this call, theCommandRegistrarwill only need to retain the link between theCommandMappingand its command (of type)Tto execute, as theCommandManagerwill always supply the mapping of the command being invoked at runtime. The alias that was matched will also be supplied.For a command that wishes to investigate the command string that was executed, they may investigate the context in
CommandCause.cause(), looking for theEventContextKeys.COMMANDcontext key.Command frameworks are free to choose how they parse commands. However, a framework's
CommandRegistrarmust do the following in order to be successfully registered and receive their commands:- The registrar must have its type registered during the
RegisterRegistryValueEventforCommandRegistrarTypes; and - Commands registered through the registrar must be synced back
to the
CommandManager, otherwise such commands will not be passed back to this registrar.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleancanExecute(CommandCause cause, CommandMapping mapping)Gets whether the givenCommandCausecan execute the command associated with the givenCommandMapping.java.util.List<CommandCompletion>complete(CommandCause cause, CommandMapping mapping, java.lang.String command, java.lang.String arguments)Provides a list of completions associated with the provided argument string.java.util.Optional<Component>help(CommandCause cause, CommandMapping mapping)Returns help text for the invoked command, if one is available.CommandResultprocess(CommandCause cause, CommandMapping mapping, java.lang.String command, java.lang.String arguments)Process the provided command.CommandMappingregister(org.spongepowered.plugin.PluginContainer container, T command, java.lang.String primaryAlias, java.lang.String... secondaryAliases)Registers a command.default java.util.Optional<Component>shortDescription(CommandCause cause, CommandMapping mapping)Returns a short description for the invoked command, if one is available.CommandRegistrarType<T>type()Get the type defining this command registrar.
-
-
-
Method Detail
-
type
CommandRegistrarType<T> type()
Get the type defining this command registrar.- Returns:
- the type
-
register
CommandMapping register(org.spongepowered.plugin.PluginContainer container, T command, java.lang.String primaryAlias, java.lang.String... secondaryAliases) throws CommandFailedRegistrationException
Registers a command.- Parameters:
container- ThePluginContainerperforming the registrationcommand- The command to registerprimaryAlias- The primary aliassecondaryAliases- Any secondary aliases. May be empty.- Returns:
- The
CommandMapping - Throws:
CommandFailedRegistrationException- if the registration failed
-
process
CommandResult process(CommandCause cause, CommandMapping mapping, java.lang.String command, java.lang.String arguments) throws CommandException
Process the provided command.Note for implementors: the provided
commandwill be the one registered as the primary alias when registering with theCommandManager.- Parameters:
cause- TheCommandCausethat caused the command to be executedmapping- TheCommandMappingfor the command being invokedcommand- The alias that was used to invoke the commandarguments- The arguments of the command (that is, the raw string with the command alias removed, so if/sponge test test2is invoked, arguments will containtest test2.)- Returns:
- The
CommandResult - Throws:
CommandException- if there is an error executing the command
-
complete
java.util.List<CommandCompletion> complete(CommandCause cause, CommandMapping mapping, java.lang.String command, java.lang.String arguments) throws CommandException
Provides a list of completions associated with the provided argument string.See
process(CommandCause, CommandMapping, String, String)for any implementation notes.- Parameters:
cause- TheCommandCausethat caused the command to be executedmapping- TheCommandMappingfor the command being invokedcommand- The alias that was used to invoke the commandarguments- The arguments of the command (that is, the raw string with the command alias removed, so if/sponge test test2is invoked, arguments will containtest test2.)- Returns:
- The completions
- Throws:
CommandException- if there is an error providing the suggestions
-
shortDescription
default java.util.Optional<Component> shortDescription(CommandCause cause, CommandMapping mapping)
Returns a short description for the invoked command, if one is available.A good short description is not necessarily help, rather, it should be a short description of the command's function. This short description may also be part of the
standard helpfor the function.It is recommended that any description here is kept very short as such a description may be used in a command listing.
- Parameters:
cause- TheCommandCausethat caused the command to be executedmapping- TheCommandMappingthat is associated with the command- Returns:
- The help, if any
-
help
java.util.Optional<Component> help(CommandCause cause, CommandMapping mapping)
Returns help text for the invoked command, if one is available.- Parameters:
cause- TheCommandCausethat caused the command to be executedmapping- TheCommandMappingthat is associated with the command- Returns:
- The help, if any
-
canExecute
boolean canExecute(CommandCause cause, CommandMapping mapping)
Gets whether the givenCommandCausecan execute the command associated with the givenCommandMapping.- Parameters:
cause- TheCommandCausemapping- TheCommandMapping- Returns:
- true of the command can execute the command
-
-