command — Command API
Phase: Server
Lets Lua scripts register custom server commands. Commands survive script reloads — the Brigadier node is registered once, but the handler function is updated on every /atomicoffe reload.
command.register(name, fn)
Registers a command named /<name>. The callback receives a command context table.
command.register("greet", function(ctx)
if ctx.player then
ctx.player.tell("Hello, " .. ctx.player.name .. "!")
else
ctx.reply("Hello from the console!")
end
end)
Context table fields
| Field | Type | Description |
|---|---|---|
ctx.player | player or nil | Player context when run by a player; nil from console/command block |
ctx.commandName | string | The name of the command that was executed |
ctx.reply(msg) | function | Sends feedback text to whoever ran the command |
Notes
- Commands are registered at the Brigadier level on the first call. Subsequent calls (e.g. after
/atomicoffe reload) update the handler in-place without creating duplicate nodes. - The command tree is automatically synced to all online players when a new command is registered at runtime.
- If a reload removes a
command.registercall entirely, the node remains in the dispatcher but becomes a no-op until the script adds it back.