diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt | 5 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt | 70 |
2 files changed, 38 insertions, 37 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt index 4650bda6d..915acf214 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt @@ -112,7 +112,10 @@ object ChatManager { val original = event.message val message = LorenzUtils.stripVanillaMessage(original.formattedText) - if (message.startsWith("§f{\"server\":\"")) return + if (message.startsWith("§f{\"server\":\"")) { + HypixelData.checkForLocraw(message) + return + } val key = IdentityCharacteristics(original) val chatEvent = LorenzChatEvent(message, original) if (!isSoopyMessage(event.message)) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index 8cce72bba..b206eb565 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -24,8 +24,6 @@ import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import com.google.gson.JsonObject import io.github.moulberry.notenoughupdates.NotEnoughUpdates import net.minecraft.client.Minecraft -import net.minecraftforge.client.event.ClientChatReceivedEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.network.FMLNetworkEvent import kotlin.concurrent.thread @@ -34,10 +32,6 @@ import kotlin.time.Duration.Companion.seconds class HypixelData { private val patternGroup = RepoPattern.group("data.hypixeldata") - private val lobbyTypePattern by patternGroup.pattern( - "lobbytype", - "(?<lobbyType>.*lobby)\\d+" - ) private val islandNamePattern by patternGroup.pattern( "islandname", "(?:§.)*(Area|Dungeon): (?:§.)*(?<island>.*)" @@ -55,6 +49,10 @@ class HypixelData { "serverid.tablist", " Server: §r§8(?<serverid>\\S+)" ) + private val lobbyTypePattern by patternGroup.pattern( + "lobbytype", + "(?<lobbyType>.*lobby)\\d+" + ) var hypixelLive = false var hypixelAlpha = false @@ -115,6 +113,36 @@ class HypixelData { return serverId } + + // This code is modified from NEU, and depends on NEU (or another mod) sending /locraw. + private val jsonBracketPattern = "^\\{.+}".toPattern() + + //todo convert to proper json object + fun checkForLocraw(message: String) { + jsonBracketPattern.matchMatcher(message.removeColor()) { + try { + val obj: JsonObject = gson.fromJson(group(), JsonObject::class.java) + if (obj.has("server")) { + locrawData = obj + locraw.keys.forEach { key -> + locraw[key] = obj[key]?.asString ?: "" + } + inLimbo = locraw["server"] == "limbo" + inLobby = locraw["lobbyname"] != "" + + if (inLobby) { + locraw["lobbyname"]?.let { + lobbyTypePattern.matchMatcher(it) { + locraw["lobbytype"] = group("lobbyType") + } + } + } + } + } catch (e: Exception) { + ErrorManager.logErrorWithData(e, "Failed to parse locraw data") + } + } + } } private var loggerIslandChange = LorenzLogger("debug/island_change") @@ -313,34 +341,4 @@ class HypixelData { return scoreboardTitle.contains("SKYBLOCK") || scoreboardTitle.contains("SKIBLOCK") // April 1st jokes are so funny } - - // This code is modified from NEU, and depends on NEU (or another mod) sending /locraw. - private val jsonBracketPattern = "^\\{.+}".toPattern() - - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onChatMessage(event: ClientChatReceivedEvent) { - jsonBracketPattern.matchMatcher(event.message.unformattedText) { - try { - val obj: JsonObject = gson.fromJson(group(), JsonObject::class.java) - if (obj.has("server")) { - locrawData = obj - locraw.keys.forEach { key -> - locraw[key] = obj[key]?.asString ?: "" - } - inLimbo = locraw["server"] == "limbo" - inLobby = locraw["lobbyname"] != "" - - if (inLobby) { - locraw["lobbyname"]?.let { - lobbyTypePattern.matchMatcher(it) { - locraw["lobbytype"] = group("lobbyType") - } - } - } - } - } catch (e: Exception) { - ErrorManager.logErrorWithData(e, "Failed to parse locraw data") - } - } - } } |