package at.hannibal2.skyhanni.features.chat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.ChatManager import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class WatchdogHider { private var inWatchdog = false private var blockedLines = 0 private var startLineComponent: IChatComponent? = null @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { if (!LorenzUtils.onHypixel || !SkyHanniMod.feature.chat.filterType.watchDog) return when (event.message) { watchdogStartLine -> { startLineComponent = event.chatComponent blockedLines = 0 } watchdogAnnouncementLine -> { ChatManager.retractMessage(startLineComponent, "watchdog") startLineComponent = null inWatchdog = true } watchdogEndLine -> { event.blockedReason = "watchdog" inWatchdog = false } } if (inWatchdog) { event.blockedReason = "watchdog" blockedLines++ if (blockedLines > 10) { blockedLines = 0 inWatchdog = false } } } companion object { private const val watchdogStartLine = "§f" private const val watchdogAnnouncementLine = "§4[WATCHDOG ANNOUNCEMENT]" private const val watchdogEndLine = "§c" } @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.move(3, "chat.watchDog", "chat.filterType.watchDog") } }