Fix XpGlobe displaying on no experience change
This commit is contained in:
@@ -33,6 +33,7 @@ import net.runelite.client.events.MapRegionChanged;
|
|||||||
import net.runelite.client.events.MenuOptionClicked;
|
import net.runelite.client.events.MenuOptionClicked;
|
||||||
import net.runelite.client.events.PlayerMenuOptionsChanged;
|
import net.runelite.client.events.PlayerMenuOptionsChanged;
|
||||||
import net.runelite.client.events.AnimationChanged;
|
import net.runelite.client.events.AnimationChanged;
|
||||||
|
import net.runelite.client.events.GameStateChanged;
|
||||||
import net.runelite.client.game.DeathChecker;
|
import net.runelite.client.game.DeathChecker;
|
||||||
import net.runelite.client.ui.overlay.OverlayRenderer;
|
import net.runelite.client.ui.overlay.OverlayRenderer;
|
||||||
import net.runelite.rs.api.MainBufferProvider;
|
import net.runelite.rs.api.MainBufferProvider;
|
||||||
@@ -118,6 +119,13 @@ public class Hooks
|
|||||||
runelite.getEventBus().post(animationChange);
|
runelite.getEventBus().post(animationChange);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "gameStateChanged":
|
||||||
|
{
|
||||||
|
GameStateChanged gameStateChange = new GameStateChanged();
|
||||||
|
gameStateChange.setGameState(RuneLite.getClient().getGameState());
|
||||||
|
runelite.getEventBus().post(gameStateChange);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
logger.warn("Unknown event {} triggered on {}", name, object);
|
logger.warn("Unknown event {} triggered on {}", name, object);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Steve <steve.rs.dev@gmail.com>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.client.events;
|
||||||
|
|
||||||
|
import net.runelite.api.GameState;
|
||||||
|
|
||||||
|
public class GameStateChanged
|
||||||
|
{
|
||||||
|
private GameState gameState;
|
||||||
|
|
||||||
|
public void setGameState(GameState gameState)
|
||||||
|
{
|
||||||
|
this.gameState = gameState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameState getGameState()
|
||||||
|
{
|
||||||
|
return gameState;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,9 +27,11 @@ package net.runelite.client.plugins.xpglobes;
|
|||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.Experience;
|
import net.runelite.api.Experience;
|
||||||
|
import net.runelite.api.GameState;
|
||||||
import net.runelite.api.Skill;
|
import net.runelite.api.Skill;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
import net.runelite.client.events.ExperienceChanged;
|
import net.runelite.client.events.ExperienceChanged;
|
||||||
|
import net.runelite.client.events.GameStateChanged;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
|
|
||||||
@@ -45,7 +47,7 @@ public class XpGlobes extends Plugin
|
|||||||
.getConfig(XpGlobesConfig.class);
|
.getConfig(XpGlobesConfig.class);
|
||||||
private final Overlay overlay = new XpGlobesOverlay(this);
|
private final Overlay overlay = new XpGlobesOverlay(this);
|
||||||
private final Client client = RuneLite.getClient();
|
private final Client client = RuneLite.getClient();
|
||||||
private final XpGlobe[] globeCache = new XpGlobe[Skill.values().length - 1]; //overall does not trigger xp change event
|
private XpGlobe[] globeCache = new XpGlobe[Skill.values().length - 1]; //overall does not trigger xp change event
|
||||||
private final List<XpGlobe> xpGlobes = new ArrayList<>();
|
private final List<XpGlobe> xpGlobes = new ArrayList<>();
|
||||||
private static final int SECONDS_TO_SHOW_GLOBE = 10;
|
private static final int SECONDS_TO_SHOW_GLOBE = 10;
|
||||||
private static final int MAXIMUM_SHOWN_GLOBES = 5;
|
private static final int MAXIMUM_SHOWN_GLOBES = 5;
|
||||||
@@ -79,6 +81,15 @@ public class XpGlobes extends Plugin
|
|||||||
Skill skill = event.getSkill();
|
Skill skill = event.getSkill();
|
||||||
int currentXp = client.getSkillExperience(skill);
|
int currentXp = client.getSkillExperience(skill);
|
||||||
int currentLevel = Experience.getLevelForXp(currentXp);
|
int currentLevel = Experience.getLevelForXp(currentXp);
|
||||||
|
int skillIdx = skill.ordinal();
|
||||||
|
XpGlobe cachedGlobe = globeCache[skillIdx];
|
||||||
|
|
||||||
|
// ExperienceChanged event occurs when stats drain/boost check we have an change to actual xp
|
||||||
|
if (cachedGlobe != null && (cachedGlobe.getCurrentXp() >= currentXp))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int startingXp = 0;
|
int startingXp = 0;
|
||||||
if (currentLevel > 1)
|
if (currentLevel > 1)
|
||||||
{
|
{
|
||||||
@@ -86,8 +97,6 @@ public class XpGlobes extends Plugin
|
|||||||
}
|
}
|
||||||
int goalXp = Experience.getXpForLevel(currentLevel + 1);
|
int goalXp = Experience.getXpForLevel(currentLevel + 1);
|
||||||
|
|
||||||
int skillIdx = skill.ordinal();
|
|
||||||
XpGlobe cachedGlobe = globeCache[skillIdx];
|
|
||||||
if (cachedGlobe != null)
|
if (cachedGlobe != null)
|
||||||
{
|
{
|
||||||
cachedGlobe.setSkill(skill);
|
cachedGlobe.setSkill(skill);
|
||||||
@@ -152,4 +161,23 @@ public class XpGlobes extends Plugin
|
|||||||
{
|
{
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetGlobeState()
|
||||||
|
{
|
||||||
|
xpGlobes.clear();
|
||||||
|
globeCache = new XpGlobe[Skill.values().length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onGameStateChanged(GameStateChanged event)
|
||||||
|
{
|
||||||
|
switch (event.getGameState())
|
||||||
|
{
|
||||||
|
case HOPPING:
|
||||||
|
case LOGGING_IN:
|
||||||
|
resetGlobeState();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user