CommandRegistry
CommandRegistry
Section titled “CommandRegistry”Package: com.hypixel.hytale.server.core.command.system
public class CommandRegistry extends Registry<CommandRegistration>A plugin-scoped proxy for registering chat/console commands. Obtained via PluginBase.getCommandRegistry(). All registrations made through this registry are automatically unregistered when the owning plugin shuts down.
Constructor
Section titled “Constructor”public CommandRegistry(@Nonnull List<BooleanConsumer> registrations, BooleanSupplier precondition, String preconditionMessage, PluginBase plugin)Constructed internally by PluginBase. The plugin reference is stored so that each registered command can be associated with its owning plugin via command.setOwner(plugin). The precondition supplier checks that the plugin is in an active state.
Methods
Section titled “Methods”registerCommand
Section titled “registerCommand”public CommandRegistration registerCommand(@Nonnull AbstractCommand command)Registers a command with the server’s CommandManager. This method:
- Calls
checkPrecondition()— throwsIllegalStateExceptionif the plugin is not in an active state. - Sets the command’s owner to the plugin (
command.setOwner(this.plugin)), if the plugin reference is non-null. This triggers auto-permission generation (see below). - Delegates to
CommandManager.get().register(command)to perform the actual registration with the server’s command dispatcher. - Wraps the returned
CommandRegistrationin the plugin-scoped Registry lifecycle viasuper.register(), ensuring the command is unregistered on plugin shutdown.
Returns a CommandRegistration handle. Call registration.unregister() to remove the command before plugin shutdown, or let automatic cleanup handle it.
Parameters:
command— An AbstractCommand subclass defining the command’s name, arguments, permissions, and execution logic.
Throws:
IllegalStateException— if the plugin is not in an active state (precondition fails) or if the registry has been shut down.
Auto-Permission Generation
Section titled “Auto-Permission Generation”When registerCommand() sets the command’s owner via AbstractCommand.setOwner(), permissions are auto-generated for the command and all its subcommands. The permission string is derived from the plugin’s base permission:
{plugin.getBasePermission()}.command.{commandName}For example, a plugin with manifest group com.example and name myplugin has a base permission of com.example.myplugin. A command named spawn registered through that plugin receives the permission:
com.example.myplugin.command.spawnSubcommands append their name to the parent command’s permission:
com.example.myplugin.command.spawn.setcom.example.myplugin.command.spawn.removeYou can override auto-generated permissions by calling AbstractCommand.requirePermission() before registration. See AbstractCommand — Permission Methods for details.
Delegation to CommandManager
Section titled “Delegation to CommandManager”The CommandManager is the server-level singleton responsible for command dispatch. When CommandRegistry delegates to CommandManager.get().register(command), the command manager:
- Indexes the command by name and all aliases.
- Makes the command available for tab completion and execution via chat or console.
- Returns a
CommandRegistrationhandle that theCommandRegistrywraps in the plugin lifecycle.
The plugin does not interact with CommandManager directly. All registration goes through CommandRegistry to ensure proper ownership and lifecycle management.
Inherited from Registry
Section titled “Inherited from Registry”This class inherits the following from Registry:
isEnabled()— returns whether the registry is active.enable()— re-enables the registry.shutdown()— disables the registry and unregisters all commands.register(T registration)— internal method for wrapping a registration in the lifecycle.getRegistrations()— returns an unmodifiable view of the shutdown tasks.
Usage Example
Section titled “Usage Example”Basic command registration
Section titled “Basic command registration”@Overrideprotected void setup() { CommandRegistry commands = getCommandRegistry();
// Register a custom command CommandRegistration reg = commands.registerCommand(new SpawnCommand());
// The command is now available in-game as /spawn. // Permission auto-generated: {basePermission}.command.spawn // It will be automatically unregistered on plugin shutdown.}Command with subcommands
Section titled “Command with subcommands”public class SpawnCommand extends AbstractCommandCollection { public SpawnCommand() { super("spawn", "myplugin.commands.spawn.description"); addSubCommand(new SpawnSetCommand()); addSubCommand(new SpawnRemoveCommand()); addSubCommand(new SpawnListCommand()); }}
// In setup():commands.registerCommand(new SpawnCommand());// Generates permissions:// {basePermission}.command.spawn// {basePermission}.command.spawn.set// {basePermission}.command.spawn.remove// {basePermission}.command.spawn.listManual unregistration
Section titled “Manual unregistration”private CommandRegistration spawnReg;
@Overrideprotected void setup() { spawnReg = getCommandRegistry().registerCommand(new SpawnCommand());}
// Later, if needed:public void disableSpawnCommand() { spawnReg.unregister();}Related Types
Section titled “Related Types”- PluginBase — provides
getCommandRegistry() - Registry — base class providing lifecycle management
- Registration — base handle for registrations
CommandRegistration— typed handle returned byregisterCommand(); extends Registration and holds a reference to theAbstractCommand- AbstractCommand — base class for defining commands with arguments, permissions, and execution logic
- CommandBase — synchronous command convenience base class
CommandManager— server-level command manager that performs the actual registrationCommandOwner— interface implemented byPluginBasefor command ownership- Command System Overview — full command system documentation