From 6af9397f43561548086b8ed7fcfb5690136278ea Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 5 Aug 2023 17:42:49 +0200 Subject: added safety check for ChatManager.retractMessage calls to prevent blocking all chat messages when hypixel changes the format --- .../skyhanni/features/chat/CompactBestiaryChatMessage.kt | 11 +++++++---- .../java/at/hannibal2/skyhanni/features/chat/WatchdogHider.kt | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/CompactBestiaryChatMessage.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/CompactBestiaryChatMessage.kt index 67c76617b..d36f8ba35 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/CompactBestiaryChatMessage.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/CompactBestiaryChatMessage.kt @@ -4,12 +4,8 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.ChatManager import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.ChatLine import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.relauncher.ReflectionHelper class CompactBestiaryChatMessage { @@ -17,6 +13,7 @@ class CompactBestiaryChatMessage { var bestiaryDescription = mutableListOf() var acceptMoreDescription = true var command = "" + private var blockedLines = 0 var lastBorder: IChatComponent? = null var lastEmpty: IChatComponent? = null @@ -54,9 +51,15 @@ class CompactBestiaryChatMessage { } } inBestiary = true + blockedLines = 0 bestiaryDescription.add(message.trim()) } else if (inBestiary) { event.blockedReason = "bestiary" + blockedLines++ + if (blockedLines > 10) { + blockedLines = 0 + inBestiary = false + } if (message == border) { inBestiary = false diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/WatchdogHider.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/WatchdogHider.kt index 60ad41e61..099d52067 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/WatchdogHider.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/WatchdogHider.kt @@ -4,16 +4,13 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.ChatManager import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.ChatLine import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.relauncher.ReflectionHelper class WatchdogHider { private var inWatchdog = false + private var blockedLines = 0 private var startLineComponent: IChatComponent? = null @SubscribeEvent @@ -23,6 +20,7 @@ class WatchdogHider { when (event.message) { watchdogStartLine -> { startLineComponent = event.chatComponent + blockedLines = 0 } watchdogAnnouncementLine -> { ChatManager.retractMessage(startLineComponent, "watchdog") @@ -37,6 +35,11 @@ class WatchdogHider { if (inWatchdog) { event.blockedReason = "watchdog" + blockedLines++ + if (blockedLines > 10) { + blockedLines = 0 + inWatchdog = false + } } } -- cgit