Skip to content

Commit

Permalink
xp tracker plugin: Remove WorldClient usages
Browse files Browse the repository at this point in the history
The xp tracker plugin does not need to query for a list of available
worlds, it only needs to know the current world type, which can be found
using `Client.getWorldType()` instead. As such, usages of WorldClient
are substituted with this simpler method instead.

Closes runelite#4190
  • Loading branch information
Nightfirecat committed Jul 6, 2018
1 parent aa7f058 commit b274a25
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.google.common.eventbus.Subscribe;
import com.google.inject.Binder;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.EnumSet;
import java.util.Objects;
import javax.imageio.ImageIO;
Expand All @@ -40,6 +39,7 @@
import net.runelite.api.Player;
import net.runelite.api.Skill;
import net.runelite.api.VarPlayer;
import net.runelite.api.WorldType;
import net.runelite.api.events.ExperienceChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
Expand All @@ -49,10 +49,6 @@
import static net.runelite.client.plugins.xptracker.XpWorldType.NORMAL;
import net.runelite.client.ui.NavigationButton;
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;

@PluginDescriptor(
Expand All @@ -77,7 +73,6 @@ public class XpTrackerPlugin extends Plugin

private final XpState xpState = new XpState();

private WorldResult worlds;
private XpWorldType lastWorldType;
private String lastUsername;

Expand All @@ -92,24 +87,6 @@ public void configure(Binder binder)
@Override
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);

BufferedImage icon;
Expand Down Expand Up @@ -142,7 +119,7 @@ public void onGameStateChanged(GameStateChanged event)
{
// LOGGED_IN is triggered between region changes too.
// 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)
{
Expand All @@ -168,25 +145,6 @@ else if (event.getGameState() == GameState.LOGIN_SCREEN)
}
}

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)
{
XpWorldType xpType = NORMAL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
package net.runelite.client.plugins.xptracker;

import net.runelite.http.api.worlds.WorldType;
import net.runelite.api.WorldType;

enum XpWorldType
{
Expand Down

0 comments on commit b274a25

Please sign in to comment.