Skip to main content

Overview

Minestom’s command system provides a powerful builder API for creating commands with auto-completion, argument parsing, and condition checking.

CommandManager

Manager used to register and execute commands.

Registration

register
void
Registers a commandThrows IllegalStateException if a command with the same name already exists
unregister
void
Removes a command from registered commands
getCommand
Command
Gets a registered command by nameReturns null if not found
commandExists
boolean
Checks if a command exists

Execution

execute
CommandResult
Executes a command for a CommandSender
executeServerCommand
CommandResult
Executes a command using a ServerSender (silent, nothing printed to console)

Callbacks

setUnknownCommandCallback
void
Sets the callback executed when an unknown command is run
getConsoleSender
ConsoleSender
Gets the ConsoleSender instance for executing commands from console
createDeclareCommandsPacket
DeclareCommandsPacket
Creates the commands packet for a specific player (for auto-completion)

Command

Represents a command with suggestion/auto-completion support.

Creating Commands

Command command = new Command("teleport", "tp");

command.setDefaultExecutor((sender, context) -> {
    sender.sendMessage("Usage: /teleport <player>");
});

command.addSyntax((sender, context) -> {
    Player target = context.get("target");
    if (sender instanceof Player player) {
        player.teleport(target.getPosition());
    }
}, ArgumentType.Entity("target").onlyPlayers(true));

MinecraftServer.getCommandManager().register(command);

Command Methods

addSyntax
Collection<CommandSyntax>
Adds a new syntax to the commandReturns the created syntaxes (multiple if optional arguments are used)
addConditionalSyntax
Collection<CommandSyntax>
Adds a syntax with a condition
setDefaultExecutor
void
Sets the executor called when no syntax matches
setCondition
void
Sets the command condition (checked before execution)
setArgumentCallback
void
Sets a callback for argument errors
addSubcommand
void
Adds a subcommand
getName
String
Gets the main command name
getAliases
String[]
Gets all command aliases
getSyntaxes
Collection<CommandSyntax>
Gets all syntaxes of this command

Argument Types

The ArgumentType class provides factory methods for all built-in argument types.

Basic Arguments

ArgumentType.Boolean(id)
ArgumentBoolean
Parses boolean values (true/false)
ArgumentType.Integer(id)
ArgumentInteger
Parses integer values
ArgumentType.Double(id)
ArgumentDouble
Parses double values
ArgumentType.Float(id)
ArgumentFloat
Parses float values
ArgumentType.Long(id)
ArgumentLong
Parses long values
ArgumentType.String(id)
ArgumentString
Parses string values (quoted or single word)
ArgumentType.Word(id)
ArgumentWord
Parses a single word (no spaces)
ArgumentType.StringArray(id)
ArgumentStringArray
Parses remaining arguments as string array

Minecraft-Specific Arguments

ArgumentType.Entity(id)
ArgumentEntity
Parses entity selectors (@p, @a, @e, etc.)
ArgumentType.ItemStack(id)
ArgumentItemStack
Parses item stack with optional NBT
ArgumentType.BlockState(id)
ArgumentBlockState
Parses block state with properties
ArgumentType.Color(id)
ArgumentColor
Parses chat colors
ArgumentType.Component(id)
ArgumentComponent
Parses JSON text components
ArgumentType.NBT(id)
ArgumentNbtTag
Parses NBT tags
ArgumentType.NbtCompound(id)
ArgumentNbtCompoundTag
Parses NBT compound tags
ArgumentType.RelativeBlockPosition(id)
ArgumentRelativeBlockPosition
Parses block positions (supports relative coordinates)
ArgumentType.RelativeVec3(id)
ArgumentRelativeVec3
Parses 3D vectors (supports relative coordinates)
ArgumentType.UUID(id)
ArgumentUUID
Parses UUIDs
ArgumentType.Time(id)
ArgumentTime
Parses time values (with units: s, t, d)
ArgumentType.Resource(id, identifier)
ArgumentResource
Parses resource locations from a registry
ArgumentType.Particle(id)
ArgumentParticle
Parses particle types with data

Argument Utilities

ArgumentType.Literal(id)
ArgumentLiteral
Matches a literal string (for subcommands)
ArgumentType.Group(id, args)
ArgumentGroup
Groups multiple arguments
ArgumentType.Loop(id, args)
ArgumentLoop<T>
Repeats argument pattern

Argument Customization

All argument types extend the base Argument<T> class with these methods:
setDefaultValue
Argument<T>
Sets a default value (makes argument optional)
setSuggestionCallback
Argument<T>
Sets custom tab-completion suggestions
setCallback
void
Sets error callback for this argument
map
Argument<O>
Maps argument output to another type
filter
Argument<T>
Adds a filter predicate

Usage Examples

Command gamemode = new Command("gamemode", "gm");

gamemode.addSyntax((sender, context) -> {
    if (!(sender instanceof Player player)) {
        sender.sendMessage("Only players can use this command");
        return;
    }
    
    int mode = context.get("mode");
    player.setGameMode(GameMode.values()[mode]);
    player.sendMessage("Gamemode changed to " + mode);
}, ArgumentType.Integer("mode").between(0, 3));

MinecraftServer.getCommandManager().register(gamemode);
Commands are registered globally through the CommandManager. Each syntax is tried in order until one matches.

Build docs developers (and LLMs) love