Plugin API
Your First Plugin
Build a plugin step by step, from a join message to commands, menus and config.
Updated Dec 5, 2026
This tutorial builds one plugin, greeter, and grows it a piece at a time. Each step compiles on its own, so stop wherever you like.
1. Create the crate
cargo new --lib greeter
cd greeter
# Cargo.toml
[lib]
crate-type = ["cdylib"]
[dependencies]
rocketmc-plugin-api = { git = "https://github.com/Rocket-Minecraft/RocketMc" }
tracing = "0.1"
Plugins are compiled to a WebAssembly component, not a native library. Use a component toolchain such as cargo-component, and check docs/API.md in the repository for the exact target your server version expects.
2. The smallest plugin
Every plugin is a type that implements Plugin and is registered with register_plugin!. use rocketmc_plugin_api::prelude::*; brings in almost everything you need.
use rocketmc_plugin_api::prelude::*;
struct Greeter;
impl Plugin for Greeter {
fn new() -> Self {
Greeter
}
fn metadata(&self) -> PluginMetadata {
PluginMetadata::new("greeter", "0.1.0")
.author("you")
.description("Greets players when they join.")
}
fn on_load(&self, ctx: Context) -> Result<()> {
tracing::info!("greeter loaded");
Ok(())
}
}
register_plugin!(Greeter);
PluginMetadata::new(..) is a builder: add .author(), .description(), .depends_on() and .permission() as needed. You can still fill the struct fields by hand if you prefer.
3. Listen to an event
The quickest way is a closure. ctx.listen observes an event and never changes it:
use rocketmc_plugin_api::events::PlayerJoinEvent;
fn on_load(&self, ctx: Context) -> Result<()> {
ctx.listen::<PlayerJoinEvent, _>(|server, event| {
server.broadcast_message(&format!("&e{} &7joined", event.player.get_name()));
event.player.send_title("&6Welcome", "&7enjoy your stay", 10, 60, 10);
})?;
Ok(())
}
To change or cancel an event, use ctx.on with a priority. The closure gets the event data and returns it:
use rocketmc_plugin_api::events::{EventPriority, PlayerJoinEvent};
use rocketmc_plugin_api::text::TextComponent;
ctx.on::<PlayerJoinEvent, _>(EventPriority::Normal, |_server, mut event| {
event.join_message = TextComponent::text("Welcome to the server!");
event
})?;
& colour codes work in the Bukkit-style helpers. See Events for priorities and the Listener trait.
4. Add a config file
PluginConfig keeps a TOML file in your data folder, creates it from embedded defaults, and adds any missing keys later. It needs fs.read.data and fs.write.data.
const DEFAULTS: &str = "[messages]\nhi = \"&aHello {player}!\"\n\n[limits]\nmax = 3\n";
fn metadata(&self) -> PluginMetadata {
PluginMetadata::new("greeter", "0.1.0")
.author("you")
.permission(permissions::FS_READ_DATA)
.permission(permissions::FS_WRITE_DATA)
}
fn on_load(&self, ctx: Context) -> Result<()> {
let config = PluginConfig::load(&ctx, "config.toml", DEFAULTS).map_err(|e| e.to_string())?;
let messages = MessageCatalog::from_config(&config, "messages");
let max = config.get_i64_or("limits.max", 3);
tracing::info!("limit is {max}");
Ok(())
}
Use permissions::* constants and never type the strings by hand.
5. Add a command
SimpleCommand::new(["hello"], "Greets a player")
.executor(move |sender, _server, args| {
let who = args.get(0).unwrap_or("there");
sender.send_message(&messages.component("hi", &[("player", who)]));
Ok(())
})
.register(&ctx)?;
/hello Steve now prints the hi message with {player} replaced. Aliases, a permission and tab completion are chained on the same builder.
6. Open a menu
Call menu::install once in on_load, then build a fresh Menu each time you open one:
use rocketmc_plugin_api::Item;
menu::install(&ctx)?;
fn open_shop(player: &Player) {
let mut shop = Menu::new(3, "&8Shop");
shop.set_button(
13,
ItemBuilder::new(Item::Diamond).name("&bBuy a diamond").lore(["&7Cost: 10 coins"]).build(),
|_server, click| click.player.send_message("&aPurchased!"),
);
shop.fill_empty(|| ItemBuilder::new(Item::GrayStainedGlassPane).name(" ").build());
shop.open(player); // consumes the menu
}
Clicks and drags in the menu are cancelled for you.
7. Run something later
tasks::run_later(20, |_server| tracing::info!("one second has passed"));
tasks::run_countdown(5, |_s, left| tracing::info!("{left}"), |_s| tracing::info!("go"));
Install
Copy the built .wasm file into the server's plugins/ folder and start the server. With hot_reload enabled, changes are picked up while it runs. You can also use plugin load greeter from the console.
If the server asks to approve permissions the first time, read the list before you accept. The first two steps need none, the config step needs the two data-folder permissions.
Where next
| I want to... | Read |
|---|---|
| Understand the building blocks | API overview |
| React to more things | Events |
| Write richer commands and tasks | Commands and scheduler |
| Use the Bukkit-style player and server helpers | Bukkit-style helpers |
| Build menus, scoreboards and effects | Menus and displays |
| Store data and run an economy | Storage and economy |
| Add ranks, regions, homes and moderation | Server toolkit |