Lifecycle Methods

There are a few lifecycle methods that you can override in your plugins to listen for specific events.

If you're looking to listen for game and worker events, check out the Event Listeners guide.

Constructor

Depending on whether you're writing a worker or a room plugin, the constructor may be different to override.

For example, a worker plugin constructor:

constructor(
public readonly worker: Worker,
public config: any
) {
super(worker, config);
}

vs a room plugin:

constructor(
public readonly room: Room,
public config: any
) {
super(room, config);
}

The constructor lets you assign any properties on your plugin that TypeScript or JavaScript will shout at you for being unassigned. Being non-asynchronous, you should not use it for any tasks with callbacks or that return a Promise. Instead, use the onPluginLoad.

Methods

onPluginLoad()

Very simply, this method is called when your plugin is first loaded and all events, commands and messages have been attached.

@HindenburgPlugin("hbplugin-fun-things")
export class MyPlugin extends WorkerPlugin {
async onPluginLoad() {

}
}

Hindenburg will wait for this method to finish if it's marked as asynchronous, so it's useful for connecting to servers or fetching resources before the server starts.

onPluginUnload()

Also rather simply, this method is called when your plugin is about to be unloaded, although has not yet actually been unloaded from the server. Hindenburg will not wait for this to complete, but any asynchronous tasks can still run parallel.

@HindenburgPlugin("hbplugin-fun-things")
export class MyPlugin extends WorkerPlugin {
onPluginUnload() {

}
}

onConfigUpdate(oldConfig: any, newConfig: any)

Called when your plugin's config in the server's config.json is modified, it allows you to catch when your plugin's config updates.

Useful for verifying the config, or modifying your plugin based on the new configuration.

@HindenburgPlugin("hbplugin-fun-things")
export class MyPlugin extends WorkerPlugin {
onConfigUpdate(oldConfig: any, newConfig: any) {

}
}

Generated using TypeDoc