Plugin Lifecycle & Events
Loading Order
Plugins are loaded in a specific sequence to ensure dependencies are met:
- Early Plugins: Loaded via
EarlyPluginLoader(inearlyplugins/). Can perform class transformation. - Core Plugins: Built-in system plugins.
- Builtin Directory: Plugins in
builtin/. - Classpath Plugins: Discovered via
manifest.jsonon the classpath. - Mod Directory: User-installed plugins in
mods/.
Plugin States
public enum PluginState {
NONE, // Initial state
SETUP, // Being configured (registering systems)
START, // Active logic starts
ENABLED, // Running normally
SHUTDOWN, // Cleanup
DISABLED // Failed or turned off
}
Event System
The event bus supports both synchronous (IEvent) and asynchronous (IAsyncEvent) events.
Registration Example
public class ExamplePlugin extends JavaPlugin {
@Override
protected void setup() {
getEventRegistry().register(
PlayerConnectEvent.class,
this::onPlayerConnect
);
}
private void onPlayerConnect(PlayerConnectEvent event) {
getLogger().info("Player connected: " + event.getPlayer().getName());
}
}
Event Priority
Priorities determine the order in which handlers receive events:
EARLIEST -> EARLY -> DEFAULT -> LATE -> LATEST
Plugin Manifest (manifest.json)
Every plugin requires a manifest.json file in its root.
{
"Group": "MyCompany",
"Name": "MyPlugin",
"Version": "1.0.0",
"Main": "com.example.MyPluginMain",
"ServerVersion": "^1.0.0",
"Dependencies": {
"Hytale:Core": "^1.0.0"
}
}