Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ProjectUnified/CraftCommand/llms.txt

Use this file to discover all available pages before exploring further.

CommandManager<S> is the abstract base class that every CraftCommand integration is built on. It owns the resolver registry, the error handler, and the command-info exposer map. Platform-specific subclasses — StandaloneCommandManager, BukkitCommandManager, and PaperCommandManager — extend it to add platform registration logic (command-map registration for Bukkit, lifecycle-event deferral for Paper, label-map tracking for Standalone) while inheriting the full resolver and error-handling API.

CommandManager<S> — base class

CommandManager<S> is parameterised on S, the platform’s command-sender type. All resolver lookups and error callbacks carry the same S throughout.

registerResolver

Registers a typed argument resolver for an exact class match.
public <T> void registerResolver(Class<T> type, ArgumentResolver<S, T> resolver)
type
Class<T>
required
The exact target class to register the resolver under. Later lookups check this key first before walking the class hierarchy or querying providers.
resolver
ArgumentResolver<S, T>
required
The resolver instance that converts raw argument strings into values of type T.

registerProvider

Registers a dynamic resolver provider that is consulted when no exact or hierarchy match is found.
public void registerProvider(ArgumentResolverProvider<S> provider)
provider
ArgumentResolverProvider<S>
required
A provider that receives the target class and returns a resolver, or null if it cannot handle that type. Providers are tried in registration order after all registerResolver entries.

getResolver

Returns the best resolver for the given type, following the four-step lookup order documented in ArgumentResolver & ArgumentResolverProvider.
public <T> ArgumentResolver<S, T> getResolver(Class<T> type)
type
Class<T>
required
The class to look up.
Returns an ArgumentResolver<S, T>. If no registered resolver or provider matches, a fallback resolver is returned that casts the sender to T if possible, or throws IllegalArgumentException.

resolveParameter

Resolves a single command parameter for a given type, advancing the shared index holder in place. Generated command wrappers delegate every parameter to this method instead of duplicating resolver lookup, width tracking, optional handling, and missing-argument reporting.
public <T> T resolveParameter(
    S sender,
    Class<T> type,
    String[] args,
    int[] indexHolder,
    String paramName,
    boolean optional,
    String defaultValue
) throws Exception
sender
S
required
The platform-native command sender. Must match the manager’s S type (e.g. CommandSourceStack for Paper). The wrapper passes the platform sender directly — not whatever type the user-facing method declares.
type
Class<T>
required
The Java class to resolve the argument into.
args
String[]
required
The full command arguments array available to the resolver.
indexHolder
int[]
required
A single-element array holding the current argument index. The method advances indexHolder[0] by the resolver’s getWidth() on success, so successive calls automatically move through args.
paramName
String
required
The parameter name used in the "missing-argument" error message.
optional
boolean
required
When true and there are not enough arguments, the method returns null (or the resolved defaultValue) instead of throwing.
defaultValue
String
required
The string default to resolve when the parameter is optional and arguments are exhausted. Pass null to return null for optional parameters with no default.
Returns the resolved T value, or null when the parameter is optional and absent with no default. Throws CommandException if a required parameter has insufficient arguments; throws any exception the resolver itself propagates.

filterSuggestions

Static helper that filters a list of tab-completion candidates to only those starting with the current input, using a case-insensitive prefix comparison.
public static List<String> filterSuggestions(List<String> suggestions, String current)
suggestions
List<String>
required
The raw candidate list. A null value is treated as an empty list.
current
String
required
The partial input typed so far. Compared in lowercase.
Returns a new List<String> containing only entries whose lowercase form starts with the lowercase form of current.

formatMessage

Formats a localisation message for a given key. The default implementation calls String.format(defaultValue, args). Override this method to provide translations or a custom message dictionary.
public String formatMessage(String key, String defaultValue, Object... args)
key
String
required
The message key (e.g. "missing-argument", "validation.min"). See Error Handling — Message keys for the full list.
defaultValue
String
required
The fallback String.format-compatible template used when no custom translation is provided.
args
Object...
required
Format arguments applied to the template.
Returns the formatted string. If String.format throws, the raw defaultValue is returned.

getErrorHandler / setErrorHandler

Reads or replaces the active error handler.
public ErrorHandler<S> getErrorHandler()
public void setErrorHandler(ErrorHandler<S> errorHandler)
errorHandler
ErrorHandler<S>
required
The new error handler. Called by generated wrappers whenever a command or resolver throws.
See Error Handling for details.

registerExposer

Registers a CommandInfoExposer produced by the generated wrapper for a given command instance. Called automatically by register(Object) in each platform subclass.
public void registerExposer(Object commandInstance, CommandInfoExposer exposer)
commandInstance
Object
required
The user-defined annotated command object (used as the map key).
exposer
CommandInfoExposer
required
The generated wrapper, which implements CommandInfoExposer and returns the command’s info list.

getCommandInfo

Returns the list of CommandInfo records registered for a command instance, or an empty list if the instance was never registered or its wrapper does not implement CommandInfoExposer.
public List<CommandInfo> getCommandInfo(Object commandInstance)
commandInstance
Object
required
The annotated command object passed to register().
Returns a List<CommandInfo> (never null).

StandaloneCommandManager

StandaloneCommandManager extends CommandManager<Object> for use in plain Java applications with no server runtime. The sender type is Object.

Constructors

// Default: rethrows all exceptions as RuntimeException
public StandaloneCommandManager()

// Custom error handler
public StandaloneCommandManager(ErrorHandler<Object> errorHandler)
The no-argument constructor installs a default error handler that re-throws the exception unchanged if it is already a RuntimeException, or wraps it in a new RuntimeException otherwise.

register(Object)

Scans for the annotation-processor-generated class named ClassName_Standalone and instantiates it via reflection. The wrapper is registered via registerCommand, and if it implements CommandInfoExposer the exposer is stored as well.
public void register(Object commandInstance)
commandInstance
Object
required
An instance of a class annotated with @Command. The processor must have generated the corresponding _Standalone wrapper at compile time.
Throws IllegalArgumentException if the wrapper class cannot be found or instantiated.

registerCommand

Directly registers a StandaloneCommand wrapper (and all its aliases) into the internal label map.
public void registerCommand(StandaloneCommand command)
command
StandaloneCommand
required
The command wrapper. command.getName() and every entry in command.getAliases() are all stored as lowercase keys.

getCommand

Looks up a registered command by its label or any alias. The lookup is case-insensitive.
public StandaloneCommand getCommand(String label)
label
String
required
The primary name or alias to look up.
Returns the StandaloneCommand, or null if no command is registered under that label.

getCommands

Returns the full label-to-command map. Aliases are also present as independent entries.
public Map<String, StandaloneCommand> getCommands()
Returns a Map<String, StandaloneCommand> (keys are lowercase).

BukkitCommandManager

BukkitCommandManager extends CommandManager<CommandSender> for Bukkit/Spigot/Paper plugins.

Constructors

// Default: sends ChatColor.RED + exception.getMessage() to the sender
public BukkitCommandManager(JavaPlugin plugin)

// Custom error handler
public BukkitCommandManager(JavaPlugin plugin, ErrorHandler<CommandSender> errorHandler)
plugin
JavaPlugin
required
Your plugin instance. Used as the namespace when registering to the Bukkit CommandMap and for duplicate-command logging.
errorHandler
ErrorHandler<CommandSender>
Custom error handler. When omitted, a red-message default is used.

register(Object)

Looks up the generated ClassName_Executor wrapper via reflection and registers it as a Bukkit Command.
public void register(Object commandInstance)
commandInstance
Object
required
An instance annotated with @Command. If the object itself is already a Command, it is forwarded directly to register(Command).
Throws IllegalArgumentException if the wrapper class cannot be found or instantiated, or if the label is already registered (a warning is logged instead of an exception in that case).

register(Command)

Registers a Bukkit Command directly to the server’s CommandMap under the plugin’s namespace.
public void register(Command command)
command
Command
required
The Bukkit command to register. Duplicate labels are ignored with a warning.

syncCommand

Calls the server’s syncCommands() method to push the updated command tree to connected clients (requires a CraftBukkit-derived server that exposes this method; silently does nothing otherwise).
public void syncCommand()

unregisterAll

Removes every command registered by this manager from the server’s CommandMap and clears the internal tracking map.
public void unregisterAll()
Call syncCommand() after unregisterAll() if you want clients to see the removal immediately.

PaperCommandManager

PaperCommandManager extends CommandManager<CommandSourceStack> for Paper plugins using the Brigadier command API.

Constructors

// Default: sends Component.text(message, NamedTextColor.RED) via Adventure
public PaperCommandManager(JavaPlugin plugin)

// Custom error handler
public PaperCommandManager(JavaPlugin plugin, ErrorHandler<CommandSourceStack> errorHandler)
plugin
JavaPlugin
required
Your plugin instance. The constructor immediately attaches a LifecycleEvents.COMMANDS handler so that all queued commands are registered when the lifecycle event fires.
errorHandler
ErrorHandler<CommandSourceStack>
Custom error handler. When omitted, a red Adventure Component default is used.
The LifecycleEvents.COMMANDS handler is registered in the constructor. You must call register() before the lifecycle event fires (i.e., before the server finishes loading your plugin). Commands registered after the event has already fired will not appear.

register(Object)

Attempts to locate and instantiate the ClassName_Paper Brigadier wrapper first. If that class is not found (e.g. the command uses only features supported by the basic API), it falls back to the ClassName_PaperBasic wrapper. The resulting wrapper is queued and registered when LifecycleEvents.COMMANDS fires.
public void register(Object commandInstance)
commandInstance
Object
required
An instance annotated with @Command. If the object is already a PaperCommand or PaperBasicCommand, it is forwarded to the appropriate typed overload directly.
Throws IllegalArgumentException if neither wrapper class can be found or instantiated.

register(PaperCommand)

Queues a full Brigadier PaperCommand wrapper for registration at the LifecycleEvents.COMMANDS event.
public void register(PaperCommand command)

register(PaperBasicCommand)

Queues a PaperBasicCommand (Paper’s simplified command API) wrapper for registration at the LifecycleEvents.COMMANDS event.
public void register(PaperBasicCommand command)

CommandInfo

CommandInfo is a lightweight data class produced by generated wrappers and exposed through CommandManager.getCommandInfo(). It describes a single executable entry point (the root command or any subcommand).
public class CommandInfo {
    public CommandInfo(List<String> path, String usage, String description) { ... }
    public List<String> getPath() { ... }
    public String getUsage() { ... }
    public String getDescription() { ... }
}

getPath()

public List<String> getPath()
Returns an ordered List<String> representing the subcommand path from the root label to this entry. For example, a teleport player subcommand under the tp command returns ["tp", "teleport", "player"].

getUsage()

public String getUsage()
Returns the usage syntax string, such as "player <target>" or "<item> [amount]". Sourced from the @Command / @Subcommand annotation’s usage attribute.

getDescription()

public String getDescription()
Returns the human-readable description sourced from the annotation’s description attribute. Returns an empty string if the annotation did not provide one.

Example: printing all subcommands

StandaloneCommandManager manager = new StandaloneCommandManager();
manager.register(new MyCommand());

List<CommandInfo> info = manager.getCommandInfo(new MyCommand());
for (CommandInfo entry : info) {
    System.out.printf("/%s — %s%n",
        String.join(" ", entry.getPath()),
        entry.getDescription());
}

Build docs developers (and LLMs) love