registerCommand

fun registerCommand(name: String, block: LiteralCommandDsl.() -> Unit)

Registers a new command with the specified name and configuration block.

This function provides a DSL-based approach to registering commands using Minecraft's Brigadier command system. The command is registered with the server's command dispatcher and synchronized with all connected players.

Example usage:

registerCommand("mycommand") {
requires { it.hasPermission(2) }
executes { context ->
context.source.sendSuccess("Hello!", true)
1
}
literal("subcommand") {
executes { 1 }
}
argument("value", IntegerArgumentType.integer()) {
executes { context ->
val value = IntegerArgumentType.getInteger(context, "value")
1
}
}
}

Parameters

name

The root name of the command to register

block

A configuration lambda that builds the command structure using LiteralCommandDsl

Throws

if the server is not available