public class SimpleDispatcher extends java.lang.Object implements Dispatcher
Dispatcher
.Constructor and Description |
---|
SimpleDispatcher()
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
call(java.lang.String arguments,
CommandLocals locals,
java.lang.String[] parentCommands)
Execute the correct command based on the input.
|
boolean |
contains(java.lang.String alias)
Returns whether the dispatcher contains a registered command for the given alias.
|
CommandMapping |
get(java.lang.String alias)
Get the
CommandCallable associated with an alias. |
java.util.Set<java.lang.String> |
getAliases()
Get a list of all the command aliases, which includes the primary alias.
|
java.util.Set<CommandMapping> |
getCommands()
Get a list of commands.
|
SimpleDescription |
getDescription()
Get an object describing this command.
|
java.util.Set<java.lang.String> |
getPrimaryAliases()
Get a list of primary aliases.
|
java.util.List<java.lang.String> |
getSuggestions(java.lang.String arguments,
CommandLocals locals)
Get a list of suggestions based on input.
|
void |
registerCommand(CommandCallable callable,
java.lang.String... alias)
Register a command with this dispatcher.
|
boolean |
testPermission(CommandLocals locals)
Test whether this command can be executed with the given context.
|
public void registerCommand(CommandCallable callable, java.lang.String... alias)
Dispatcher
registerCommand
in interface Dispatcher
callable
- the command executoralias
- a list of aliases, where the first alias is the primary namepublic java.util.Set<CommandMapping> getCommands()
Dispatcher
The returned collection cannot be modified.
getCommands
in interface Dispatcher
public java.util.Set<java.lang.String> getAliases()
Dispatcher
A command may have more than one alias assigned to it. The returned collection cannot be modified.
getAliases
in interface Dispatcher
public java.util.Set<java.lang.String> getPrimaryAliases()
Dispatcher
The returned collection cannot be modified.
getPrimaryAliases
in interface Dispatcher
public boolean contains(java.lang.String alias)
Dispatcher
contains
in interface Dispatcher
alias
- the aliaspublic CommandMapping get(java.lang.String alias)
Dispatcher
CommandCallable
associated with an alias. Returns
null if no command is named by the given alias.get
in interface Dispatcher
alias
- the aliaspublic java.lang.Object call(java.lang.String arguments, CommandLocals locals, java.lang.String[] parentCommands) throws CommandException
CommandCallable
The implementing class must perform the necessary permission checks.
call
in interface CommandCallable
arguments
- the argumentslocals
- the localsparentCommands
- a list of parent commands, with the first most entry being the top-level commandCommandException
- thrown on a command errorpublic java.util.List<java.lang.String> getSuggestions(java.lang.String arguments, CommandLocals locals) throws CommandException
CommandCompleter
getSuggestions
in interface CommandCompleter
arguments
- the arguments entered up to this pointlocals
- the localsCommandException
- thrown if there was a parsing errorpublic SimpleDescription getDescription()
CommandCallable
getDescription
in interface CommandCallable
public boolean testPermission(CommandLocals locals)
CommandCallable
testPermission
in interface CommandCallable
locals
- the locals