Event System
Learn how RuneLite's event system works and how to listen for game events in your plugins.
RuneLite uses an event-driven architecture. Think of events like notifications that the game sends out when something happens - like when a player logs in, an item is picked up, or a game tick occurs.
How Events Work
Events are like messages broadcast to all plugins that are listening. When something happens in the game:
1. RuneLite creates an event object
2. The event is sent to the EventBus
3. All registered plugins receive the event
4. Your plugin's event handler method is called
The Event Bus
The EventBus is like a radio station. Your plugin subscribes to specific "channels" (event types) it's interested in. When an event is broadcast on that channel, your plugin receives it.
Common Events
- **GameTick**: Fires every 0.6 seconds (one game tick)
- **PlayerChanged**: Fires when player data changes
- **ItemContainerChanged**: Fires when inventory/equipment changes
- **MenuEntryAdded**: Fires when right-click menu items are added
Best Practices
- RuneLite automatically registers @Subscribe methods in Plugin subclasses — no manual registration needed (deprecated since 2024)
- Use @Subscribe annotation on event handler methods
- Keep event handlers fast - they run on the game thread
- Prefer event-driven patterns (NpcSpawned, ItemSpawned, etc.) over GameTick polling for better performance
Code Examples
Example 1
1// No manual registration needed anymore!
2// RuneLite automatically registers @Subscribe methods
3
4@Subscribe
5public void onGameTick(GameTick event) {
6 // This runs every game tick
7 System.out.println("Game tick!");
8}Example 2
1// Listen for inventory changes
2@Subscribe
3public void onItemContainerChanged(ItemContainerChanged event) {
4 if (event.getContainerId() == InventoryID.INVENTORY.getId()) {
5 // Inventory changed!
6 ItemContainer container = event.getItemContainer();
7 // Process items...
8 }
9}