Class CommandRegistry
- All Implemented Interfaces:
org.cloudburstmc.api.registry.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.
- Since:
- API 2.0.0
- Author:
- Sleepybear
- See Also:
PluginCommand
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()com.nukkitx.protocol.bedrock.packet.AvailableCommandsPacketcreatePacketFor(CloudPlayer player)Used internally to obtain the AvailableCommandsPacket to send to a client.booleanUsed to dispatch a command.static CommandRegistryget()Gets the instance of the CommandRegistry.getCommand(String name)Returns aCommandobject by looking it up via name or aliasReturns all registered command and alias StringsgetPluginCommand(String name)Used to obtain a Plugin Command from the registry.Used to obtain a Mapping of String name to Command objects.booleanisClosed()booleanisRegistered(String cmd)Used to check if a command is registered with the CommandRegistrybooleanisRegistered(Command cmd)Used to check if a command is registered with the CommandRegistryvoidMethod used to register a custom command.voidregisterSimpleCommand(org.cloudburstmc.api.plugin.PluginContainer plugin, Object simpleCommand)Used to registerSimpleCommands created using the annotations found incn.nukkit.command.simplepackage.voidvoidunregister(org.cloudburstmc.api.plugin.PluginContainer plugin, String name)Method used to unregister a command.voidunregisterAlias(org.cloudburstmc.api.plugin.PluginContainer plugin, String alias)Unregisters an alias for one of your Plugin'sCommands, or for a built-in command.
-
Method Details
-
registerVanilla
public void registerVanilla() -
get
Gets the instance of the CommandRegistry.- Returns:
- the CommandRegistry singleton
-
register
public void register(org.cloudburstmc.api.plugin.PluginContainer plugin, Command command) throws org.cloudburstmc.api.registry.RegistryExceptionMethod used to register a custom command. Any aliases that are defined in the
CommandDatacreated during the Command construction are also registered. Your Command should extend fromPluginCommand.If you are using the
SimpleCommandannotations to create your command, you should register it usingregisterSimpleCommand().- Parameters:
plugin- A reference to yourPlugincommand- TheCommandobject of your Command.- Throws:
org.cloudburstmc.api.registry.RegistryException- if command is unable to be registered
-
registerSimpleCommand
public void registerSimpleCommand(org.cloudburstmc.api.plugin.PluginContainer plugin, Object simpleCommand)Used to registerSimpleCommands created using the annotations found incn.nukkit.command.simplepackage.- Parameters:
plugin- Reference to yourPluginsimpleCommand- Object reference to the class containing the SimpleCommand annotations.
-
unregister
public void unregister(org.cloudburstmc.api.plugin.PluginContainer plugin, String name) throws org.cloudburstmc.api.registry.RegistryExceptionMethod used to unregister a command. Please note that a Plugin may only unregister it's own commands, or a built in command.- Parameters:
plugin- A reference to yourPluginContainerinstancename- The command name, or alias for the command- Throws:
org.cloudburstmc.api.registry.RegistryException- if unregistering was unsuccessful
-
unregisterAlias
public void unregisterAlias(org.cloudburstmc.api.plugin.PluginContainer plugin, String alias) throws org.cloudburstmc.api.registry.RegistryExceptionUnregisters an alias for one of your Plugin'sCommands, or for a built-in command.- Parameters:
plugin- A reference to yourPluginalias- The alias to unregister- Throws:
org.cloudburstmc.api.registry.RegistryException- on attempt to unregister another Plugin's alias
-
isClosed
public boolean isClosed() -
close
public void close() throws org.cloudburstmc.api.registry.RegistryException- Specified by:
closein interfaceorg.cloudburstmc.api.registry.Registry- Throws:
org.cloudburstmc.api.registry.RegistryException
-
getCommand
Returns aCommandobject by looking it up via name or alias- Parameters:
name- The name or alias of the command- Returns:
- The
Commandobject, if known, otherwisenull.
-
getCommandList
Returns all registered command and alias Strings- Returns:
- A
Setof String objects, of all known command names and aliases.
-
getRegisteredCommands
Used to obtain a Mapping of String name to Command objects. Note that this map does not include aliases.- Returns:
- An
ImmutableMapof String command names toCommandobjects.
-
isRegistered
Used to check if a command is registered with the CommandRegistry- Parameters:
cmd- A reference to the Command object- Returns:
trueif registered,falseotherwise
-
isRegistered
Used to check if a command is registered with the CommandRegistry- Parameters:
cmd- The command or alias name- Returns:
trueif registered,falseotherwise
-
getPluginCommand
Used to obtain a Plugin Command from the registry.- Parameters:
name- The command name or alias- Returns:
- The
PluginCommandassociated with the command name, ornull
-
dispatch
Used to dispatch a command. This method should be used over obtaining an object reference to a Command and calling execute yourself.- Parameters:
sender- TheCommandSendersource of the command.commandLine- The full command line to execute, including the command name.- Returns:
trueif the command was located and executed,falseotherwise.
-
createPacketFor
public com.nukkitx.protocol.bedrock.packet.AvailableCommandsPacket createPacketFor(CloudPlayer player)Used internally to obtain the AvailableCommandsPacket to send to a client.- Parameters:
player- The player receiving the packet- Returns:
- The Packet
-