Plugin concepts
This page is for people who write native plugins. It explains the ideas you need before you write code. The code starts at Your first plugin.
The ABI
A native plugin is a library (.so, .dll or .dylib) that the server loads. It talks to the server only through the ABI, a fixed list of plain C types and functions. The list lives in the crate vanillite-abi. The current version on the dev branch is 1.25 (ABI_MAJOR 1, ABI_MINOR 25).
Because the contract is plain C, a plugin does not depend on the compiler or the libraries of the server. Memory is freed by the side that allocated it.
The easy way is the Rust SDK vanillite-plugin: a safe Rust API over the ABI. Any language that can export a C function can implement the ABI directly: the library exports one function, vanillite_plugin_abi, and the server calls the functions it returns. There is no ready-made C header on dev; the declarations are the repr(C) types in vanillite-abi (also recorded as data in abi.snapshot). The layer vanillite-bukkit shows a non-Rust user: it generates its Java bindings from this data.
What is stable
| Change | Version | What it means for plugins |
|---|---|---|
| Remove or change a function, type, field or constant | major | Not allowed within a major version. Old plugins would break. |
| Add functions, events, constants or fields at the end of a record | minor | Allowed. Old plugins do not notice. |
How this is kept:
- Every table and record starts with its size. Each side reads only the part both know, and new fields are only appended.
- Arrays of records carry their element size, so a record in an array can grow too.
- Enumerations are numbers. A value nobody knows is ignored or refused, never trusted.
- The test
abi_snapshotcompares every declaration with a recorded snapshot of the last release and fails on a breaking change without a major version bump.
The version rule: a plugin built for 1.4 runs on a 1.25 server. A plugin that needs 1.21 is refused by a 1.4 server. The Rust SDK writes the minor version of the SDK it was built with into the library, so build with the SDK of the oldest server you want to support. api in plugin.toml must not be higher than that.
Other checks when a library loads: built for this platform (target triple), built with panic = "unwind" (the default), and, for plugins that provide a system, built for this Minecraft data version. Players and entities are identified by UUID, worlds by a handle, blocks by their state text such as minecraft:oak_log[axis=y], never by protocol ids, so plugins keep working across Minecraft updates. Only code that works with numeric block state ids (generators) is tied to a data version.
Threads: there is no main thread
Vanillite runs each dimension on its own owner thread, in parallel (see Threads and ticks). So there is no single "main thread" a plugin can use for everything. Instead:
- Game state belongs to an owner: a world (and with it its blocks, players and entities), or the server itself between ticks.
- A callback (an event handler, a command, a task) runs on the owner of what it is about. It gets a context,
Ctx, that is valid only during the call. Through it the plugin can read and change that world. - Calls that touch world state with a context of another owner fail with the status
WRONG_OWNER. In the Bukkit layer this shows asnot allowed from this thread or task. - The global owner is the exception (since ABI 1.18).
enableand global tasks run while no world ticks, and their context owns every loaded world: the world threads lend their worlds to the server thread for the call. So a plugin can read and change all worlds inenableor in a global task, as a Bukkit plugin does on Paper's main thread. - Nested handlers (since ABI 1.21). A plugin is not called again while one of its calls is running: that call is dropped. A handler subscribed with the flag
NESTEDis the exception. When the plugin's own action fires an event (it spawns an entity, causes an explosion or damage), the handler runs at once, inside the action, as in Bukkit. It gets a context of its own; host functions given the outer call's context answerINVALID_ARGUMENTuntil the handler returns. At most 8 calls can be nested on one thread; a deeper one is dropped. The Rust SDK has no switch for it yet; it is used through the raw host functionsubscribe_flags(the Bukkit layer does). Serveris the thread-safe part of the API (messages, config, scheduling, scoreboards, world list). It can be copied, kept and used from any thread.- A few functions need no owner (ABI 1.25). A chunk can be captured on its world's owner and read out later from any other thread, which is what map renderers need (Plugin API: players, entities and worlds).
flowchart LR
subgraph owners[Owners]
G[Global<br/>server thread between ticks<br/>owns every world]
W1[World: overworld<br/>owner thread]
W2[World: nether<br/>owner thread]
E[Entity task<br/>on the entity's world]
B[Background<br/>no world access]
end
P[Plugin code] -->|Server::schedule| G
P -->|Server::schedule| W1
P -->|Server::schedule| W2
P -->|Server::schedule_entity| E
P -->|Server::run_async| B
To work on something another owner owns, schedule a task on that owner (Server::schedule(Owner::World(world), delay, period, |ctx| …)). It runs there with a context that fits. For work across several worlds, schedule it on Owner::Global. Slow work such as files, databases or the network belongs on a background thread (run_async); send its result back to an owner with schedule. More in Plugin API: tasks, config and data.
| Owner | Where the task runs |
|---|---|
Global |
The server thread between ticks. For server-wide work; it may use every world (since ABI 1.18). |
World(world) |
That world's owner thread, before its simulation in a tick. |
Location(world, pos) |
The owner of a block position (today its world). |
Entity(world, uuid) |
The world of the entity. The task ends when the entity is gone. |
| background | A background thread, off the tick. No world access. |
Calling a plugin from several threads: threading in plugin.toml says how. serialized (the default) means the server never calls the plugin on two threads at once, so plugin code needs no locks. concurrent says the plugin is thread-safe and may be called from several world threads at once. Packet listeners run on network threads, so plugins that use them should say concurrent.
Two serialized plugins cannot hang the server. Plugin A on the Overworld thread may call into plugin B (an event, a command, a permission check) while B on the Nether thread calls into A. Each would wait for the other. The server notices such a circle and refuses the one call that would close it: that call is dropped with the status WRONG_PHASE and a log line (see Plugin troubleshooting). Waiting without a circle is never refused. Registering a command while another thread runs or completes a command cannot block either.
A panic in a handler is caught. The plugin is switched off and the server keeps running (a panicking provider stops the server in order).
Lifecycle
| Step | When | What a plugin does |
|---|---|---|
load |
At start, before the worlds exist | Registers events, commands, permissions, packet listeners and providers. Registries are writable only here (late commands, see Plugin API: commands and permissions, are an exception). |
enable |
When the worlds exist | Starts work: reads worlds, starts timers. |
| running | Every tick | Handlers, commands and tasks run on their owners. |
disable |
At shutdown | Saves state. Plugins are never unloaded while the server runs. |
With plugins.development = true, vanillite plugin reload <id> loads a new build next to the old one. save_state hands over bytes of the old build and restore_state takes them in the new one, after load and before enable.
plugin.toml
Every plugin has a manifest next to its library. The server reads it before it loads the library.
id = "greeter" # a-z, 0-9, _ and -, 1 to 64 characters; also the data folder's name
name = "Greeter"
version = "0.1.0"
api = "1.5" # plugin API (ABI) version needed, major.minor
library = "my_plugin" # base name: libmy_plugin.so, my_plugin.dll, libmy_plugin.dylib
| Key | Required | Meaning |
|---|---|---|
id |
yes | Unique id. The data folder is plugins/<id>/. |
api |
yes | ABI version needed, major.minor. |
name |
no | Display name (default: the id). |
version |
no | The plugin's own version (default 0.0.0). |
library |
no | Base name of the library, without prefix and extension (default: the id with - as _). |
depends |
no | Plugin ids that must load first. If one is missing, this plugin is skipped. |
soft-depends |
no | Plugin ids that load first when they are present. |
threading |
no | serialized (default) or concurrent, see above. |
uses |
no | What the plugin uses (files, network, admin). Shown to the admin in the log, not enforced. |
provides |
no | Slots the plugin may fill, for example chunk-generator, see Plugin API: slots and hosted plugins. |
description, authors, website |
no | Shown by /version <plugin>. authors is a list of names. |
Strings may have up to 256 bytes, lists up to 64 entries.
Packages
A package is a folder or a .vlp file (a zip). Both hold plugin.toml and the library, either next to it or in native/<target-triple>/ (one per platform, for example native/x86_64-unknown-linux-gnu/). A .vlp can carry several platforms. Install steps: Installing plugins.
See also: Replaceable systems, Plugins.
Next: Your first plugin.