Events

Reacting to changes in the game.

Events are a highly efficient way of reacting to changes in the game engine, such as Npcs spawning and despawning, Skill level-ups, or Varps changing. RuneMate offers a variety of listeners that can be leveraged to this end.

Listeners

The EventListener interfaces can be implemented in order to react to various events in-game. For example, we can use the EngineListener to run some code every tick:

MyEngineListener.java
public class MyEngineListener implements EngineListener {

    private int tick;

    @Override
    public void onEngineEvent(EngineEvent event) {
        if (event.getType() == EngineEvent.Type.SERVER_TICK) {
            tick++;
        }
    }

}

Event Dispatcher

The EventDispatcher is the core of the event framework, and all listeners must be registered with it. An instance of the EventDispatcher is provided by your bot instance:

MyBot.java
public class MyBot extends LoopingBot {

    private MyEngineListener listener;
    
    @Override
    public void onStart(String... args) {
        getEventDispatcher().addListener(listener);
    }
}

Last updated