Class CommandRegistry

java.lang.Object
org.cloudburstmc.server.registry.CommandRegistry
All Implemented Interfaces:
org.cloudburstmc.api.registry.Registry

public class CommandRegistry extends Object implements org.cloudburstmc.api.registry.Registry

CommandRegistry is used to register custom commands. Use the register() method to pass a PluginCommand object with a reference to your Plugin. 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 Details

    • registerVanilla

      public void registerVanilla()
    • get

      public static CommandRegistry 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.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().

      Parameters:
      plugin - A reference to your Plugin
      command - The Command object 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 register SimpleCommands created using the annotations found in cn.nukkit.command.simple package.
      Parameters:
      plugin - Reference to your Plugin
      simpleCommand - 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.RegistryException
      Method 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 your PluginContainer instance
      name - 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.RegistryException
      Unregisters an alias for one of your Plugin's Commands, or for a built-in command.
      Parameters:
      plugin - A reference to your Plugin
      alias - 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:
      close in interface org.cloudburstmc.api.registry.Registry
      Throws:
      org.cloudburstmc.api.registry.RegistryException
    • getCommand

      public Command getCommand(String name)
      Returns a Command object by looking it up via name or alias
      Parameters:
      name - The name or alias of the command
      Returns:
      The Command object, if known, otherwise null.
    • getCommandList

      public Set<String> getCommandList()
      Returns all registered command and alias Strings
      Returns:
      A Set of String objects, of all known command names and aliases.
    • getRegisteredCommands

      public Map<String,​Command> getRegisteredCommands()
      Used to obtain a Mapping of String name to Command objects. Note that this map does not include aliases.
      Returns:
      An ImmutableMap of String command names to Command objects.
    • isRegistered

      public boolean isRegistered(Command cmd)
      Used to check if a command is registered with the CommandRegistry
      Parameters:
      cmd - A reference to the Command object
      Returns:
      true if registered, false otherwise
    • isRegistered

      public boolean isRegistered(String cmd)
      Used to check if a command is registered with the CommandRegistry
      Parameters:
      cmd - The command or alias name
      Returns:
      true if registered, false otherwise
    • getPluginCommand

      public PluginIdentifiableCommand getPluginCommand(String name)
      Used to obtain a Plugin Command from the registry.
      Parameters:
      name - The command name or alias
      Returns:
      The PluginCommand associated with the command name, or null
    • dispatch

      public boolean dispatch(org.cloudburstmc.api.command.CommandSender sender, String commandLine)
      Used to dispatch a command. This method should be used over obtaining an object reference to a Command and calling execute yourself.
      Parameters:
      sender - The CommandSender source of the command.
      commandLine - The full command line to execute, including the command name.
      Returns:
      true if the command was located and executed, false otherwise.
    • 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