Skip to content

Commit

Permalink
idle notifier: add custom notifications
Browse files Browse the repository at this point in the history
Add custom notifications for:
HP Threshold
Prayer threshold
Low energy threshold
High energy threshold
Oxygen threshold
Spec threshold

Co-authored-by: DapperMickie <[email protected]>
  • Loading branch information
Adam- and DapperMickie committed Jun 24, 2024
1 parent 227af35 commit 6d46110
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import net.runelite.client.config.Range;
import net.runelite.client.config.Units;

@ConfigGroup("idlenotifier")
@ConfigGroup(IdleNotifierConfig.GROUP)
public interface IdleNotifierConfig extends Config
{
String GROUP = "idlenotifier";

@ConfigItem(
keyName = "animationidle",
name = "Idle Animation Notifications",
Expand Down Expand Up @@ -90,75 +92,145 @@ default int getIdleNotificationDelay()
return 5000;
}

@ConfigItem(
keyName = "hitpointsNotification",
name = "Hitpoints Notification",
description = "Configures if hitpoints notifications are enabled",
position = 6
)
default Notification getHitpointsNotification()
{
return Notification.OFF;
}

@ConfigItem(
keyName = "hitpoints",
name = "Hitpoints Threshold",
description = "The amount of hitpoints to send a notification at. A value of 0 will disable notification.",
position = 6
description = "The amount of hitpoints to send a notification at.",
position = 7
)
@Range(min = 1)
default int getHitpointsThreshold()
{
return 0;
return 1;
}

@ConfigItem(
keyName = "prayerNotification",
name = "Prayer Notification",
description = "Configures if prayer notifications are enabled.",
position = 8
)
default Notification getPrayerNotification()
{
return Notification.OFF;
}

@ConfigItem(
keyName = "prayer",
name = "Prayer Threshold",
description = "The amount of prayer points to send a notification at. A value of 0 will disable notification.",
position = 7
description = "The amount of prayer points to send a notification at.",
position = 9
)
@Range(min = 1)
default int getPrayerThreshold()
{
return 0;
return 1;
}

@ConfigItem(
keyName = "lowEnergyNotification",
name = "Low Energy Notification",
description = "Configures if low energy notifications are enabled",
position = 10
)
default Notification getLowEnergyNotification()
{
return Notification.OFF;
}

@ConfigItem(
keyName = "lowEnergy",
name = "Low Energy Threshold",
description = "The amount of energy points remaining to send a notification at. A value of 100 will disable notification.",
position = 8
description = "The amount of energy points remaining to send a notification at.",
position = 11
)
@Units(Units.PERCENT)
@Range(max = 100)
@Range(max = 99)
default int getLowEnergyThreshold()
{
return 100;
return 0;
}

@ConfigItem(
keyName = "highEnergyNotification",
name = "High Energy Notification",
description = "Configures if high energy notifications are enabled",
position = 12
)
default Notification getHighEnergyNotification()
{
return Notification.OFF;
}

@ConfigItem(
keyName = "highEnergy",
name = "High Energy Threshold",
description = "The amount of energy points reached to send a notification. A value of 0 will disable notification.",
position = 9
description = "The amount of energy points reached to send a notification.",
position = 13
)
@Units(Units.PERCENT)
@Range(max = 100)
@Range(min = 1, max = 100)
default int getHighEnergyThreshold()
{
return 0;
return 100;
}

@ConfigItem(
keyName = "oxygenNotification",
name = "Oxygen Notification",
description = "Configures if oxygen notifications are enabled",
position = 14
)
default Notification getOxygenNotification()
{
return Notification.OFF;
}

@ConfigItem(
keyName = "oxygen",
name = "Oxygen Threshold",
position = 10,
description = "The amount of remaining oxygen to send a notification at. A value of 0 will disable notification."
position = 15,
description = "The amount of remaining oxygen to send a notification at."
)
@Units(Units.PERCENT)
@Range(min = 1)
default int getOxygenThreshold()
{
return 0;
return 1;
}

@ConfigItem(
keyName = "specNotification",
name = "Spec Notification",
description = "Configures if special attack notifications are enabled",
position = 16
)
default Notification getSpecNotification()
{
return Notification.OFF;
}

@ConfigItem(
keyName = "spec",
name = "Spec Threshold",
position = 11,
description = "The amount of special attack energy reached to send a notification at. A value of 0 will disable notification."
position = 17,
description = "The amount of special attack energy reached to send a notification at."
)
@Units(Units.PERCENT)
@Range(min = 1)
default int getSpecEnergyThreshold()
{
return 0;
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.config.Notification;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
Expand Down Expand Up @@ -85,6 +86,9 @@ public class IdleNotifierPlugin extends Plugin
@Inject
private IdleNotifierConfig config;

@Inject
private ConfigManager configManager;

private Instant lastAnimating;
private int lastAnimation = IDLE;
private Instant lastInteracting;
Expand Down Expand Up @@ -117,6 +121,7 @@ protected void startUp()
{
// can't tell when 6hr will be if enabled while already logged in
sixHourWarningTime = null;
migrateConfig();
}

@Subscribe
Expand Down Expand Up @@ -548,32 +553,32 @@ public void onGameTick(GameTick event)

if (checkLowHitpoints())
{
notifier.notify("You have low hitpoints!");
notifier.notify(config.getHitpointsNotification(), "You have low hitpoints!");
}

if (checkLowPrayer())
{
notifier.notify("You have low prayer!");
notifier.notify(config.getPrayerNotification(), "You have low prayer!");
}

if (checkLowEnergy())
{
notifier.notify("You have low run energy!");
notifier.notify(config.getLowEnergyNotification(), "You have low run energy!");
}

if (checkHighEnergy())
{
notifier.notify("You have restored run energy!");
notifier.notify(config.getHighEnergyNotification(), "You have restored run energy!");
}

if (checkLowOxygen())
{
notifier.notify("You have low oxygen!");
notifier.notify(config.getOxygenNotification(), "You have low oxygen!");
}

if (checkFullSpecEnergy())
{
notifier.notify("You have restored spec energy!");
notifier.notify(config.getSpecNotification(), "You have restored spec energy!");
}
}

Expand All @@ -588,6 +593,83 @@ public void onVarbitChanged(VarbitChanged event)
}
}

private void migrateConfig()
{
String migrated = configManager.getConfiguration(IdleNotifierConfig.GROUP, "migrated");
if ("1".equals(migrated))
{
return;
}

int hitpointsThreshold = configManager.getConfiguration(IdleNotifierConfig.GROUP, "hitpoints", int.class);
if (hitpointsThreshold == 0)
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "hitpoints", 1);
configManager.setConfiguration(IdleNotifierConfig.GROUP, "hitpointsNotification", Notification.OFF);
}
else
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "hitpointsNotification", Notification.ON);
}

int prayerThreshold = configManager.getConfiguration(IdleNotifierConfig.GROUP, "prayer", int.class);
if (prayerThreshold == 0)
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "prayer", 1);
configManager.setConfiguration(IdleNotifierConfig.GROUP, "prayerNotification", Notification.OFF);
}
else
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "prayerNotification", Notification.ON);
}

int lowEnergyThreshold = configManager.getConfiguration(IdleNotifierConfig.GROUP, "lowEnergy", int.class);
if (lowEnergyThreshold == 100)
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "lowEnergy", 0);
configManager.setConfiguration(IdleNotifierConfig.GROUP, "lowEnergyNotification", Notification.OFF);
}
else
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "lowEnergyNotification", Notification.ON);
}

int highEnergyThreshold = configManager.getConfiguration(IdleNotifierConfig.GROUP, "highEnergy", int.class);
if (highEnergyThreshold == 0)
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "highEnergy", 100);
configManager.setConfiguration(IdleNotifierConfig.GROUP, "highEnergyNotification", Notification.OFF);
}
else
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "highEnergyNotification", Notification.ON);
}

int oxygenThreshold = configManager.getConfiguration(IdleNotifierConfig.GROUP, "oxygen", int.class);
if (oxygenThreshold == 0)
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "oxygen", 1);
configManager.setConfiguration(IdleNotifierConfig.GROUP, "oxygenNotification", Notification.OFF);
}
else
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "oxygenNotification", Notification.ON);
}

int specThreshold = configManager.getConfiguration(IdleNotifierConfig.GROUP, "spec", int.class);
if (specThreshold == 0)
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "spec", 1);
configManager.setConfiguration(IdleNotifierConfig.GROUP, "specNotification", Notification.OFF);
}
else
{
configManager.setConfiguration(IdleNotifierConfig.GROUP, "specNotification", Notification.ON);
}

configManager.setConfiguration(IdleNotifierConfig.GROUP, "migrated", 1);
}

private void checkNpcInteraction(final NPC target)
{
final NPCComposition npcComposition = target.getComposition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import net.runelite.api.events.HitsplatApplied;
import net.runelite.api.events.InteractingChanged;
import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.config.Notification;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -80,6 +81,10 @@ public class IdleNotifierPluginTest
@Bind
private Notifier notifier;

@Mock
@Bind
private ConfigManager configManager;

@Inject
private IdleNotifierPlugin plugin;

Expand Down Expand Up @@ -302,6 +307,7 @@ public void testSendOneNotificationForAnimationAndInteract()
@Test
public void testSpecRegen()
{
when(config.getSpecNotification()).thenReturn(Notification.ON);
when(config.getSpecEnergyThreshold()).thenReturn(50);

when(client.getVarpValue(eq(VarPlayer.SPECIAL_ATTACK_PERCENT))).thenReturn(400); // 40%
Expand All @@ -310,7 +316,7 @@ public void testSpecRegen()

when(client.getVarpValue(eq(VarPlayer.SPECIAL_ATTACK_PERCENT))).thenReturn(500); // 50%
plugin.onGameTick(new GameTick());
verify(notifier).notify(eq("You have restored spec energy!"));
verify(notifier).notify(Notification.ON, "You have restored spec energy!");
}

@Test
Expand Down

0 comments on commit 6d46110

Please sign in to comment.