From 08ad28fd7b0360db41734c74f5441916dca1f5f4 Mon Sep 17 00:00:00 2001 From: Appability Date: Fri, 22 Dec 2023 16:48:59 -0800 Subject: [PATCH 1/2] fix history blocking all sea creature messages when some features enabled --- .../fishing/SeaCreatureMessageShortener.kt | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureMessageShortener.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureMessageShortener.kt index 0525031c035b..acaa8bdff82b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureMessageShortener.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureMessageShortener.kt @@ -3,6 +3,8 @@ package at.hannibal2.skyhanni.features.fishing import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.SeaCreatureFishEvent import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.util.ChatComponentText +import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class SeaCreatureMessageShortener { @@ -11,18 +13,19 @@ class SeaCreatureMessageShortener { @SubscribeEvent fun onSeaCreatureFish(event: SeaCreatureFishEvent) { if (!LorenzUtils.inSkyBlock) return - if (!config.shortenFishingMessage && !config.compactDoubleHook) return - val seaCreature = event.seaCreature - event.chatEvent.blockedReason = "sea_creature_caught" - val doubleHookPrefix = if (config.compactDoubleHook && event.doubleHook) "§e§lDOUBLE HOOK! " else "" - val message = doubleHookPrefix + if (config.shortenFishingMessage) { - "§9You caught a ${seaCreature.displayName}§9!" - } else event.chatEvent.message - LorenzUtils.chat(message, false) + val original = event.chatEvent.chatComponent.formattedText + var edited = original - if (seaCreature.fishingExperience == 0) { - LorenzUtils.debug("no fishing exp set for " + seaCreature.name) + if (config.shortenFishingMessage) { + edited = "§9You caught a ${event.seaCreature.displayName}§9!" } + + if (config.compactDoubleHook && event.doubleHook) { + edited = "§e§lDOUBLE HOOK! $edited" + } + + if (original == edited) return + event.chatEvent.chatComponent = ChatComponentText(edited) } } From acb767a5383e3275f490e9b45bc43918bcd99040 Mon Sep 17 00:00:00 2001 From: Appability Date: Fri, 22 Dec 2023 18:34:37 -0800 Subject: [PATCH 2/2] fix modifying trophy fish messages + chatlineid support in lorenzchatevent --- .../at/hannibal2/skyhanni/data/ChatManager.kt | 9 ++++ .../skyhanni/events/LorenzChatEvent.kt | 5 +- .../fishing/SeaCreatureMessageShortener.kt | 1 - .../fishing/trophy/TrophyFishMessages.kt | 50 ++++++++++--------- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt index c426f9666f17..34e4354dda34 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.features.chat.ChatFilterGui import at.hannibal2.skyhanni.utils.IdentityCharacteristics import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.chat import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible import net.minecraft.client.Minecraft import net.minecraft.client.gui.ChatLine @@ -121,6 +122,14 @@ object ChatManager { } else { messageHistory[key] = MessageFilteringResult(original, ActionKind.ALLOWED, null, null) } + + // TODO: Handle this with ChatManager.retractMessage or some other way for logging and /shchathistory purposes? + if (chatEvent.chatLineId != 0) { + event.isCanceled = true + Minecraft.getMinecraft().ingameGUI.chatGUI.printChatMessageWithOptionalDeletion( + event.message, chatEvent.chatLineId + ) + } } private fun isSoopyMessage(message: IChatComponent): Boolean { diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzChatEvent.kt index 6b50e20927cd..acce544db3ed 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/LorenzChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzChatEvent.kt @@ -5,5 +5,6 @@ import net.minecraft.util.IChatComponent class LorenzChatEvent( var message: String, var chatComponent: IChatComponent, - var blockedReason: String = "" -) : LorenzEvent() \ No newline at end of file + var blockedReason: String = "", + var chatLineId: Int = 0 +) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureMessageShortener.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureMessageShortener.kt index acaa8bdff82b..1b1689e1f35a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureMessageShortener.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureMessageShortener.kt @@ -4,7 +4,6 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.SeaCreatureFishEvent import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraft.util.ChatComponentText -import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class SeaCreatureMessageShortener { diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt index ed394e20a1e1..a01833672b4a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt @@ -14,7 +14,6 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.ordinal import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraft.client.Minecraft import net.minecraft.util.ChatComponentText import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -42,41 +41,46 @@ class TrophyFishMessages { val trophyFishes = fishes ?: return val trophyFishCounts = trophyFishes.getOrPut(internalName) { mutableMapOf() } val amount = trophyFishCounts.addOrPut(rarity, 1) - event.blockedReason = "trophy_fish" - if (config.enabled && config.design == DesignFormat.STYLE_1 && amount == 1) { - LorenzUtils.chat("§6§lTROPHY FISH! §c§lFIRST §r$displayRarity $displayName", prefix = false) + if (shouldBlockTrophyFish(rarity, amount)) { + event.blockedReason = "low_trophy_fish" return } - if (config.bronzeHider && rarity == TrophyRarity.BRONZE && amount != 1) return - if (config.silverHider && rarity == TrophyRarity.SILVER && amount != 1) return - val totalText = if (config.totalAmount) { + val original = event.chatComponent + var edited = original + + if (config.enabled) { + edited = ChatComponentText("§6§lTROPHY FISH! " + when (config.design) { + DesignFormat.STYLE_1 -> if (amount == 1) "§c§lFIRST §r$displayRarity $displayName" + else "§7$amount. §r$displayRarity $displayName" + DesignFormat.STYLE_2 -> "§bYou caught a $displayName $displayRarity§b. §7(${amount.addSeparators()})" + else -> "§bYou caught your ${amount.addSeparators()}${amount.ordinal()} $displayRarity $displayName§b." + }) + } + + if (config.totalAmount) { val total = trophyFishCounts.sumAllValues() - " §7(${total.addSeparators()}. total)" - } else "" - - val component = ChatComponentText( - if (config.enabled) { - "§6§lTROPHY FISH! " + when (config.design) { - DesignFormat.STYLE_1 -> "§7$amount. §r$displayRarity $displayName$totalText" - DesignFormat.STYLE_2 -> "§bYou caught a $displayName $displayRarity§b. §7(${amount.addSeparators()})$totalText" - else -> "§bYou caught your ${amount.addSeparators()}${amount.ordinal()} $displayRarity $displayName§b.$totalText" - } - } else event.message - ) + edited.appendSibling(ChatComponentText(" §7(${total.addSeparators()}. total)")) + } if (config.tooltip) { TrophyFishManager.getInfo(internalName)?.let { - component.chatStyle = it.getTooltip(trophyFishCounts) + edited.chatStyle = it.getTooltip(trophyFishCounts) } } - Minecraft.getMinecraft().ingameGUI.chatGUI.printChatMessageWithOptionalDeletion( - component, if (config.duplicateHider) (internalName + rarity).hashCode() else 0 - ) + event.chatComponent = edited + + if (config.duplicateHider) { + event.chatLineId = (internalName + rarity).hashCode() + } } + private fun shouldBlockTrophyFish(rarity: TrophyRarity, amount: Int) = + config.bronzeHider && rarity == TrophyRarity.BRONZE && amount != 1 + || config.silverHider && rarity == TrophyRarity.SILVER && amount != 1 + @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.move(2, "fishing.trophyCounter", "fishing.trophyFishing.chatMessages.enabled")