Interface CommandManager
-
- All Known Subinterfaces:
CommandManager.Mutable
@DoNotStore public interface CommandManager
Registers and dispatches commands.The command manager may be replaced at any point during the game lifecycle when the client chooses to reload registries.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
CommandManager.Mutable
A mutable view of the command manager, allowing additional commands to be registered.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.Optional<CommandMapping>
commandMapping(java.lang.String alias)
Gets theCommandMapping
associated with the requested alias, if any.java.util.List<CommandCompletion>
complete(java.lang.String arguments)
Provides possible completions based on the input argument string.java.util.List<CommandCompletion>
complete(Subject subject, Audience receiver, java.lang.String arguments)
<T extends Subject & Audience>
java.util.List<CommandCompletion>complete(T subjectReceiver, java.lang.String arguments)
java.util.Set<java.lang.String>
knownAliases()
Gets all the command aliases known to this command manager.java.util.Set<CommandMapping>
knownMappings()
Gets all themappings
known to this command manager.java.util.Collection<org.spongepowered.plugin.PluginContainer>
plugins()
Gets aCollection
ofPluginContainer
s with commands registered.CommandResult
process(java.lang.String arguments)
Executes a command based on the provided arguments.CommandResult
process(Subject subject, Audience channel, java.lang.String arguments)
<T extends Subject & Audience>
CommandResultprocess(T subjectReceiver, java.lang.String arguments)
<T> java.util.Optional<CommandRegistrar<T>>
registrar(io.leangen.geantyref.TypeToken<T> type)
Get a registrar that will register commands oftype
to the active command manager.<T> java.util.Optional<CommandRegistrar<T>>
registrar(java.lang.Class<T> type)
Get a registrar that will register commands oftype
to the active command manager.void
updateCommandTreeForPlayer(ServerPlayer player)
Asks the server to send an updated client completion command tree to the specifiedServerPlayer
.
-
-
-
Method Detail
-
registrar
<T> java.util.Optional<CommandRegistrar<T>> registrar(java.lang.Class<T> type)
Get a registrar that will register commands oftype
to the active command manager.This allows for out-of-band command registrations between calls to
RegisterCommandEvent
, though where possible that event should be preferred.When commands are registered outside of events, changes will not be automatically reflected in client command views. To update any applicable clients, see
updateCommandTreeForPlayer(ServerPlayer)
.- Type Parameters:
T
- registrar type- Parameters:
type
- the registrar type- Returns:
- a registrar, if any is known for
type
-
registrar
<T> java.util.Optional<CommandRegistrar<T>> registrar(io.leangen.geantyref.TypeToken<T> type)
Get a registrar that will register commands oftype
to the active command manager.This allows for out-of-band command registrations between calls to
RegisterCommandEvent
, though where possible that event should be preferred.When commands are registered outside of events, changes will not be automatically reflected in client command views. To update any applicable clients, see
updateCommandTreeForPlayer(ServerPlayer)
.- Type Parameters:
T
- registrar type- Parameters:
type
- the registrar type- Returns:
- a registrar, if any is known for
type
-
process
CommandResult process(java.lang.String arguments) throws CommandException
Executes a command based on the provided arguments.- Parameters:
arguments
- The arguments to parse and execute- Returns:
- The
CommandResult
- Throws:
CommandException
- if something goes wrong during parsing or execution
-
process
<T extends Subject & Audience> CommandResult process(T subjectReceiver, java.lang.String arguments) throws CommandException
Executes a command based on the provided arguments, with a provided object that is both aSubject
for permission checks and aAudience
to return command messages to.- Type Parameters:
T
- The type of receiver- Parameters:
subjectReceiver
- TheSubject
&Audience
arguments
- The arguments to parse and execute- Returns:
- The
CommandResult
- Throws:
CommandException
- if something goes wrong during parsing or execution
-
process
CommandResult process(Subject subject, Audience channel, java.lang.String arguments) throws CommandException
Executes a command based on the provided arguments, with a providedSubject
for permission checks and a providedAudience
to return command messages to.- Parameters:
subject
- TheSubject
for permission checkschannel
- TheAudience
to return messages toarguments
- The arguments of the command- Returns:
- The
CommandResult
- Throws:
CommandException
- if something goes wrong during parsing or execution
-
complete
java.util.List<CommandCompletion> complete(java.lang.String arguments)
Provides possible completions based on the input argument string.- Parameters:
arguments
- The arguments- Returns:
- The completions
-
complete
<T extends Subject & Audience> java.util.List<CommandCompletion> complete(T subjectReceiver, java.lang.String arguments)
-
complete
java.util.List<CommandCompletion> complete(Subject subject, Audience receiver, java.lang.String arguments)
-
knownAliases
java.util.Set<java.lang.String> knownAliases()
Gets all the command aliases known to this command manager.- Returns:
- The known aliases
-
knownMappings
java.util.Set<CommandMapping> knownMappings()
Gets all themappings
known to this command manager.- Returns:
- The known mappings.
-
plugins
java.util.Collection<org.spongepowered.plugin.PluginContainer> plugins()
Gets aCollection
ofPluginContainer
s with commands registered.- Returns:
- A
Collection
ofPluginContainer
s.
-
commandMapping
java.util.Optional<CommandMapping> commandMapping(java.lang.String alias)
Gets theCommandMapping
associated with the requested alias, if any.- Parameters:
alias
- The alias to get the mapping for- Returns:
- The
CommandMapping
, if any
-
updateCommandTreeForPlayer
void updateCommandTreeForPlayer(ServerPlayer player)
Asks the server to send an updated client completion command tree to the specifiedServerPlayer
.This should be used sparingly as repeated calls may cause performance issues. Implementations may choose to ignore this call if it deems it unnecessary to send an update.
This method may return before the updates have been sent.
- Parameters:
player
- TheServerPlayer
to send the command tree to.
-
-