diff options
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/Utils.java | 27 |
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); } |
