Merge pull request #4194 from Nightfirecat/remove-worldclient-from-xptracker-plugin
Remove WorldClient usages from xp tracker plugin
This commit is contained in:
@@ -27,7 +27,7 @@ package net.runelite.client.plugins.xptracker;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
public enum SkillColor
|
enum SkillColor
|
||||||
{
|
{
|
||||||
ATTACK(105, 32, 7),
|
ATTACK(105, 32, 7),
|
||||||
DEFENCE(98, 119, 190),
|
DEFENCE(98, 119, 190),
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ class XpInfoBox extends JPanel
|
|||||||
expHour.setText(htmlLabel("XP/Hour: ", xpSnapshotSingle.getXpPerHour()));
|
expHour.setText(htmlLabel("XP/Hour: ", xpSnapshotSingle.getXpPerHour()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String htmlLabel(String key, int value)
|
static String htmlLabel(String key, int value)
|
||||||
{
|
{
|
||||||
String valueStr = StackFormatter.quantityToRSDecimalStack(value);
|
String valueStr = StackFormatter.quantityToRSDecimalStack(value);
|
||||||
|
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ class XpPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void updateTotal(XpSnapshotTotal xpSnapshotTotal)
|
void updateTotal(XpSnapshotTotal xpSnapshotTotal)
|
||||||
{
|
{
|
||||||
// if player has gained exp and hasn't switched displays yet, hide error panel and show overall info
|
// if player has gained exp and hasn't switched displays yet, hide error panel and show overall info
|
||||||
if (xpSnapshotTotal.getXpGainedInSession() > 0 && !overallPanel.isVisible())
|
if (xpSnapshotTotal.getXpGainedInSession() > 0 && !overallPanel.isVisible())
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class XpSnapshotTotal
|
|||||||
private final int xpGainedInSession;
|
private final int xpGainedInSession;
|
||||||
private final int xpPerHour;
|
private final int xpPerHour;
|
||||||
|
|
||||||
public static XpSnapshotTotal zero()
|
static XpSnapshotTotal zero()
|
||||||
{
|
{
|
||||||
return new XpSnapshotTotal(0, 0);
|
return new XpSnapshotTotal(0, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import static com.google.common.base.MoreObjects.firstNonNull;
|
|||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.google.inject.Binder;
|
import com.google.inject.Binder;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
@@ -40,6 +39,7 @@ import net.runelite.api.GameState;
|
|||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
import net.runelite.api.Skill;
|
import net.runelite.api.Skill;
|
||||||
import net.runelite.api.VarPlayer;
|
import net.runelite.api.VarPlayer;
|
||||||
|
import net.runelite.api.WorldType;
|
||||||
import net.runelite.api.events.ExperienceChanged;
|
import net.runelite.api.events.ExperienceChanged;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.GameTick;
|
import net.runelite.api.events.GameTick;
|
||||||
@@ -49,10 +49,6 @@ import net.runelite.client.plugins.PluginDescriptor;
|
|||||||
import static net.runelite.client.plugins.xptracker.XpWorldType.NORMAL;
|
import static net.runelite.client.plugins.xptracker.XpWorldType.NORMAL;
|
||||||
import net.runelite.client.ui.NavigationButton;
|
import net.runelite.client.ui.NavigationButton;
|
||||||
import net.runelite.client.ui.PluginToolbar;
|
import net.runelite.client.ui.PluginToolbar;
|
||||||
import net.runelite.http.api.worlds.World;
|
|
||||||
import net.runelite.http.api.worlds.WorldClient;
|
|
||||||
import net.runelite.http.api.worlds.WorldResult;
|
|
||||||
import net.runelite.http.api.worlds.WorldType;
|
|
||||||
import net.runelite.http.api.xp.XpClient;
|
import net.runelite.http.api.xp.XpClient;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
@@ -77,7 +73,6 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
|
|
||||||
private final XpState xpState = new XpState();
|
private final XpState xpState = new XpState();
|
||||||
|
|
||||||
private WorldResult worlds;
|
|
||||||
private XpWorldType lastWorldType;
|
private XpWorldType lastWorldType;
|
||||||
private String lastUsername;
|
private String lastUsername;
|
||||||
|
|
||||||
@@ -92,24 +87,6 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
WorldClient worldClient = new WorldClient();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
worlds = worldClient.lookupWorlds();
|
|
||||||
if (worlds != null)
|
|
||||||
{
|
|
||||||
log.debug("Worlds list contains {} worlds", worlds.getWorlds().size());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log.warn("Unable to look up worlds");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
log.warn("Error looking up worlds list", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
xpPanel = new XpPanel(this, client, skillIconManager);
|
xpPanel = new XpPanel(this, client, skillIconManager);
|
||||||
|
|
||||||
BufferedImage icon;
|
BufferedImage icon;
|
||||||
@@ -142,7 +119,7 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
// LOGGED_IN is triggered between region changes too.
|
// LOGGED_IN is triggered between region changes too.
|
||||||
// Check that the username changed or the world type changed.
|
// Check that the username changed or the world type changed.
|
||||||
XpWorldType type = getWorldType(client.getWorld());
|
XpWorldType type = worldSetToType(client.getWorldType());
|
||||||
|
|
||||||
if (!Objects.equals(client.getUsername(), lastUsername) || lastWorldType != type)
|
if (!Objects.equals(client.getUsername(), lastUsername) || lastWorldType != type)
|
||||||
{
|
{
|
||||||
@@ -168,25 +145,6 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private XpWorldType getWorldType(int worldNum)
|
|
||||||
{
|
|
||||||
if (worlds == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
World world = worlds.findWorld(worldNum);
|
|
||||||
|
|
||||||
if (world == null)
|
|
||||||
{
|
|
||||||
log.warn("Logged into nonexistent world {}?", client.getWorld());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
XpWorldType type = worldSetToType(world.getTypes());
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private XpWorldType worldSetToType(EnumSet<WorldType> types)
|
private XpWorldType worldSetToType(EnumSet<WorldType> types)
|
||||||
{
|
{
|
||||||
XpWorldType xpType = NORMAL;
|
XpWorldType xpType = NORMAL;
|
||||||
@@ -206,7 +164,7 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
* This is called by the user manually clicking resetSkillState in the UI.
|
* This is called by the user manually clicking resetSkillState in the UI.
|
||||||
* It reloads the current skills from the client after resetting internal state.
|
* It reloads the current skills from the client after resetting internal state.
|
||||||
*/
|
*/
|
||||||
public void resetAndInitState()
|
void resetAndInitState()
|
||||||
{
|
{
|
||||||
resetState();
|
resetState();
|
||||||
|
|
||||||
@@ -221,7 +179,7 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
* Throw out everything, the user has chosen a different account or world type.
|
* Throw out everything, the user has chosen a different account or world type.
|
||||||
* This resets both the internal state and UI elements
|
* This resets both the internal state and UI elements
|
||||||
*/
|
*/
|
||||||
public void resetState()
|
private void resetState()
|
||||||
{
|
{
|
||||||
xpState.reset();
|
xpState.reset();
|
||||||
xpPanel.resetAllInfoBoxes();
|
xpPanel.resetAllInfoBoxes();
|
||||||
@@ -233,7 +191,7 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
* Will also clear the skill from the UI.
|
* Will also clear the skill from the UI.
|
||||||
* @param skill Skill to reset
|
* @param skill Skill to reset
|
||||||
*/
|
*/
|
||||||
public void resetSkillState(Skill skill)
|
void resetSkillState(Skill skill)
|
||||||
{
|
{
|
||||||
int currentXp = client.getSkillExperience(skill);
|
int currentXp = client.getSkillExperience(skill);
|
||||||
xpState.resetSkill(skill, currentXp);
|
xpState.resetSkill(skill, currentXp);
|
||||||
@@ -246,7 +204,7 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
* Reset all skills except for the one provided
|
* Reset all skills except for the one provided
|
||||||
* @param skill Skill to ignore during reset
|
* @param skill Skill to ignore during reset
|
||||||
*/
|
*/
|
||||||
public void resetOtherSkillState(Skill skill)
|
void resetOtherSkillState(Skill skill)
|
||||||
{
|
{
|
||||||
for (Skill s : Skill.values())
|
for (Skill s : Skill.values())
|
||||||
{
|
{
|
||||||
@@ -289,7 +247,7 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
xpPanel.updateTotal(xpState.getTotalSnapshot());
|
xpPanel.updateTotal(xpState.getTotalSnapshot());
|
||||||
}
|
}
|
||||||
|
|
||||||
public XpSnapshotSingle getSkillSnapshot(Skill skill)
|
XpSnapshotSingle getSkillSnapshot(Skill skill)
|
||||||
{
|
{
|
||||||
return xpState.getSkillSnapshot(skill);
|
return xpState.getSkillSnapshot(skill);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.xptracker;
|
package net.runelite.client.plugins.xptracker;
|
||||||
|
|
||||||
import net.runelite.http.api.worlds.WorldType;
|
import net.runelite.api.WorldType;
|
||||||
|
|
||||||
enum XpWorldType
|
enum XpWorldType
|
||||||
{
|
{
|
||||||
@@ -32,7 +32,7 @@ enum XpWorldType
|
|||||||
DMM,
|
DMM,
|
||||||
SDMM;
|
SDMM;
|
||||||
|
|
||||||
public static XpWorldType of(WorldType type)
|
static XpWorldType of(WorldType type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user