Skip to content
ZERNYTH.

Plugin Lifecycle

Every plugin has a main class that extends JavaPlugin. The engine calls three methods you can override.

MethodWhen
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.

KeyPurpose
dependPlugins that must be enabled first.
softdependPlugins to load first when present.
loadbeforePlugins this one must load before.
importsDeclared dependencies whose exported packages this plugin may use.
exportsPackages other plugins may import.
librariesLocal JAR files, up to 16.
commandsCommand 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.

Was this page helpful?