Notifications & Alerts
Learn how to send notifications to users for level ups, achievements, warnings, and other important events.
Notifications are messages that appear in RuneLite's notification area. They're perfect for:
- Level-up celebrations
- Achievement alerts
- Warning messages
- Important status updates
NotificationManager
NotificationManager handles sending notifications. You inject it and call notify():
@Inject
private NotificationManager notificationManager;
notificationManager.notify(
"Title",
"Message",
NotificationType.LEVEL_UP
);
Notification Types
Common types:
- **LEVEL_UP**: For skill level ups
- **ACHIEVEMENT**: For achievements
- **GAMEMESSAGE**: General game messages
- **TRADE**: Trade-related notifications
Level-Up Notifications
A common use case is notifying on level ups:
private final Map<Skill, Integer> lastLevels = new HashMap<>();
@Subscribe
public void onStatChanged(StatChanged event) {
Skill skill = event.getSkill();
int newLevel = event.getLevel();
int lastLevel = lastLevels.getOrDefault(skill, 1);
if (newLevel > lastLevel) {
notificationManager.notify(
"Level Up!",
"Congratulations on reaching level " + newLevel +
" in " + skill.getName() + "!",
NotificationType.LEVEL_UP
);
lastLevels.put(skill, newLevel);
}
}
Warning Notifications
You can also send warnings for low health, low prayer, etc.:
@Subscribe
public void onGameTick(GameTick event) {
Player player = client.getLocalPlayer();
if (player != null) {
int healthRatio = player.getHealthRatio();
int maxHP = player.getMaxHealth();
int currentHP = (healthRatio * maxHP) / 255;
int healthPercent = (currentHP * 100) / maxHP;
if (healthPercent < 25 && !hasWarned) {
notificationManager.notify(
"Low Health!",
"Your health is at " + healthPercent + "%",
NotificationType.GAMEMESSAGE
);
hasWarned = true;
} else if (healthPercent > 50) {
hasWarned = false;
}
}
}
Best Practices
- Don't spam notifications - users will disable them
- Use appropriate NotificationType for each case
- Use flags to prevent duplicate notifications
- Keep messages concise and clear
Code Examples
Example 1
1// Send level-up notification
2@Inject
3private NotificationManager notificationManager;
4
5private final Map<Skill, Integer> lastLevels = new HashMap<>();
6
7@Subscribe
8public void onStatChanged(StatChanged event) {
9 Skill skill = event.getSkill();
10 int newLevel = event.getLevel();
11 int lastLevel = lastLevels.getOrDefault(skill, 1);
12
13 if (newLevel > lastLevel) {
14 notificationManager.notify(
15 "Level Up!",
16 "Congratulations on reaching level " + newLevel +
17 " in " + skill.getName() + "!",
18 NotificationType.LEVEL_UP
19 );
20 lastLevels.put(skill, newLevel);
21 }
22}Example 2
1// Send low health warning
2private boolean hasWarned = false;
3
4@Subscribe
5public void onGameTick(GameTick event) {
6 Player player = client.getLocalPlayer();
7 if (player != null) {
8 int healthRatio = player.getHealthRatio();
9 int maxHP = player.getMaxHealth();
10 if (maxHP == 0) maxHP = 255;
11
12 int currentHP = (healthRatio * maxHP) / 255;
13 int healthPercent = (currentHP * 100) / maxHP;
14
15 if (healthPercent < 25 && !hasWarned) {
16 notificationManager.notify(
17 "Low Health Warning!",
18 "Your health is at " + healthPercent + "%",
19 NotificationType.GAMEMESSAGE
20 );
21 hasWarned = true;
22 } else if (healthPercent > 50) {
23 hasWarned = false; // Reset warning
24 }
25 }
26}