Your first plugin
In this page you write a small Rust plugin, build it, install it and try it. Then you meet the three example plugins in the repository. Read Plugin concepts first if "owner", "ABI" or plugin.toml are new to you.
You need Rust (the repository pins its toolchain in rust-toolchain.toml) and a Vanillite server of the version you build for.
1. The project
Cargo.toml:
[package]
name = "my-plugin"
version = "0.1.0"
edition = "2024"
[lib]
crate-type = ["cdylib"] # a dynamic library the server can load
[dependencies]
# The SDK of the server version you build for: a release tag, or a path to a checkout.
vanillite-plugin = { git = "https://github.com/hthoene/vanillite", tag = "v0.1.0-beta.4+mc26.3" }
Do not set panic = "abort"; the server refuses such a library.
src/lib.rs:
use vanillite_plugin::prelude::*;
struct Greeter;
impl Plugin for Greeter {
fn load(registrar: &mut Registrar<Self>) -> Result<Self, Error> {
// An event: greet a player who joins.
registrar.on_join(priority::NORMAL, |_, ctx, event| {
let _ = ctx
.server()
.send_message(event.player(), format!("Welcome, {}!", event.name()));
});
// A command: /greet
registrar.command(Command::literal("greet").executes(|_, ctx, invocation| {
invocation.reply(ctx, "Hello!");
Ok(1) // the command's result, like Vanilla's
}));
Ok(Greeter)
}
}
// Exports the plugin as the library's entry point.
vanillite_plugin::export_plugin!(Greeter);
plugin.toml:
id = "greeter"
name = "Greeter"
version = "0.1.0"
api = "1.1" # the plugin API (ABI) version needed
library = "my_plugin" # libmy_plugin.so, my_plugin.dll or libmy_plugin.dylib
Handlers get three things: your plugin object, a Ctx (the world access of this call) and the event. See Plugin API: events and Plugin API: commands and permissions.
2. Build and install
cargo build --release
mkdir -p /path/to/server/plugins/greeter
cp plugin.toml target/release/libmy_plugin.so /path/to/server/plugins/greeter/
(On Windows the library is my_plugin.dll in target\release, on macOS libmy_plugin.dylib.) Build on the platform you run the server on, or for it with --target. Then restart the server.
3. Test
- The log shows
Loading plugin greeter 0.1.0 (SHA-256 …)andEnabled plugin greeter 0.1.0. /pluginslists Greeter in green.- Join the server: you get
Welcome, <name>!. Type/greet:Hello!.
If something is wrong, see Plugin troubleshooting. Use vanillite_plugin::info!("…"), warn!, error! and debug! to write to the log; lines are prefixed with the plugin's id.
While you develop, set plugins.development = true in vanillite.toml. Then vanillite plugin reload greeter in the console loads a new build without a restart. Never use it on a production server.
The examples
All three are in examples/ of the repository. Build one with cargo build -p <package> and install it like above (plugin.toml and the library into plugins/<id>/).
| Example | Package | What it shows |
|---|---|---|
| hello-plugin | vanillite-example-hello |
The wide tour: /hello with suggestions, join messages from config.toml, persistent player data, a refused login name, cancelled events, a menu, boss bar, scoreboard, sounds, particles, a mob goal, a service for other plugins, plugin events, bulk block access, a ray trace, a new world (/hello lobby) and a replacement world generator (off until generator.enabled). |
| packet-plugin | vanillite-example-packets |
The packet interface: hide name tags per viewer (/nametags off, a per-receiver listener that rewrites team packets), a prefix on every system message (a per-broadcast listener, chat.prefix), read-only signs (signs.read-only, a serverbound listener that cancels), and /punch, which feeds a packet in as if the client sent it. Uses the packets feature of the SDK. |
| packet-bench | vanillite-example-packet-bench |
A measuring plugin, not a feature. It puts counting listeners on the entity movement packets so that load tests can show what a listener costs (mode in config.toml: off, broadcast, receiver, rewrite, unrelated). |
Walk through hello-plugin
Its plugin.toml has threading = "serialized" and provides = ["chunk-generator"]. In load it:
- writes its defaults with
registrar.config(include_str!("../config.toml"))and reads values later withserver.config_string("messages.join")(Plugin API: tasks, config and data), - registers handlers (
on_join,on_login,on_inventory_click,on_entity_drops, …), - registers permissions (
registrar.permission("hello.pad", PermissionDefault::Op)) and a command tree with sub-commands, arguments (ArgType::Vec3,ArgType::Word) and a suggestion provider, - offers a service:
server.register_service("hello:greeter", 1, &GREETER).
Work that touches another owner goes through server.schedule(Owner::Entity(world, player), 0, 0, move |ctx| { … }). For example /hello pad fills a layer of glass under the player with one ctx.blocks read and one ctx.set_blocks write. See Plugin API: players, entities and worlds.
Walk through packet-plugin
Its plugin.toml says threading = "concurrent" because packet listeners run on network threads. Its Cargo.toml turns on the packets feature:
vanillite-plugin = { git = "…", tag = "…", features = ["packets"] }
The smallest listener is a few lines, from the example:
use vanillite_plugin::packet::PacketFilter;
// Signs are read-only: the client's edit never reaches the game.
registrar.on_packet(PacketFilter::serverbound("sign_update"), |event| event.cancel());
More in Plugin API: packets.
Run packet-bench
packet-bench is meant for the repository's load test: cargo xtask loadtest --plugin examples/packet-bench --plugin-set 'mode = "receiver"' installs it on the test server for the run and removes it afterwards. These runs are not kept in the benchmark history. See How we measure.
Other languages
The ABI is plain C. A library in any language works if it exports vanillite_plugin_abi and fills the PluginInfo record. The Rust definitions in vanillite-abi are the contract, and layout.rs describes every record, offset and constant as data, which is how the Java bindings of the Bukkit layer are generated. A plain C header is not shipped on dev.
See also: Plugin concepts, Plugins.
Next: Plugin API: events.