aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2024-08-21 15:15:30 -0400
committerAaron <51387595+AzureAaron@users.noreply.github.com>2024-08-21 15:15:30 -0400
commit74af6b2be167b045b42b9ea848c80265c283081f (patch)
tree44d0fa6cfe45aa7fdf2092b593df1d5f38347a80 /src/main/java
parent3f358afc7bc8f842daee8f91afcd9eeedf7be25a (diff)
downloadSkyblocker-74af6b2be167b045b42b9ea848c80265c283081f.tar.gz
Skyblocker-74af6b2be167b045b42b9ea848c80265c283081f.tar.bz2
Skyblocker-74af6b2be167b045b42b9ea848c80265c283081f.zip
Make scheduling more robust
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/Utils.java23
1 files changed, 16 insertions, 7 deletions
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);