One of the most central components to writing a plugin for Hindenburg is the ability to listen for specific events from rooms or from the worker.
As with every other Hindenburg plugin design decisions; you can attach event listeners with the @EventListener
decorator.
For example:
@HindenburgPlugin("hbplugin-fun-things")
export class MyPlugin extends RoomPlugin {
@EventListener("player.setcolor")
onPlayerSetColor(ev: PlayerSetColorEvent<Room>) {
this.logger.info("Player %s set their color to %s",
ev.player, Color[ev.newColor]);
}
}
You can access every symbol,
EventListener
,PlayerSetColorEvent
andColor
via the@skeldjs/hindenburg
package.
Many (not all) events will allow you to cancel what would normally happen, or allow you to revert any changes that the event made. Most events also allow you to change data, for example the room.assignroles
event allows you to modify the roles that will be assigned to players when the game starts.
Some events will also wait for any asynchronous tasks to complete.
Be careful what you do in certain events. The
room.fixedupdate
event, for example, can significantly slow down your server if handlers for this event take too long.
If you're writing a room plugin, only events emitted from that room will be listened to. Events attached to rooms or to the worker will be detached if your plugin is unloaded.
If you're working in TypeScript, due to a long-standing issue, you must specify the type of the event, making it slightly more verbose, i.e. ev: PlayerSendChatEvent<Room>
.
However, Hindenburg allows you to use this to your advantage, as you can omit the event name entirely from the @EventListener()
decorator, thanks to TypeScript's ability to emit type metadata for decorators. For example, you could instead do:
@EventListener()
onPlayerSetColor(ev: PlayerSetColorEvent<Room>) {
this.logger.info("Player %s set their color to %s",
ev.player, Color[ev.newColor]);
}
As Hindenburg is based upon skeldjs, it naturally inherits every event, which you can view here.
Hindenburg also adds a few more events, and modifies some skeldjs ones:
room.beforecreate
room.beforedestroy
room.create
room.destroy
room.gameend
room.gamestart
room.selecthost
Generated using TypeDoc