From c2a3de433b5a169c7a4dcb138247457d09ad1d45 Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 12 Jun 2024 17:51:13 +0200 Subject: Improvement: Better Hypixel detection (#2064) --- .../java/at/hannibal2/skyhanni/data/HypixelData.kt | 40 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index 0e2f9af32..37e61257f 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -38,6 +38,14 @@ import kotlin.time.Duration.Companion.seconds class HypixelData { private val patternGroup = RepoPattern.group("data.hypixeldata") + private val serverNameConnectionPattern by patternGroup.pattern( + "servername.connection", + "(?.+\\.)?hypixel\\.net", + ) + private val serverNameScoreboardPattern by patternGroup.pattern( + "servername.scoreboard", + "§e(?.+\\.)?hypixel\\.net", + ) private val islandNamePattern by patternGroup.pattern( "islandname", "(?:§.)*(Area|Dungeon): (?:§.)*(?.*)", @@ -370,12 +378,34 @@ class HypixelData { } private fun checkHypixel() { - val list = ScoreboardData.sidebarLinesFormatted - if (list.isEmpty()) return + val mc = Minecraft.getMinecraft() + val player = mc.thePlayer ?: return + + var hypixel = false + + player.clientBrand?.let { + if (it.contains("hypixel", ignoreCase = true)) { + hypixel = true + } + } + + serverNameConnectionPattern.matchMatcher(mc.getCurrentServerData().serverIP) { + hypixel = true + if (group("prefix") == "alpha.") { + hypixelAlpha = true + } + } + + for (line in ScoreboardData.sidebarLinesFormatted) { + serverNameScoreboardPattern.matchMatcher(line) { + hypixel = true + if (group("prefix") == "alpha.") { + hypixelAlpha = true + } + } + } - val last = list.last() - hypixelLive = last == "§ewww.hypixel.net" - hypixelAlpha = last == "§ealpha.hypixel.net" + hypixelLive = hypixel && !hypixelAlpha } private fun checkSidebar() { -- cgit