Skip to content

Commit

Permalink
fix: avoid level notif when hopping from leagues (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy authored Nov 30, 2024
1 parent 2349318 commit 4904919
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased

- Bugfix: Avoid level notification when hopping worlds with different profiles like Leagues. (#615)

## 1.10.17

- Bugfix: Update KC regex for Jagex's Sol Heredit (Echo) mistake. (#620)
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/dinkplugin/notifiers/LevelNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.runelite.api.Experience;
import net.runelite.api.GameState;
import net.runelite.api.Skill;
import net.runelite.api.WorldType;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.StatChanged;
import net.runelite.client.callback.ClientThread;
Expand All @@ -38,6 +39,7 @@
public class LevelNotifier extends BaseNotifier {
public static final int LEVEL_FOR_MAX_XP = Experience.MAX_VIRT_LEVEL + 1; // 127
static final @VisibleForTesting int INIT_GAME_TICKS = 16; // ~10s
private static final Set<WorldType> SPECIAL_WORLDS = EnumSet.of(WorldType.PVP_ARENA, WorldType.QUEST_SPEEDRUNNING, WorldType.BETA_WORLD, WorldType.NOSAVE_MODE, WorldType.TOURNAMENT_WORLD, WorldType.DEADMAN, WorldType.SEASONAL);
private static final int SKILL_COUNT = Skill.values().length;
private static final String COMBAT_NAME = "Combat";
private static final Set<String> COMBAT_COMPONENTS;
Expand All @@ -47,6 +49,7 @@ public class LevelNotifier extends BaseNotifier {
private final Map<Skill, Integer> currentXp = new EnumMap<>(Skill.class);
private int ticksWaited = 0;
private int initTicks = 0;
private Set<WorldType> specialWorldType = null;

@Inject
private ClientThread clientThread;
Expand All @@ -68,6 +71,7 @@ private void initLevels() {
}
currentLevels.put(COMBAT_NAME, calculateCombatLevel());
this.initTicks = 0;
this.specialWorldType = getSpecialWorldTypes();
log.debug("Initialized current skill levels: {}", currentLevels);
}

Expand All @@ -79,6 +83,7 @@ public void reset() {
xpReached.clear();
currentXp.clear();
currentLevels.clear();
this.specialWorldType = null;
});
}

Expand Down Expand Up @@ -116,6 +121,9 @@ public void onStatChanged(StatChanged statChange) {
public void onGameStateChanged(GameStateChanged gameStateChanged) {
if (gameStateChanged.getGameState() == GameState.LOGIN_SCREEN) {
this.reset();
} else if (gameStateChanged.getGameState() == GameState.LOGGED_IN && !getSpecialWorldTypes().equals(this.specialWorldType)) {
// world switched where player may have different level profiles; re-initialize
this.reset();
}
}

Expand Down Expand Up @@ -370,6 +378,12 @@ private int getLevel(int xp) {
return Experience.getLevelForXp(xp);
}

private Set<WorldType> getSpecialWorldTypes() {
var world = client.getWorldType().clone();
world.retainAll(SPECIAL_WORLDS); // O(1)
return world;
}

private static String getSkillIcon(String skillName) {
return Utils.WIKI_IMG_BASE_URL + skillName + "_icon.png";
}
Expand Down

0 comments on commit 4904919

Please sign in to comment.