public class CommandRegistry extends Object implements Registry
CommandRegistry is used to register custom commands. Use the register()
method to pass a object with a reference to your PluginCommandPlugin.
If the name used in the Command constructor is not unique, the registry will try to prefix the command with the
lower cased version of your plugin name (ex: nukkitx:commnad).
You may also use the SimpleCommand annotations to create your Command,
in which case you would use registerSimpleCommand()
method to register the command.
PluginCommand| Modifier and Type | Method and Description |
|---|---|
void |
close() |
com.nukkitx.protocol.bedrock.packet.AvailableCommandsPacket |
createPacketFor(Player player)
Used internally to obtain the AvailableCommandsPacket to send to a client.
|
boolean |
dispatch(CommandSender sender,
String commandLine)
Used to dispatch a command.
|
static CommandRegistry |
get()
Gets the instance of the CommandRegistry.
|
Command |
getCommand(String name)
Returns a
Command object by looking it up via name or alias |
Set<String> |
getCommandList()
Returns all registered command and alias Strings
|
PluginIdentifiableCommand |
getPluginCommand(String name)
Used to obtain a Plugin Command from the registry.
|
Map<String,Command> |
getRegisteredCommands()
Used to obtain a Mapping of String name to Command objects.
|
boolean |
isClosed() |
boolean |
isRegistered(Command cmd)
Used to check if a command is registered with the CommandRegistry
|
boolean |
isRegistered(String cmd)
Used to check if a command is registered with the CommandRegistry
|
void |
register(PluginContainer plugin,
Command command)
Method used to register a custom command.
|
void |
registerSimpleCommand(PluginContainer plugin,
Object simpleCommand)
Used to register
SimpleCommands created using the annotations found in cn.nukkit.command.simple
package. |
void |
registerVanilla() |
void |
unregister(PluginContainer plugin,
String name)
Method used to unregister a command.
|
void |
unregisterAlias(PluginContainer plugin,
String alias)
Unregisters an alias for one of your Plugin's
Commands, or for a
built-in command. |
public void registerVanilla()
public static CommandRegistry get()
public void register(PluginContainer plugin, Command command) throws RegistryException
Method used to register a custom command. Any aliases that are defined in the
CommandData created during the Command construction are also
registered. Your Command should extend from PluginCommand.
If you are using the SimpleCommand
annotations to create your command, you should register it using
registerSimpleCommand().
plugin - A reference to your Plugincommand - The Command object of your Command.RegistryException - if command is unable to be registeredpublic void registerSimpleCommand(PluginContainer plugin, Object simpleCommand)
SimpleCommands created using the annotations found in cn.nukkit.command.simple
package.plugin - Reference to your PluginsimpleCommand - Object reference to the class containing the SimpleCommand annotations.public void unregister(PluginContainer plugin, String name) throws RegistryException
plugin - A reference to your PluginContainer instancename - The command name, or alias for the commandRegistryException - if unregistering was unsuccessfulpublic void unregisterAlias(PluginContainer plugin, String alias) throws RegistryException
Commands, or for a
built-in command.plugin - A reference to your Pluginalias - The alias to unregisterRegistryException - on attempt to unregister another Plugin's aliaspublic boolean isClosed()
public void close()
throws RegistryException
close in interface RegistryRegistryExceptionpublic Command getCommand(String name)
Command object by looking it up via name or aliasname - The name or alias of the commandCommand object, if known, otherwise null.public Set<String> getCommandList()
Set of String objects, of all known command names and aliases.public Map<String,Command> getRegisteredCommands()
ImmutableMap of String command names to Command objects.public boolean isRegistered(Command cmd)
cmd - A reference to the Command objecttrue if registered, false otherwisepublic boolean isRegistered(String cmd)
cmd - The command or alias nametrue if registered, false otherwisepublic PluginIdentifiableCommand getPluginCommand(String name)
name - The command name or aliasPluginCommand associated with the command name, or nullpublic boolean dispatch(CommandSender sender, String commandLine)
sender - The CommandSender source of the command.commandLine - The full command line to execute, including the command name.true if the command was located and executed, false otherwise.public com.nukkitx.protocol.bedrock.packet.AvailableCommandsPacket createPacketFor(Player player)
player - The player receiving the packetCopyright © 2020. All rights reserved.