mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23: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>
17 lines
584 B
JavaScript
17 lines
584 B
JavaScript
import { HostEcho, HostEchoReceived } from "./messages.js";
|
|
|
|
// Uses the default export entrypoint, the controller and ctl parts of this
|
|
// plugin use the deprecated class export so both paths are exercised.
|
|
export default async function(context) {
|
|
const { host, logger } = context;
|
|
logger.info("test_plugin host loaded");
|
|
const receivedEchoes = new Set();
|
|
|
|
host.handle(HostEcho, async (event) => {
|
|
logger.info(`test_plugin host echo ${event.text}`);
|
|
receivedEchoes.add(event.text);
|
|
});
|
|
|
|
host.handle(HostEchoReceived, async (request) => receivedEchoes.has(request.text));
|
|
}
|