From cc291932906c38943e20cee29ee591695a9875b5 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sun, 23 Jun 2024 18:13:52 +0200 Subject: Backend: Usage of TabWidget (#1240) Co-authored-by: Cal Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/data/HypixelData.kt | 22 ++++++++-------------- .../hannibal2/skyhanni/data/ProfileStorageData.kt | 17 +++++------------ 2 files changed, 13 insertions(+), 26 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/data') diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index 7599cc80f..82bd6d315 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -11,7 +11,6 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent -import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.events.WidgetUpdateEvent import at.hannibal2.skyhanni.events.minecraft.ClientDisconnectEvent import at.hannibal2.skyhanni.features.bingo.BingoAPI @@ -59,10 +58,6 @@ object HypixelData { "serverid.scoreboard", "§7\\d+/\\d+/\\d+ §8(?[mM])(?\\S+).*", ) - private val serverIdTablistPattern by patternGroup.pattern( - "serverid.tablist", - " Server: §r§8(?\\S+)", - ) private val lobbyTypePattern by patternGroup.pattern( "lobbytype", "(?.*lobby)\\d+", @@ -161,14 +156,14 @@ object HypixelData { if (LorenzUtils.lastWorldSwitch.passedSince() < 1.seconds) return if (!TabListData.fullyLoaded) return - ScoreboardData.sidebarLinesFormatted.matchFirst(serverIdScoreboardPattern) { - val serverType = if (group("servertype") == "M") "mega" else "mini" - serverId = "$serverType${group("serverid")}" + TabWidget.SERVER.matchMatcherFirstLine { + serverId = group("serverid") return } - TabListData.getTabList().matchFirst(serverIdTablistPattern) { - serverId = group("serverid") + ScoreboardData.sidebarLinesFormatted.matchFirst(serverIdScoreboardPattern) { + val serverType = if (group("servertype") == "M") "mega" else "mini" + serverId = "$serverType${group("serverid")}" return } @@ -301,11 +296,9 @@ object HypixelData { } } - @SubscribeEvent - fun onTabListUpdate(event: TabListUpdateEvent) { - event.tabList.matchFirst(UtilsPatterns.tabListProfilePattern) { + private fun checkProfile() { + TabWidget.PROFILE.matchMatcherFirstLine { var newProfile = group("profile").lowercase() - // Hypixel shows the profile name reversed while in the Rift if (RiftAPI.inRift()) newProfile = newProfile.reversed() if (profileName == newProfile) return @@ -374,6 +367,7 @@ object HypixelData { fun onTabListUpdate(event: WidgetUpdateEvent) { when (event.widget) { TabWidget.AREA -> checkIsland(event) + TabWidget.PROFILE -> checkProfile() else -> Unit } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt index 3d9bdcf78..18211ccd8 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt @@ -4,21 +4,20 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.SackData import at.hannibal2.skyhanni.config.storage.PlayerSpecificStorage import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage +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.ProfileJoinEvent -import at.hannibal2.skyhanni.events.TabListUpdateEvent +import at.hannibal2.skyhanni.events.WidgetUpdateEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.TabListData -import at.hannibal2.skyhanni.utils.UtilsPatterns import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.seconds @@ -75,15 +74,9 @@ object ProfileStorageData { } @SubscribeEvent - fun onTabListUpdate(event: TabListUpdateEvent) { - if (!LorenzUtils.inSkyBlock) return - - event.tabList.matchFirst(UtilsPatterns.tabListProfilePattern) { - noTabListTime = SimpleTimeMark.farPast() - return - } - - noTabListTime = SimpleTimeMark.now() + fun onTabListUpdate(event: WidgetUpdateEvent) { + if (!event.isWidget(TabWidget.PROFILE)) return + noTabListTime = if (event.isClear()) SimpleTimeMark.now() else SimpleTimeMark.farPast() } @SubscribeEvent -- cgit