Commands
Use command builders to expose server actions safely.
In this section
Related section pages:
Registration
Prefer ctx.RegisterCommand(...) for plugin commands. Commands registered through plugin context are automatically unregistered when the plugin stops or reloads.
givegem.go
func NewGiveGemCommand(ctx plugin.Context) command.Command { return command.New("givegem"). Permission("example.ruby"). Argument("count", command.TypeInt, command.Default(1), command.Min(1), command.Max(64)). Executor(func(_ context.Context, cmd command.Context) (command.Result, error) { if cmd.Source.PlayerID == "" { return command.Result{Messages: []string{"only players can use this command"}}, nil } count := cmd.Int("count") playerHandle, ok := ctx.Gameplay().Players().Get(cmd.Source.PlayerID) if !ok { return command.Result{Messages: []string{"player not found"}}, nil } _, err := playerHandle.Inventory().Give(item.New("example:ruby").Count(count).Stack()) return command.Result{Messages: []string{"ruby added"}}, err })}Typed Arguments
Typed arguments normalize common gameplay values before the executor runs. This keeps command handlers focused on gameplay behavior instead of string parsing.
buff.go
command.New("buff"). Argument("target", command.TypePlayer, command.Default("@s")). Argument("effect", command.TypeEffect, command.Default("speed")). Executor(func(_ context.Context, cmd command.Context) (command.Result, error) { effectType, _ := cmd.Effect("effect") _ = effectType return command.Result{Messages: []string{"buff applied"}}, nil })Results And Delivery
Command handlers should return command.Result. The server decides how to deliver the result to the command source, whether that source is a player, console, or automation.