Plugins

Netherrack v0.6.0-beta has a small Java plugin API. Plugins get lifecycle callbacks, events, commands, permission nodes, scheduled tasks, Bedrock forms, HUD messages, player metadata, offline-player lookup, and a narrow view of players and blocks.

Experimental API

The API is new and may change between releases. Plugins declare which API version they were built for, and the server checks it before loading them. A plugin built for 0.6.x runs on any 0.6.x server, but not on 0.5.x or 1.x.

Installing a plugin

  1. Build or download a plugin jar. Don’t bundle the API into it — the server supplies that.

  2. Stop the server and copy the jar into plugins/ next to netherrack.jar. Netherrack creates the folder on first start if it doesn’t exist.

  3. Start the server. Each plugin gets a data folder at plugins/<plugin-name>/ and a logger whose lines are prefixed with the plugin name. A config.yml is written there when the plugin calls saveConfig().

  4. Run /plugins to see what loaded. The list includes disabled plugins, so look at the startup log for load errors too.

Jar changes need a restart: runtime plugin enable, disable and reload are not implemented yet. Duplicate plugin names are skipped, and a failing callback disables only that plugin and anything that depends on it.

Setting up a plugin project

Use Java 17 or newer. The API lives under the package root com.netherrack.api.* and is published by JitPack from the v0.6.0-SNAPSHOT tag; the version plugins declare is 0.6.0. In short, the Maven coordinate is com.github.NetherrackOSS:NetherrackAPI:v0.6.0-SNAPSHOT. Keep the dependency at provided scope so the jar stays small and uses the copy shaded into netherrack.jar.

pom.xml
<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>com.github.NetherrackOSS</groupId>
    <artifactId>NetherrackAPI</artifactId>
    <version>v0.6.0-SNAPSHOT</version>
    <scope>provided</scope>
  </dependency>
</dependencies>

The full example plugin in the server repository shows every feature described on this page: examples/hello-plugin.

plugin.yml

Every plugin jar needs a plugin.yml at its root. Only name, version and main are required. The loader understands simple YAML: top-level key: value lines, inline lists such as [hi] or indented - hi lists, and the nested commands: block. Unknown keys are ignored.

plugin.yml
name: HelloPlugin
version: 1.0.0
api-version: 0.6.0
main: com.example.hello.HelloPlugin
description: A small example plugin
author: You
load: POSTWORLD
depend: [OtherPlugin]
softdepend: [OptionalPlugin]
loadbefore: [LaterPlugin]
commands:
  hello:
    description: Sends a greeting
    aliases: [hi]
    usage: /hello [name]
    permission: hello.use
KeyMeaning
name, version, mainRequired. The name may contain letters, digits, dots, dashes and underscores; main is the full class implementing Plugin, normally by extending PluginBase.
api-versionThe API version the plugin targets, 0.6.0. Defaults to the API jar’s current version if omitted.
loadSTARTUP or POSTWORLD. Defaults to POSTWORLD; see Lifecycle.
depend, softdepend, loadbeforeOrdering hints. A missing hard dependency stops that plugin from enabling; soft dependencies and loadbefore only affect order.
commandsCommand declarations with description, aliases, usage and permission. There is no permissions: block in this API version — register nodes in code instead.

Lifecycle and load order

Extend com.netherrack.api.plugin.PluginBase. It supplies the config, logger, server, data folder and scheduler; the three callbacks do nothing unless you override them.

HelloPlugin.java
package com.example.hello;

import com.netherrack.api.plugin.PluginBase;

public final class HelloPlugin extends PluginBase {

    @Override
    public void onLoad() {
        getLogger().info("HelloPlugin loaded");
    }

    @Override
    public void onEnable() {
        String greeting = getConfig().get("greeting", "Hello!");
        getConfig().set("greeting", greeting);
        saveConfig();
        getLogger().info("Greeting: " + greeting);
    }

    @Override
    public void onDisable() {
        getLogger().info("HelloPlugin disabled");
    }
}

The server walks these phases in order:

  1. Jars in plugins/ are read and sorted by load order and dependencies. Invalid descriptors and duplicate names are reported and skipped.

  2. STARTUP plugins get onLoad() before the world and network listener exist. Use this only for state the plugin can prepare on its own.

  3. The world, listener and ticking start. POSTWORLD plugins then get onLoad().

  4. Each plugin’s declared commands are registered, then onEnable() runs in dependency order. Register listeners, permissions and tasks here.

  5. ServerStartEvent fires after every plugin is enabled, so listeners registered in onEnable() hear it.

  6. On shutdown, ServerStopEvent fires first, then onDisable() runs in reverse order. Commands, listeners, permissions and tasks are removed automatically.

getConfig() is a small YAML file at plugins/<name>/config.yml. It supports get(key, fallback) and set(key, value); call saveConfig() to write changes. getLogger() writes through the server’s normal logging settings, so a plugin’s lines obey the same formats and colors as everything else.

Events

Register a class implementing Listener from onEnable(), then mark its public methods with @EventHandler. A handler for a base class can handle a whole family of events: a handler for PlayerEvent also receives PlayerJoinEvent. All applicable handlers run in priority order.

import com.netherrack.api.event.EventHandler;
import com.netherrack.api.event.Listener;
import com.netherrack.api.event.player.PlayerChatEvent;
import com.netherrack.api.event.player.PlayerJoinEvent;

public final class MyListener implements Listener {

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        event.getPlayer().sendMessage("Welcome, " + event.getPlayer().getName() + "!");
    }

    @EventHandler
    public void onChat(PlayerChatEvent event) {
        if (event.getMessage().equalsIgnoreCase("!hello")) {
            event.setCancelled(true);
            event.getPlayer().sendMessage("Hello!");
        }
    }
}

Register it with getServer().getPluginManager().registerEvents(new MyListener(), this). Handlers may choose a priority from LOWEST, LOW, NORMAL, HIGH, HIGHEST and MONITOR, and may set ignoreCancelled (on by default). MONITOR should only observe. A handler that throws is reported without stopping the others, and every handler is unregistered when the plugin is disabled.

EventCancellableWhat it doesThread
ServerStartEventNoServer fully started and plugins enabled.Main startup thread
ServerStopEventNoGraceful shutdown has begun.Shutdown thread
PlayerLoginEventYesBefore login succeeds; cancelling kicks with the event’s kick message.Player’s network thread
PlayerJoinEventNoPlayer has joined and been added to the player list.Player’s network thread
PlayerQuitEventNoPlayer has disconnected and been saved.Player’s network thread
PlayerChatEventYesBefore broadcast; the message can be rewritten.Player’s network thread
PlayerCommandEventYesBefore dispatch; the command can be rewritten (no leading slash).Player’s network thread
PlayerDamageEventYesBefore health changes; the cause and original amount are exposed, and the amount can be changed.Player’s network thread or server tick
PlayerDeathEventNoAfter death but before drops and the death message; both can be edited.Player’s network thread or server tick
PlayerRespawnEventNoBefore a dead player is placed at their respawn point; the location can be changed.Player’s network thread
PlayerGameModeChangeEventYesBefore a game mode changes; old and new modes are exposed.Player’s network thread
PlayerMoveEventYesWhen a reported position changes; cancelling restores the old location and setTo rewrites the destination.Player’s network thread
PlayerTeleportEventYesBefore a teleport; extends PlayerMoveEvent and adds a TeleportCause.Player’s network thread
PlayerInventoryClickEventYesBefore an inventory interaction is applied; exposes the slot, stack, cursor and InventoryClickAction.Player’s network thread
PlayerItemPickupEventYesBefore a dropped stack is added to the inventory.Player’s network thread
PlayerItemDropEventYesBefore a player drops a stack; the stack can be replaced.Player’s network thread
PlayerItemUseEventYesBefore a held item is used on a block or on air.Player’s network thread
PlayerItemConsumeEventYesBefore eating begins; the food stack can be replaced.Player’s network thread
PlayerMetadataChangeEventYesBefore a connected player’s metadata value changes.Player’s network thread
PlayerActionBarEventYesBefore an action bar message; the text and animation times can be rewritten.Player’s network thread
PlayerToastEventYesBefore a toast; the title and content can be rewritten.Player’s network thread
PlayerPopupEventYesBefore a popup message; the text can be rewritten.Player’s network thread
PlayerFormRespondedEventNoAfter a player answers or closes a form.Player’s network thread
BlockPlaceEventYesBefore a player places a block.Player’s network thread
BlockBreakEventYesBefore a player breaks a block.Player’s network thread
Handlers run on the action thread

Event delivery is synchronous so a cancellable event can decide what the action does next. Server events run on the startup or shutdown thread; most player and block events run on that player’s network thread, while damage and death caused by survival ticks run on the server tick. Return quickly, and use the scheduler for slower work.

Commands

Commands are declared in plugin.yml and registered just before the plugin’s onEnable(). The main plugin class handles them by overriding onCommand(sender, command, label, args), or a separate class can be installed with getCommand("hello").setExecutor(...). Returning false shows the declared usage line.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    sender.sendMessage("Hello, " + sender.getName() + "!");
    return true;
}

Plugin commands use the server’s default command level, and the permission field in plugin.yml is checked when the command runs. A blank node needs no API permission. getCommand(name) works inside onEnable() but returns null in onLoad(). If a name or alias is already used by the server or another plugin, the conflicting command is skipped with a warning rather than replacing the existing one. When a plugin stops, its commands are removed.

Permissions

Register the nodes a plugin checks so their defaults are known. A node has a name, description and default from PermissionDefault: ALLOW, DENY, OPERATOR, NOT_OPERATOR or UNDEFINED.

import com.netherrack.api.permission.Permission;
import com.netherrack.api.permission.PermissionDefault;
import com.netherrack.api.permission.PermissionAttachment;

getPermissionManager().registerPermission(
        new Permission("hello.use", "Use /hello", PermissionDefault.ALLOW, this));

PermissionAttachment attachment = player.addAttachment(this);
attachment.setPermission("hello.use", true);
player.recalculatePermissions();

Attachments can allow or deny nodes for a player or the console. Exact nodes beat parent.* wildcards, explicit denials beat defaults, and checks are live. API permissions add to the existing op-level system rather than replacing it; an unregistered node still follows the player’s operator status.

Scheduler

getScheduler() runs work on the server tick, twenty ticks per second. runTask(plugin, runnable) runs next tick, runTaskLater(plugin, runnable, delayTicks) waits a number of ticks, and runTaskTimer(plugin, runnable, delayTicks, periodTicks) repeats. Each returns a TaskHandler with an id that cancelTask(id) can use. A delay of zero means the next tick, never the current one.

getScheduler().runTaskLater(this, () -> getLogger().info("Later!"), 20L);
TaskHandler task = getScheduler().runTaskTimer(this, this::tick, 0L, 20L);
getScheduler().cancelTask(task.getTaskId());

All of a plugin’s tasks are cancelled when it is disabled. Use a normal thread for blocking disk or network work rather than holding up the tick.

Players, worlds and blocks

The API keeps server internals out of plugin code. Player exposes the name, UUID, XUID, world, location, game mode, teleport, messages, kick and metadata. Server.getPlayers() lists the players currently registered, while the offline-player methods described below cover identities from past sessions too.

HUD messages follow Cloudburst Nukkit's player methods: sendActionBar(String), sendToast(String, String) and sendPopup(String). Each send fires its matching cancellable event before the packet, so listeners can rewrite or cancel it. The action bar also has an overload with fade-in, stay and fade-out times in ticks; the short overload uses one tick in, no stay and one tick out.

player.sendActionBar("Mining 12%");
player.sendToast("Quest complete", "Return to the village");
player.sendPopup("Press jump to continue");
Player player = sender.getPlayer();
Location location = player.getLocation();
BlockPosition below = new BlockPosition(
        location.toBlockPosition().getX(),
        location.toBlockPosition().getY() - 1,
        location.toBlockPosition().getZ());
BlockSnapshot block = player.getWorld().getBlock(below);
sender.sendMessage("Standing on " + (block == null ? "air" : block));

Items, metadata and offline players

0.6.0 adds a protocol-free ItemStack with an item id, count and damage value. Item and death events expose immutable stacks; a listener that wants to change what is dropped or eaten sets a new stack on the event. DamageCause, TeleportCause and InventoryClickAction name the matching gameplay causes without leaking protocol enums.

import com.netherrack.api.entity.DamageCause;
import com.netherrack.api.event.player.PlayerDamageEvent;
import com.netherrack.api.event.player.PlayerItemDropEvent;

@EventHandler
public void onDamage(PlayerDamageEvent event) {
    if (event.getCause() == DamageCause.FALL && event.getOriginalAmount() > 4) {
        event.setAmount(4);
    }
}

@EventHandler
public void onDrop(PlayerItemDropEvent event) {
    if (event.getItem().getId().equals("minecraft:diamond")) {
        event.setCancelled(true);
    }
}

Every Player is a MetadataHolder. Keys are case-insensitive strings and values are strings; getMeta() returns an immutable snapshot with lower-case keys. Setting or removing a value on a connected player fires the cancellable PlayerMetadataChangeEvent, so another plugin can veto or rewrite it. prefix and suffix are convenience keys. Metadata is session-only and is never written to disk.

player.setMeta("team", "red");
player.setPrefix("[Red] ");
String team = player.getMeta("TEAM");

Server.getOfflinePlayer(nameOrXuid), getOfflinePlayer(UUID) and getOfflinePlayers() return identity-only OfflinePlayer objects with the last known name, UUID, XUID and online state. They combine connected players with the Nukkit-style players/ identity files, permissions, whitelist, bans and saved world UUIDs. There is no offline inventory or location API.

import com.netherrack.api.entity.OfflinePlayer;

OfflinePlayer known = getServer().getOfflinePlayer("SchleroMC");
if (known != null) {
    getLogger().info(known.getName() + " online=" + known.isOnline());
}

Forms

Player.showForm(Form) opens a Bedrock form and returns its id, or -1 if the player already has one open. SimpleForm is a title, a message and a list of buttons. A button can be text-only or carry a FormButtonImage: path(...) names a texture in the client’s resource pack and url(...) points at an image to download. Its onSubmit callback receives the player and the clicked SimpleFormResponse; onClose runs when the player dismisses the form. The server sends the JSON, matches the response by id, ignores stale answers, and fires PlayerFormRespondedEvent for plugins that want to observe every response.

import com.netherrack.api.form.FormButtonImage;
import com.netherrack.api.form.SimpleForm;
import com.netherrack.api.form.SimpleFormResponse;

Player player = sender.getPlayer();
SimpleForm form = new SimpleForm("Test", "Test")
        .addButton("Plain button")
        .addButton("From texture", FormButtonImage.path("textures/items/apple"))
        .addButton("From URL", FormButtonImage.url("https://example.com/icon.png"))
        .onSubmit((submitter, response) -> submitter.sendMessage(
                "You clicked " + response.getButtonText() + "."))
        .onClose(submitter -> submitter.sendMessage("You closed the form."));
player.showForm(form);

The example plugin’s /testform command opens a form with both icon types and a plain button, and /testmessages sends all three HUD messages so a listener can observe their events. Callbacks run on the player’s network thread, so keep them short and use the scheduler for slower work.

Limitations