Skip to main content

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

FieldTypeDescription
ctx.playerplayer or nilPlayer context when run by a player; nil from console/command block
ctx.commandNamestringThe name of the command that was executed
ctx.reply(msg)functionSends 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.register call entirely, the node remains in the dispatcher but becomes a no-op until the script adds it back.