Plugin Lifecycle
Every plugin has a main class that extends JavaPlugin. The engine calls three methods you can override.
| Method | When |
|---|---|
onLoad() | After dependency checks. The plugin's constructor also runs at this stage. |
onEnable() | When the plugin starts. Register events, commands and tasks here. |
onDisable() | When the plugin stops. |
package dev.example;
import dev.zernyth.api.plugin.JavaPlugin;
public final class LifecyclePlugin extends JavaPlugin {
@Override public void onLoad() { getLogger().info("Loaded " + getDescription().version()); }
@Override public void onEnable() { getLogger().info("Data folder: " + getDataFolder()); }
@Override public void onDisable() { getLogger().info("Stopped"); }
}plugin.yml
name, version and main are required. The file is limited to 64 KiB, and unknown or duplicate keys are rejected.
| Key | Purpose |
|---|---|
depend | Plugins that must be enabled first. |
softdepend | Plugins to load first when present. |
loadbefore | Plugins this one must load before. |
imports | Declared dependencies whose exported packages this plugin may use. |
exports | Packages other plugins may import. |
libraries | Local JAR files, up to 16. |
commands | Command declarations. |
Quote versions that look numeric, so YAML keeps their exact spelling.
Disabling
Disabling rejects new asynchronous work before onDisable runs, cancels pending work and requests cancellation of running work. Re-enabling creates a new owner generation and class loader. Plugins must stop threads they created themselves.