-
Notifications
You must be signed in to change notification settings - Fork 8
Omegga Events API
Omegga operates by reading console logs and emitting events. Plugins can hook these events and run their own code to react to in-game triggers.
Event Name | Arguments | Trigger |
---|---|---|
* |
string event, ...args | Any event is emitted |
closed |
none | Brickadia server process closes |
exit |
none | Brickadia server exits |
line |
none | Brickadia server console output |
host |
none | Host is detected on server start |
start |
none | Brickadia server finishes auth |
mapchange |
{map: string} | Brickadia server changes map |
unauthorized |
none | Brickadia server fails auth check |
chat |
string name, string message | A chat message is sent by user named name with message message
|
cmd |
string command, string name, ...args | A chat command command (always lowercase) is run by a user named name , ...args is an array of strings taken from the chat message (split by space) |
cmd:command |
string name, ...args | Same as cmd but the command is built into the event handle rather than a variable |
chatcmd:command |
string name, ...args | Same as cmd:command but run when a player sends !command |
join |
Player player | A player joins the Brickadia server |
leave |
Player player | A player leaves the Brickadia server |
plugin:players:raw |
Array<Array> raw players | Emitted when players join or leave. players is an array of raw player info, used to help RPC plugins keep track of all online players |
version |
(string | number) version |
plugin:status |
string name, object plugin | A plugin loads/unloads/starts/stops |
The Omegga object is an EventListener that has an Omegga.on('event', fn)
method that returns an Omegga
so it can be chained.
To deregister an event, use Omegga.removeAllListeners('name')
or Omegga.off('name', fn)
. Be careful running Omegga.removeAllListeners()
on non-cmd events as it has the potential to deregister core events
Here is an example event handler run when the server starts.
Omegga.on('start', () => {
// run on server start
})
Here is an example of a chained event handler, one of which being asynchronous.
Omegga
.on('chatcmd:ping', (name, ...args) => {
Omegga.broadcast(`"pong @ ${name} + ${args.length} args"`);
})
.on('chatcmd:pos', async name => {
const [x, y, z] = await Omegga.getPlayer(name).getPosition();
Omegga.broadcast(`"<b>${name}</> is at ${x} ${y} ${z}"`);
});
If you are developing in an unsafe node plugin (omegga.main.js
) be sure cleanup any listeners that were created. Below is an example stop()
implementation of a plugin
class Plugin {
constructor(omegga) {
this.omegga = omegga;
// it's important to bind a function when used like this because
// it defines what `this` is in the `exampleCallback` method.
// without `bind`, code like `this.foo()` will error!
this.exampleCallback = this.exampleCallback.bind(this);
}
init() {
this.omegga
.on('chatcmd:ping', /* code */)
.on('chatcmd:pos', /* code */)
.on('chat', this.exampleCallback) // see constructor for info
}
exampleCallback() { /* code */}
stop() {
this.omegga
.removeAllListeners('chatcmd:ping')
.removeAllListeners('chatcmd:pos');
.off('chat', this.exampleCallback)
}
}
RPC Plugins receive events as methods by the same name. All arguments are passed in as an array.
Here is an example implementation in JavaScript, though other languages may have different implementations of JSON-RPC-2.0.
// ping command
rpc.addMethod('chatcmd:ping', ([name, ...args]) => {
rpc.notify('broadcast', `"pong @ ${name} + ${args.length} args"`);
});
// player position command
rpc.addMethod('chatcmd:pos', async ([name]) => {
log ('player', name, 'requests position');
const [x, y, z] = await getPlayerPos(name); // getPlayerPosition gets a player's position by name
rpc.notify('broadcast', `"<b>${name}</> is at ${x} ${y} ${z}"`);
});