Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Events

Omegga reads console logs and emits events. Plugins hook these and run their own code in reaction.

EventArgumentsTrigger
*event, ...argsAny event is emitted
linelineA line of Brickadia console output
closednoneThe Brickadia server process closed
exitnoneThe Brickadia server exited
start{map}The server finished auth
host{id, name}The host was detected on server start
versionversionThe game CL was detected
unauthorizednoneThe server failed an auth check
mapchange{map}The map changed
autorestartAutoRestartConfigAn autorestart is scheduled
server:startingnoneOmegga is starting the game
server:stoppingnoneOmegga is stopping the game
server:stoppednoneThe game stopped
joinOmeggaPlayerA player joined
leaveOmeggaPlayerA player left
kickname, kicker, reasonA player was kicked
banname, kicker, reason, durationA player was banned
chatname, messageA player sent a chat message
cmdcommand, name, ...argsA player ran /command args. command is lowercased, args are the remaining space-separated words
cmd:commandname, ...argsSame, with the command built into the event name
chatcmdcommand, name, ...argsSame as cmd, for !command
chatcmd:commandname, ...argsSame as cmd:command, for !command
interactBrickInteractionA player clicked a brick with an interact component
event:NAMEplayer, ...argsAn interact component’s message was event:NAME:arg1,arg2. Escape a literal comma as \,
wirelograwA [Wire Graph] log line, without the prefix
wirecmdcommand, ...argsA [Wire Graph] log that starts with command args
wirecmd:command...argsSame, with the command built into the event name
minigamejoin{player: {name, id}, minigameName}Deprecated as of EA3. A player joined a minigame. minigameName is not unique, and is null when the player leaves all minigames. Runs before join
plugin:players:rawstring[][]Players joined or left. Raw player info, so RPC plugins can track who is online
plugin:statusname, pluginA plugin loaded, unloaded, started, or stopped

Node plugin usage

The Omegga object is an event emitter with an Omegga.on(event, fn) that returns the Omegga, so calls chain.

Omegga.on('start', () => {
  // run on server start
});
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}`);
  });

Deregister with Omegga.off('name', fn) or Omegga.removeAllListeners('name'). Be careful with removeAllListeners on non-cmd events, as it can deregister omegga’s own.

Node VM plugins do not need to clean up, because the VM goes away with the plugin. Node plugins do:

class Plugin {
  constructor(omegga) {
    this.omegga = omegga;

    // bind, or `this.foo()` inside exampleCallback will throw
    this.exampleCallback = this.exampleCallback.bind(this);
  }

  init() {
    this.omegga
      .on('chatcmd:ping', /* code */)
      .on('chat', this.exampleCallback);
  }

  exampleCallback() { /* code */ }

  stop() {
    this.omegga
      .removeAllListeners('chatcmd:ping')
      .off('chat', this.exampleCallback);
  }
}

RPC plugin usage

RPC plugins receive events as methods of the same name, with all arguments in an array.

// 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]) => {
  const [x, y, z] = await getPlayerPos(name);
  rpc.notify('broadcast', `<b>${name}</> is at ${x} ${y} ${z}`);
});