mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 07:04:52 +09:00
Replace invokeHook and the per plugin on* methods with AsyncHook collections on the controller, host, instance, clusterioctl and web control objects. Plugin entrypoints export a default function that receives a load context and attaches handlers to the hooks it needs. Class exports still load through fromContext with a deprecation warning. The create templates and docs use the entrypoint function. This is clusterio/clusterio#921 recreated on top of master after the ESM migration and the PluginDeclaration permissions change. Closes #730 Co-Authored-By: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
31 lines
813 B
JavaScript
31 lines
813 B
JavaScript
import * as lib from "@clusterio/lib";
|
|
//%if multi_context
|
|
import { PluginExampleEvent, PluginExampleRequest } from "./messages.js";
|
|
//%endif
|
|
|
|
export default async function loadHostPlugin(context) {
|
|
const { host, logger, plugin } = context;
|
|
//%if multi_context
|
|
|
|
host.handle(PluginExampleEvent, async (event) => {
|
|
logger.info(JSON.stringify(event));
|
|
});
|
|
|
|
host.handle(PluginExampleRequest, async (request) => {
|
|
logger.info(JSON.stringify(request));
|
|
return {
|
|
myResponseString: request.myString,
|
|
myResponseNumbers: request.myNumberArray,
|
|
};
|
|
});
|
|
//%endif
|
|
|
|
host.hooks.hostConfigFieldChanged.attach(plugin.name, async (field, curr, prev) => {
|
|
logger.info(`host::hostConfigFieldChanged ${field}`);
|
|
});
|
|
|
|
host.hooks.shutdown.attach(plugin.name, async () => {
|
|
logger.info("host::shutdown");
|
|
});
|
|
}
|