CommandRegistry is Essential’s central system for managing commands and custom argument parsers. It provides methods to register commands, add custom type parsers, and unregister commands.
Accessing the Registry
Get the command registry instance through the Essential API:CommandRegistry Interface
Registering Commands
Using the register() Method
The simplest way to register a command is using the built-inregister() method:
Manual Registration
You can also register manually:Registration Best Practices
Register commands during your mod’s initialization:Unregistering Commands
Remove a command from the registry when it’s no longer needed:- Disabling features dynamically
- Reloading command configurations
- Mod shutdown/cleanup
Custom Argument Parsers
While Essential provides built-in parsers for common types (String, Int, Double, Boolean), you can create custom parsers for your own types.Built-in Types
These types work automatically without custom parsers:StringInt/java.lang.IntegerDouble/java.lang.DoubleFloat/java.lang.FloatBoolean/java.lang.Boolean
Creating a Custom Parser
1. Define Your Type
2. Implement ArgumentParser
3. Register the Parser
4. Use in Commands
ArgumentParser Interface
Advanced Parser Examples
Multi-Argument Parser
Parse multiple arguments into a single object:Annotation-Aware Parser
Access parameter annotations in your parser:Enum Parser
Parse enum types with automatic tab completion:ArgumentQueue Reference
TheArgumentQueue interface provides methods to access command arguments:
Usage Patterns
Complete Registration Example
Best Practices
1. Register During Initialization
Register all commands and parsers during your mod’s initialization phase:2. Handle Parser Errors Gracefully
Provide clear error messages when parsing fails:3. Implement Tab Completion
Always implementcomplete() for better user experience:
4. Reuse Parsers
Create one parser instance and reuse it:Next Steps
Overview
Back to command system overview
Creating Commands
Learn how to create commands