From 3f358afc7bc8f842daee8f91afcd9eeedf7be25a Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Tue, 20 Aug 2024 00:26:28 -0400 Subject: Request Profile Id if we don't receive it --- src/main/java/de/hysky/skyblocker/utils/Utils.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java index 7f91920b..52df4d91 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; @@ -68,6 +70,7 @@ public class Utils { */ @NotNull private static String profileId = ""; + private static boolean receivedProfileId = false; /** * The following fields store data returned from the Mod API: {@link #environment}, {@link #server}, {@link #gameType}, {@link #locationRaw}, and {@link #map}. */ @@ -408,6 +411,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")) { @@ -440,6 +444,18 @@ public class Utils { } } + /** + * After 8 seconds of having swapped servers we send the /profileid command if we didn't + * yet receive the profile id message. + */ + private static void tickProfileId() { + receivedProfileId = false; + + Scheduler.INSTANCE.schedule(() -> { + if (!receivedProfileId) 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 +504,8 @@ public class Utils { } else if (message.startsWith(PROFILE_ID_PREFIX)) { String prevProfileId = profileId; profileId = message.substring(PROFILE_ID_PREFIX.length()); + receivedProfileId = true; + if (!prevProfileId.equals(profileId)) { SkyblockEvents.PROFILE_CHANGE.invoker().onSkyblockProfileChange(prevProfileId, profileId); } -- cgit From 74af6b2be167b045b42b9ea848c80265c283081f Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:15:30 -0400 Subject: Make scheduling more robust --- src/main/java/de/hysky/skyblocker/utils/Utils.java | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java index 52df4d91..4c6a5fa3 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Utils.java +++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java @@ -70,7 +70,11 @@ public class Utils { */ @NotNull private static String profileId = ""; - private static boolean receivedProfileId = false; + /** + * 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}. */ @@ -445,14 +449,19 @@ public class Utils { } /** - * After 8 seconds of having swapped servers we send the /profileid command if we didn't - * yet receive the profile id message. + * 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() { - receivedProfileId = false; + profileIdRequest++; + + Scheduler.INSTANCE.schedule(new Runnable() { + private final int requestId = profileIdRequest; - Scheduler.INSTANCE.schedule(() -> { - if (!receivedProfileId) MessageScheduler.INSTANCE.sendMessageAfterCooldown("/profileid"); + @Override + public void run() { + if (requestId == profileIdRequest) MessageScheduler.INSTANCE.sendMessageAfterCooldown("/profileid"); + } }, 20 * 8); //8 seconds } @@ -504,7 +513,7 @@ public class Utils { } else if (message.startsWith(PROFILE_ID_PREFIX)) { String prevProfileId = profileId; profileId = message.substring(PROFILE_ID_PREFIX.length()); - receivedProfileId = true; + profileIdRequest++; if (!prevProfileId.equals(profileId)) { SkyblockEvents.PROFILE_CHANGE.invoker().onSkyblockProfileChange(prevProfileId, profileId); -- cgit