From 9dbc2ba9eb3a14a539523c90efea67cb09b944da Mon Sep 17 00:00:00 2001 From: jani270 <69345714+jani270@users.noreply.github.com> Date: Wed, 1 Nov 2023 10:43:31 +0100 Subject: Feature: Makes potion effect messages clickable (#657) Makes the Compact Potion message open the Potion effects menu on click. #657 --- .../skyhanni/config/features/ChatConfig.java | 6 ++++ .../features/chat/CompactSplashPotionMessage.kt | 40 ++++++++++++++++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java index 309ce04a7..e2e67573f 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java @@ -164,6 +164,12 @@ public class ChatConfig { @FeatureToggle public boolean compactPotionMessage = true; + @Expose + @ConfigOption(name = "Clickable Potion Messages", desc = "Makes the Compact Potion message open the Potion effects menu on click.") + @ConfigEditorBoolean + @FeatureToggle + public boolean compactPotionClickableMessage = true; + @Expose @ConfigOption(name = "Compact Bestiary Message", desc = "Shorten the Bestiary level up message, showing additional information when hovering.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/CompactSplashPotionMessage.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/CompactSplashPotionMessage.kt index dfc0db3f9..d9732079f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/CompactSplashPotionMessage.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/CompactSplashPotionMessage.kt @@ -5,28 +5,54 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraft.util.ChatComponentText import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class CompactSplashPotionMessage { + private val config get() = SkyHanniMod.feature.chat + private val potionEffectPattern = "§a§lBUFF! §fYou have gained §r(?.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern() - private val potionEffectOthersPattern = + private val potionSplashEffectOthersPattern = "§a§lBUFF! §fYou were splashed by (?.*) §fwith §r(?.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern() + private val potionSplashEffectPattern = + "§a§lBUFF! §fYou splashed yourself with §r(?.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern() @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { - if (!LorenzUtils.inSkyBlock || !SkyHanniMod.feature.chat.compactPotionMessage) return + if (!LorenzUtils.inSkyBlock || !config.compactPotionMessage) return potionEffectPattern.matchMatcher(event.message) { val name = group("name") - event.chatComponent = ChatComponentText("§a§lPotion Effect! §r$name") + sendMessage("§a§lPotion Effect! §r$name") + event.blockedReason = "blocked" } - potionEffectOthersPattern.matchMatcher(event.message) { + potionSplashEffectOthersPattern.matchMatcher(event.message) { val playerName = group("playerName").removeColor() val effectName = group("effectName") - event.chatComponent = ChatComponentText("§a§lPotion Effect! §r$effectName by §b$playerName") + sendMessage( + "§a§lPotion Effect! §r$effectName by §b$playerName", + ) + event.blockedReason = "blocked" + } + + potionSplashEffectPattern.matchMatcher(event.message) { + val name = group("name") + sendMessage("§a§lPotion Effect! §r$name") + event.blockedReason = "blocked" + } + } + + private fun sendMessage(message: String) { + if (config.compactPotionClickableMessage) { + LorenzUtils.hoverableChat( + message, + listOf("§eClick to view your potion effects."), + "/effects" + ) + } else { + LorenzUtils.chat(message) + } } -} \ No newline at end of file +} -- cgit