plugins: replace getUsername uses with getAccountHash

This commit is contained in:
Adam
2022-03-21 19:41:17 -04:00
parent bb0b30915d
commit d9f303adac
3 changed files with 16 additions and 15 deletions

View File

@@ -185,7 +185,7 @@ public class GrandExchangePlugin extends Plugin
private boolean wasFuzzySearch;
private String machineUuid;
private String lastUsername;
private long lastAccount;
private int tradeSeq;
/**
@@ -298,7 +298,8 @@ public class GrandExchangePlugin extends Plugin
clientToolbar.removeNavigation(button);
mouseManager.unregisterMouseListener(inputListener);
keyManager.unregisterKeyListener(inputListener);
lastUsername = machineUuid = null;
machineUuid = null;
lastAccount = -1L;
tradeSeq = 0;
}
@@ -893,13 +894,13 @@ public class GrandExchangePlugin extends Plugin
private String getMachineUuid()
{
String username = client.getUsername();
if (lastUsername == username)
long accountHash = client.getAccountHash();
if (lastAccount == accountHash)
{
return machineUuid;
}
lastUsername = username;
lastAccount = accountHash;
try
{
@@ -922,7 +923,7 @@ public class GrandExchangePlugin extends Plugin
hasher.putBytes(hardwareAddress);
}
}
hasher.putUnencodedChars(username);
hasher.putLong(accountHash);
machineUuid = hasher.hash().toString();
tradeSeq = 0;
return machineUuid;

View File

@@ -34,7 +34,6 @@ import java.awt.image.BufferedImage;
import java.time.temporal.ChronoUnit;
import java.util.EnumSet;
import java.util.List;
import java.util.Objects;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Setter;
@@ -123,7 +122,7 @@ public class XpTrackerPlugin extends Plugin
@VisibleForTesting
private XpPanel xpPanel;
private XpWorldType lastWorldType;
private String lastUsername;
private long lastAccount;
private long lastTickMillis = 0;
private boolean fetchXp; // fetch lastXp for the online xp tracker
private long lastXp = 0;
@@ -162,6 +161,7 @@ public class XpTrackerPlugin extends Plugin
// Initialize the tracker & last xp if already logged in
fetchXp = true;
initializeTracker = true;
lastAccount = -1L;
}
@Override
@@ -182,15 +182,15 @@ public class XpTrackerPlugin extends Plugin
// Check that the username changed or the world type changed.
XpWorldType type = worldSetToType(client.getWorldType());
if (!Objects.equals(client.getUsername(), lastUsername) || lastWorldType != type)
if (client.getAccountHash() != lastAccount || lastWorldType != type)
{
// Reset
log.debug("World change: {} -> {}, {} -> {}",
lastUsername, client.getUsername(),
lastAccount, client.getAccountHash(),
firstNonNull(lastWorldType, "<unknown>"),
firstNonNull(type, "<unknown>"));
lastUsername = client.getUsername();
lastAccount = client.getAccountHash();
// xp is not available until after login is finished, so fetch it on the next gametick
fetchXp = true;
lastWorldType = type;

View File

@@ -29,7 +29,6 @@ package net.runelite.client.plugins.xpupdater;
import com.google.inject.Provides;
import java.io.IOException;
import java.util.EnumSet;
import java.util.Objects;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
@@ -74,7 +73,7 @@ public class XpUpdaterPlugin extends Plugin
@Inject
private OkHttpClient okHttpClient;
private String lastUsername;
private long lastAccount;
private boolean fetchXp;
private long lastXp;
@@ -88,6 +87,7 @@ public class XpUpdaterPlugin extends Plugin
protected void startUp()
{
fetchXp = true;
lastAccount = -1L;
}
@Subscribe
@@ -96,9 +96,9 @@ public class XpUpdaterPlugin extends Plugin
GameState state = gameStateChanged.getGameState();
if (state == GameState.LOGGED_IN)
{
if (!Objects.equals(client.getUsername(), lastUsername))
if (lastAccount != client.getAccountHash())
{
lastUsername = client.getUsername();
lastAccount = client.getAccountHash();
fetchXp = true;
}
}