From c96c8b979e327ae1d9d79d9c4198141717223204 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 7 Mar 2021 11:49:15 -0500 Subject: [PATCH] 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 --- .../client/plugins/barrows/BarrowsPlugin.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java index cde5c6bb73..0cb6174d6e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/barrows/BarrowsPlugin.java @@ -77,7 +77,6 @@ public class BarrowsPlugin extends Plugin private static final int CRYPT_REGION_ID = 14231; private LoopTimer barrowsPrayerDrainTimer; - private boolean wasInCrypt = false; @Getter private Widget puzzleAnswer; @@ -128,7 +127,6 @@ public class BarrowsPlugin extends Plugin overlayManager.remove(barrowsOverlay); overlayManager.remove(brotherOverlay); puzzleAnswer = null; - wasInCrypt = false; stopPrayerDrainTimer(); // Restore widgets @@ -157,18 +155,14 @@ public class BarrowsPlugin extends Plugin @Subscribe public void onGameStateChanged(GameStateChanged event) { - if (event.getGameState() == GameState.LOADING) - { - wasInCrypt = isInCrypt(); - } - else if (event.getGameState() == GameState.LOGGED_IN) + if (event.getGameState() == GameState.LOGGED_IN) { boolean isInCrypt = isInCrypt(); - if (wasInCrypt && !isInCrypt) + if (!isInCrypt && barrowsPrayerDrainTimer != null) { stopPrayerDrainTimer(); } - else if (!wasInCrypt && isInCrypt) + else if (isInCrypt && barrowsPrayerDrainTimer == null) { startPrayerDrainTimer(); } @@ -233,6 +227,7 @@ public class BarrowsPlugin extends Plugin { if (config.showPrayerDrainTimer()) { + assert barrowsPrayerDrainTimer == null; final LoopTimer loopTimer = new LoopTimer( PRAYER_DRAIN_INTERVAL_MS, ChronoUnit.MILLIS,