diff --git a/GauntletTimer.java b/GauntletTimer.java index 0b2924b..ffe2334 100644 --- a/GauntletTimer.java +++ b/GauntletTimer.java @@ -72,20 +72,23 @@ class GauntletTimer extends Overlay { /** * This is called when the player resets the plugin mid-raid. We do not want to confuse the timer. + *
+ * TODO: Originally, this function will disable the timer if the plugin is started mid raid. + * Unfortunately, VARBITS can't be checked unless you're on the client thread. + * I've no idea how to access RL's task handler. + * Good luck to you. If you restart plugin mid raid, oh well. Your timer's going to be inaccurate. */ public void initStates() { - timeRaidStart = -1L; - timeBossEnter = -1L; - - if (client.getGameState() != GameState.STARTING && client.getGameState() != GameState.UNKNOWN) { - if (GauntletUtils.inRaid(client)) { - currentState = RaidState.IN_RAID; - if (GauntletUtils.inBoss(client)) { - currentState = RaidState.IN_BOSS; - } - } else - currentState = RaidState.UNKNOWN; - } +// timeRaidStart = -1L; +// timeBossEnter = -1L; +// +// if (GauntletUtils.inRaid(client)) { +// currentState = RaidState.IN_RAID; +// if (GauntletUtils.inBoss(client)) { +// currentState = RaidState.IN_BOSS; +// } +// } else +// currentState = RaidState.UNKNOWN; } /** @@ -122,13 +125,20 @@ class GauntletTimer extends Overlay { public void checkStates(boolean checkVarps) { final Player p = client.getLocalPlayer(); - if(p == null) + if (p == null) return; if (checkVarps) { - if (currentState == RaidState.UNKNOWN && GauntletUtils.inRaid(client) && !GauntletUtils.inBoss(client) && p.getHealthRatio() != 0) { // Player has started a new raid. - currentState = RaidState.IN_RAID; - timeRaidStart = System.currentTimeMillis(); + if (currentState == RaidState.UNKNOWN) { + if (GauntletUtils.inRaid(client) && p.getHealthRatio() != 0) { // Player has started a new raid. + if (!GauntletUtils.inBoss(client)) { + currentState = RaidState.IN_RAID; + timeRaidStart = System.currentTimeMillis(); + } else { + currentState = RaidState.IN_RAID; + timeRaidStart = timeBossEnter = System.currentTimeMillis(); + } + } } else if (currentState == RaidState.IN_RAID) { if (GauntletUtils.inRaid(client)) { if (GauntletUtils.inBoss(client)) { // Player has begun the boss fight. diff --git a/GauntletUtils.java b/GauntletUtils.java index 0ad41ff..b59f8d8 100644 --- a/GauntletUtils.java +++ b/GauntletUtils.java @@ -2,6 +2,7 @@ package net.runelite.client.plugins.gauntlet; import net.runelite.api.Client; import net.runelite.api.NPC; +import net.runelite.api.Varbits; public class GauntletUtils { @@ -138,7 +139,11 @@ public class GauntletUtils { * @return boolean */ public static boolean inRaid(Client client) { - return client.getVarbitValue(client.getVarps(), VARP_RAID_ROOM) == 1; + try { + return client.getVarbitValue(client.getVarps(), VARP_RAID_ROOM) == 1; + } catch (IndexOutOfBoundsException ignore) { + return false; + } } /** @@ -148,6 +153,10 @@ public class GauntletUtils { * @return boolean */ public static boolean inBoss(Client client) { - return client.getVarbitValue(client.getVarps(), VARP_BOSS_ROOM) == 1; + try { + return client.getVarbitValue(client.getVarps(), VARP_BOSS_ROOM) == 1; + } catch (IndexOutOfBoundsException ignore) { + return false; + } } }