Plugins
Lifecycle
Order of operations
- The server scans
plugins/and reads eachplugin.json, rejecting bad manifests, duplicate names and unsupported API versions. - It sorts plugins by
depend,softdependandloadbefore. A circular dependency is an error. - It loads each one. A plugin whose dependency failed is skipped.
- It loads the plugins' resource packs.
- It calls
onLoadon each plugin. - It calls
onEnableon each plugin in order. A plugin whose dependency is not enabled is skipped. - At shutdown it calls
onDisablein reverse order and cancels the plugin's scheduled tasks.
The three callbacks
class MyPlugin : public falcon::Plugin {
public:
void onLoad() override {
// Register custom content here.
}
bool onEnable() override {
logger().info("enabled");
return true;
}
void onDisable() override {
logger().info("disabled");
}
};
FALCON_PLUGIN(MyPlugin)
Returning false from onEnable, or throwing, leaves the plugin disabled and logs an error. The C++ wrapper catches exceptions from every callback, handler and task.
Register custom content in onLoad, as the HelloPlugin example does with its Thunder Wand, and listeners, commands and tasks in onEnable.
Native entry point
FALCON_PLUGIN(Type) exports falcon_plugin_entry. The server calls it with the API table, the plugin handle and the callback struct. It returns 0 if the API major version differs or the table is too small.
