barrows: simplify timer creation logic
There is a rare bug which can cause multiple timers to appear at once, and although I cannot figure out what is wrong with the existing code, this simplifies the logic sufficiently that it shouldn't happen anymore. Co-authored-by: Alexsuperfly <alexcsumner@gmail.com>
This commit is contained in:
@@ -77,7 +77,6 @@ public class BarrowsPlugin extends Plugin
|
|||||||
private static final int CRYPT_REGION_ID = 14231;
|
private static final int CRYPT_REGION_ID = 14231;
|
||||||
|
|
||||||
private LoopTimer barrowsPrayerDrainTimer;
|
private LoopTimer barrowsPrayerDrainTimer;
|
||||||
private boolean wasInCrypt = false;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private Widget puzzleAnswer;
|
private Widget puzzleAnswer;
|
||||||
@@ -128,7 +127,6 @@ public class BarrowsPlugin extends Plugin
|
|||||||
overlayManager.remove(barrowsOverlay);
|
overlayManager.remove(barrowsOverlay);
|
||||||
overlayManager.remove(brotherOverlay);
|
overlayManager.remove(brotherOverlay);
|
||||||
puzzleAnswer = null;
|
puzzleAnswer = null;
|
||||||
wasInCrypt = false;
|
|
||||||
stopPrayerDrainTimer();
|
stopPrayerDrainTimer();
|
||||||
|
|
||||||
// Restore widgets
|
// Restore widgets
|
||||||
@@ -157,18 +155,14 @@ public class BarrowsPlugin extends Plugin
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameStateChanged(GameStateChanged event)
|
public void onGameStateChanged(GameStateChanged event)
|
||||||
{
|
{
|
||||||
if (event.getGameState() == GameState.LOADING)
|
if (event.getGameState() == GameState.LOGGED_IN)
|
||||||
{
|
|
||||||
wasInCrypt = isInCrypt();
|
|
||||||
}
|
|
||||||
else if (event.getGameState() == GameState.LOGGED_IN)
|
|
||||||
{
|
{
|
||||||
boolean isInCrypt = isInCrypt();
|
boolean isInCrypt = isInCrypt();
|
||||||
if (wasInCrypt && !isInCrypt)
|
if (!isInCrypt && barrowsPrayerDrainTimer != null)
|
||||||
{
|
{
|
||||||
stopPrayerDrainTimer();
|
stopPrayerDrainTimer();
|
||||||
}
|
}
|
||||||
else if (!wasInCrypt && isInCrypt)
|
else if (isInCrypt && barrowsPrayerDrainTimer == null)
|
||||||
{
|
{
|
||||||
startPrayerDrainTimer();
|
startPrayerDrainTimer();
|
||||||
}
|
}
|
||||||
@@ -233,6 +227,7 @@ public class BarrowsPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
if (config.showPrayerDrainTimer())
|
if (config.showPrayerDrainTimer())
|
||||||
{
|
{
|
||||||
|
assert barrowsPrayerDrainTimer == null;
|
||||||
final LoopTimer loopTimer = new LoopTimer(
|
final LoopTimer loopTimer = new LoopTimer(
|
||||||
PRAYER_DRAIN_INTERVAL_MS,
|
PRAYER_DRAIN_INTERVAL_MS,
|
||||||
ChronoUnit.MILLIS,
|
ChronoUnit.MILLIS,
|
||||||
|
|||||||
Reference in New Issue
Block a user