Lifecycle

Register, start, stop, and clean up plugins predictably.

In this section

Related section pages:

Lifecycle Flow

The public plugin lifecycle is Init -> Start -> Stop. The runtime initializes plugin registrations first, starts plugins after the dependency graph is ready, and stops plugins in reverse order.

lifecycle.txt
Init -> Start -> Stop

Registration

Init(ctx plugin.Context) is for commands, events, blocks, items, effects, and entity types. Store ctx only when handlers need access to ctx.Gameplay() later.

lifecycle.go
func (p *Plugin) Init(ctx plugin.Context) error {	p.ctx = ctx	return ctx.RegisterCommand(NewGiveCommand(ctx))}func (p *Plugin) Start(ctx context.Context) error {	p.ctx.Logger().Info("plugin started")	return nil}func (p *Plugin) Stop(ctx context.Context) error {	return p.ctx.Gameplay().Flush(ctx)}

Runtime Work

Start(context.Context) runs after all registered plugins are initialized. Use it for background tasks, subscriptions, and runtime wiring that depends on other plugins already being available.

Testing

For in-game testing, run the test server from the module root and keep plugin registration deterministic so reloads do not leak handlers.