Developing Go Plugins

LapisMC plugins are written in standard Go and compiled into shared objects (.so) loaded dynamically at runtime via Go's native plugin package.

1. Create Your Plugin Code

myplugin.go
package main

import (
	"github.com/lapismc/lapismc/api"
	"github.com/lapismc/lapismc/api/event"
)

// Exported Symbol: PluginInit is entrypoint for LapisMC
func PluginInit(ctx *api.Context) {
	ctx.Log.Info("Custom Go Plugin Initialized!")

	ctx.Events.OnPlayerJoin(func(e *event.PlayerJoinEvent) {
		e.SetHeaderMOTD("Welcome to LapisMC!")
	})
}

2. Build the Shared Library

Plugins must be compiled with the -buildmode=plugin flag using the exact same Go version as your core LapisMC binary:

Terminal
go build -buildmode=plugin -o plugins/myplugin.so myplugin.go