From 3b40f945a71927e2c75bd2da528f3ed25a2577b0 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 7 Aug 2019 19:08:26 -0400 Subject: [PATCH] xptracker: move initialization until after login This fixes the xptracker not being properly initialized if it starts up after the player is already logged in. --- .../plugins/xptracker/XpTrackerPlugin.java | 64 +++++++++++++++---- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpTrackerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpTrackerPlugin.java index d178730ae5..6de3527bc9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpTrackerPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpTrackerPlugin.java @@ -120,6 +120,7 @@ public class XpTrackerPlugin extends Plugin private long lastTickMillis = 0; private boolean fetchXp; // fetch lastXp for the online xp tracker private long lastXp = 0; + private boolean initializeTracker; private final XpClient xpClient = new XpClient(); private final XpState xpState = new XpState(); @@ -153,8 +154,9 @@ public class XpTrackerPlugin extends Plugin clientToolbar.addNavigation(navButton); - // Initialize the last xp if already logged in + // Initialize the tracker & last xp if already logged in fetchXp = true; + initializeTracker = true; } @Override @@ -188,8 +190,14 @@ public class XpTrackerPlugin extends Plugin fetchXp = true; lastWorldType = type; resetState(); + // Must be set from hitting the LOGGING_IN case below + assert initializeTracker; } } + else if (state == GameState.LOGGING_IN) + { + initializeTracker = true; + } else if (state == GameState.LOGIN_SCREEN) { Player local = client.getLocalPlayer(); @@ -327,6 +335,12 @@ public class XpTrackerPlugin extends Plugin final int startGoalXp = startGoal != null ? client.getVar(startGoal) : -1; final int endGoalXp = endGoal != null ? client.getVar(endGoal) : -1; + if (initializeTracker) + { + // This is the XP sync on login, wait until after login to begin counting + return; + } + if (xpTrackerConfig.hideMaxed() && currentLevel >= Experience.MAX_REAL_LEVEL) { return; @@ -345,18 +359,9 @@ public class XpTrackerPlugin extends Plugin final XpUpdateResult updateResult = xpState.updateSkill(skill, currentXp, startGoalXp, endGoalXp); xpPanel.updateSkillExperience(updateResult == XpUpdateResult.UPDATED, xpPauseState.isPaused(skill), skill, xpState.getSkillSnapshot(skill)); - if (skill == Skill.CONSTRUCTION && updateResult == XpUpdateResult.INITIALIZED) - { - // Construction is the last skill initialized on login, now initialize the total experience - long overallXp = client.getOverallExperience(); - log.debug("Initializing XP tracker with {} overall exp", overallXp); - xpState.initializeSkill(Skill.OVERALL, overallXp); - } - else if (xpState.isInitialized(Skill.OVERALL)) - { - xpState.updateSkill(Skill.OVERALL, client.getOverallExperience(), -1, -1); - xpPanel.updateTotal(xpState.getTotalSnapshot()); - } + // Also update the total experience + xpState.updateSkill(Skill.OVERALL, client.getOverallExperience(), -1, -1); + xpPanel.updateTotal(xpState.getTotalSnapshot()); } @Subscribe @@ -382,12 +387,43 @@ public class XpTrackerPlugin extends Plugin @Subscribe public void onGameTick(GameTick event) { - rebuildSkills(); + if (initializeTracker) + { + initializeTracker = false; + + // Initialize the tracker with the initial xp if not already initialized + for (Skill skill : Skill.values()) + { + if (skill == Skill.OVERALL) + { + continue; + } + + if (!xpState.isInitialized(skill)) + { + final int currentXp = client.getSkillExperience(skill); + // goal exps are not necessary for skill initialization + XpUpdateResult xpUpdateResult = xpState.updateSkill(skill, currentXp, -1, -1); + assert xpUpdateResult == XpUpdateResult.INITIALIZED; + } + } + + // Initialize the overall xp + if (!xpState.isInitialized(Skill.OVERALL)) + { + long overallXp = client.getOverallExperience(); + log.debug("Initializing XP tracker with {} overall exp", overallXp); + xpState.initializeSkill(Skill.OVERALL, overallXp); + } + } + if (fetchXp) { lastXp = client.getOverallExperience(); fetchXp = false; } + + rebuildSkills(); } @Subscribe