From a3c940937bccd9f92acdc3ad2abe8e39e71ca847 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 30 Jul 2024 10:28:05 +0200 Subject: [PATCH] Improvement: Fewer Tab list chat errors (#2266) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../config/storage/PlayerSpecificStorage.java | 3 ++ .../at/hannibal2/skyhanni/data/HypixelData.kt | 1 + .../skyhanni/data/ProfileStorageData.kt | 52 ++++++++++++------- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/PlayerSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/PlayerSpecificStorage.java index 171cb82b1b38..c3b949c79235 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/PlayerSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/PlayerSpecificStorage.java @@ -22,6 +22,9 @@ public class PlayerSpecificStorage { @Expose public Boolean useRomanNumerals = true; + @Expose + public Boolean multipleProfiles = false; + @Expose public Integer gardenCommunityUpgrade = -1; diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index dbcf1276047a..bc43a807e02e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -293,6 +293,7 @@ object HypixelData { if (profileName == newProfile) return profileName = newProfile ProfileJoinEvent(newProfile).postAndCatch() + ProfileStorageData.profileJoinMessage() } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt index 18211ccd8637..ad119804baed 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.data.model.TabWidget import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.HypixelJoinEvent import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.events.WidgetUpdateEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @@ -32,6 +33,7 @@ object ProfileStorageData { private var sackPlayers: SackData.PlayerSpecific? = null var sackProfiles: SackData.ProfileSpecific? = null + var hypixelDataLoaded = false @SubscribeEvent(priority = EventPriority.HIGHEST) fun onProfileJoin(event: ProfileJoinEvent) { @@ -84,24 +86,28 @@ object ProfileStorageData { if (!LorenzUtils.inSkyBlock) return if (noTabListTime == SimpleTimeMark.farPast()) return - if (noTabListTime.passedSince() > 3.seconds) { - noTabListTime = SimpleTimeMark.now() - val foundSkyBlockTabList = TabListData.getTabList().any { it.contains("§b§lArea:") } - if (foundSkyBlockTabList) { - ChatUtils.clickableChat( - "§cCan not read profile name from tab list! Open /widget and enable Profile Widget. " + - "This is needed for the mod to function! And therefore this warning cannot be disabled", - onClick = { - HypixelCommands.widget() - }, - "§eClick to run /widget!", - ) - } else { - ChatUtils.chat( - "§cExtra Information from Tab list not found! " + - "Enable it: SkyBlock Menu ➜ Settings ➜ Personal ➜ User Interface ➜ Player List Info", - ) - } + playerSpecific?.let { + // do not try to load the data when hypixel has not yet send the profile loaded message + if (it.multipleProfiles && !hypixelDataLoaded) return + } + + if (noTabListTime.passedSince() < 5.seconds) return + noTabListTime = SimpleTimeMark.now() + val foundSkyBlockTabList = TabListData.getTabList().any { it.contains("§b§lArea:") } + if (foundSkyBlockTabList) { + ChatUtils.clickableChat( + "§cCan not read profile name from tab list! Open /widget and enable Profile Widget. " + + "This is needed for the mod to function! And therefore this warning cannot be disabled", + onClick = { + HypixelCommands.widget() + }, + "§eClick to run /widget!", + ) + } else { + ChatUtils.chat( + "§cExtra Information from Tab list not found! " + + "Enable it: SkyBlock Menu ➜ Settings ➜ Personal ➜ User Interface ➜ Player List Info", + ) } } @@ -124,4 +130,14 @@ object ProfileStorageData { sackPlayers = SkyHanniMod.sackData.players.getOrPut(playerUuid) { SackData.PlayerSpecific() } ConfigLoadEvent().postAndCatch() } + + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + hypixelDataLoaded = false + } + + fun profileJoinMessage() { + hypixelDataLoaded = true + playerSpecific?.multipleProfiles = true + } }