aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorKevin <92656833+kevinthegreat1@users.noreply.github.com>2024-08-24 15:13:17 +0800
committerGitHub <noreply@github.com>2024-08-24 15:13:17 +0800
commitc32687eb6215a4ff5532d2e05ce1d482a1929174 (patch)
treeac89ceed00128d0dffdb8bce971b2075914cf09e /src/main/java
parentbe406952913c8440ae6061beea82c5a76ef58504 (diff)
parent74af6b2be167b045b42b9ea848c80265c283081f (diff)
downloadSkyblocker-c32687eb6215a4ff5532d2e05ce1d482a1929174.tar.gz
Skyblocker-c32687eb6215a4ff5532d2e05ce1d482a1929174.tar.bz2
Skyblocker-c32687eb6215a4ff5532d2e05ce1d482a1929174.zip
Merge pull request #947 from AzureAaron/profile-id-fix
Request Profile Id if we don't receive it
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/Utils.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java
index 7f91920b..4c6a5fa3 100644
--- a/src/main/java/de/hysky/skyblocker/utils/Utils.java
+++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java
@@ -6,6 +6,8 @@ import com.mojang.util.UndashedUuid;
import de.hysky.skyblocker.events.SkyblockEvents;
import de.hysky.skyblocker.mixins.accessors.MessageHandlerAccessor;
import de.hysky.skyblocker.skyblock.item.MuseumItemCache;
+import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
+import de.hysky.skyblocker.utils.scheduler.Scheduler;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.azureaaron.hmapi.data.rank.PackageRank;
@@ -69,6 +71,11 @@ public class Utils {
@NotNull
private static String profileId = "";
/**
+ * The server from which we last received the profile id message from.
+ */
+ @NotNull
+ private static int profileIdRequest = 0;
+ /**
* The following fields store data returned from the Mod API: {@link #environment}, {@link #server}, {@link #gameType}, {@link #locationRaw}, and {@link #map}.
*/
@SuppressWarnings("JavadocDeclaration")
@@ -408,6 +415,7 @@ public class Utils {
if (Utils.gameType.equals("SKYBLOCK")) {
isOnSkyblock = true;
+ tickProfileId();
if (!previousServerType.equals("SKYBLOCK")) SkyblockEvents.JOIN.invoker().onSkyblockJoin();
} else if (previousServerType.equals("SKYBLOCK")) {
@@ -441,6 +449,23 @@ public class Utils {
}
/**
+ * After 8 seconds of having swapped servers we check if we've been sent the profile id message on
+ * this server and if we haven't then we send the /profileid command.
+ */
+ private static void tickProfileId() {
+ profileIdRequest++;
+
+ Scheduler.INSTANCE.schedule(new Runnable() {
+ private final int requestId = profileIdRequest;
+
+ @Override
+ public void run() {
+ if (requestId == profileIdRequest) MessageScheduler.INSTANCE.sendMessageAfterCooldown("/profileid");
+ }
+ }, 20 * 8); //8 seconds
+ }
+
+ /**
* Parses /locraw chat message and updates {@link #server}, {@link #gameType}, {@link #locationRaw}, {@link #map}
* and {@link #location}
*
@@ -488,6 +513,8 @@ public class Utils {
} else if (message.startsWith(PROFILE_ID_PREFIX)) {
String prevProfileId = profileId;
profileId = message.substring(PROFILE_ID_PREFIX.length());
+ profileIdRequest++;
+
if (!prevProfileId.equals(profileId)) {
SkyblockEvents.PROFILE_CHANGE.invoker().onSkyblockProfileChange(prevProfileId, profileId);
}