Plugin basics
The plugin lifecycle - onLoad, onEnable, onDisable - and the logger.
Every plugin is a class that extends Plugin and overrides the lifecycle methods the server calls for you. This page covers those three states and the logger you use throughout.
The lifecycle
The server drives each plugin through three states, which map to the methods you override:
#include <endstone/endstone.hpp>
namespace es = endstone;
class MyPlugin : public es::Plugin {
public:
void onLoad() override
{
// read configuration and prepare state; the world isn't up yet
getLogger().info("Loading...");
}
void onEnable() override
{
// register commands and listeners, start tasks - the game is live
getLogger().info("Enabled!");
}
void onDisable() override
{
// flush anything unsaved and release what you acquired
getLogger().info("Disabled.");
}
};onLoad- the server isn't fully up, so prepare internal state but don't touch the world.onEnable- register commands and event listeners, start scheduled tasks, anything that touches the now-live game.onDisable- on stop or reload, flush unsaved data and release resources.
Every plugin is loaded before any is enabled, so by the time onEnable runs you can rely on the plugins you depend on being present.
Logging
Every plugin has a logger, reached with getLogger(), that writes to the server console with your plugin's name attached:
getLogger().info("Ready.");
getLogger().warning("Config missing 'greeting', using default.");
getLogger().error("Failed to load data.");The logger takes a format string and arguments, like getLogger().info("Loaded {} warps", count).