regenmeter: add option to notify before next hp regen

This commit is contained in:
seandewar
2019-05-08 04:11:25 +01:00
parent 9623ed4b30
commit a8728b9b56
2 changed files with 31 additions and 2 deletions

View File

@@ -57,4 +57,14 @@ public interface RegenMeterConfig extends Config
{
return false;
}
@ConfigItem(
keyName = "notifyBeforeHpRegenDuration",
name = "Hitpoint Regen Notification (seconds)",
description = "Notify approximately when your next hitpoint is about to regen. A value of 0 will disable notification."
)
default int getNotifyBeforeHpRegenSeconds()
{
return 0;
}
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018 Abex
* Copyright (c) 2019, Sean Dewar <https://github.com/seandewar>
* Copyright (c) 2018, Abex
* Copyright (c) 2018, Zimaya <https://github.com/Zimaya>
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* All rights reserved.
@@ -30,6 +31,7 @@ import com.google.inject.Provides;
import javax.inject.Inject;
import lombok.Getter;
import net.runelite.api.Client;
import net.runelite.api.Constants;
import net.runelite.api.GameState;
import net.runelite.api.Prayer;
import net.runelite.api.Skill;
@@ -37,6 +39,7 @@ import net.runelite.api.VarPlayer;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
@@ -46,7 +49,7 @@ import net.runelite.client.ui.overlay.OverlayManager;
@PluginDescriptor(
name = "Regeneration Meter",
description = "Track and show the hitpoints and special attack regeneration timers",
tags = {"combat", "health", "hitpoints", "special", "attack", "overlay"}
tags = {"combat", "health", "hitpoints", "special", "attack", "overlay", "notifications"}
)
public class RegenMeterPlugin extends Plugin
{
@@ -59,6 +62,9 @@ public class RegenMeterPlugin extends Plugin
@Inject
private OverlayManager overlayManager;
@Inject
private Notifier notifier;
@Inject
private RegenMeterOverlay overlay;
@@ -149,5 +155,18 @@ public class RegenMeterPlugin extends Plugin
// Show it going down
hitpointsPercentage = 1 - hitpointsPercentage;
}
if (config.getNotifyBeforeHpRegenSeconds() > 0 && currentHP < maxHP && shouldNotifyHpRegenThisTick(ticksPerHPRegen))
{
notifier.notify("[" + client.getLocalPlayer().getName() + "] regenerates their next hitpoint soon!");
}
}
private boolean shouldNotifyHpRegenThisTick(int ticksPerHPRegen)
{
// if the configured duration lies between two ticks, choose the earlier tick
final int ticksBeforeHPRegen = ticksPerHPRegen - ticksSinceHPRegen;
final int notifyTick = (int) Math.ceil(config.getNotifyBeforeHpRegenSeconds() * 1000d / Constants.GAME_TICK_LENGTH);
return ticksBeforeHPRegen == notifyTick;
}
}