diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-03-07 21:46:17 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-07 11:46:17 +0100 |
commit | 7facd340b6e51d862a9e32977e56a7b0f69f3da0 (patch) | |
tree | 977d9d9c01518f660ed1b461e1ff2d3fc51d2612 /src/main/java/at/hannibal2/skyhanni/data | |
parent | 1181ef837104b4a5f68de6cf5793b21ad7573e03 (diff) | |
download | skyhanni-7facd340b6e51d862a9e32977e56a7b0f69f3da0.tar.gz skyhanni-7facd340b6e51d862a9e32977e56a7b0f69f3da0.tar.bz2 skyhanni-7facd340b6e51d862a9e32977e56a7b0f69f3da0.zip |
Backend: Use less forge events (#1085)
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") - } - } - } } |