diff options
author | Walker Selby <git@walkerselby.com> | 2023-12-04 07:09:38 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-04 16:09:38 +0100 |
commit | 5a8d02dcd10015f310bab9d18558d2299c856dd1 (patch) | |
tree | 00ed1b7cc677dc8f38b540ea80424166752c5fc8 /src/main | |
parent | a0b37ef8029ff0aecf890447e62e92bf2c28c304 (diff) | |
download | skyhanni-5a8d02dcd10015f310bab9d18558d2299c856dd1.tar.gz skyhanni-5a8d02dcd10015f310bab9d18558d2299c856dd1.tar.bz2 skyhanni-5a8d02dcd10015f310bab9d18558d2299c856dd1.zip |
Fix: Fix Poison Candy I Compact Potion & Cleanup (#758)
changed CompactSplashPotionMessage, added compact potion message support for splash messages and for Poisoned Candy I. #758
Diffstat (limited to 'src/main')
3 files changed, 47 insertions, 29 deletions
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 c823d83f0..43ea37c16 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/CompactSplashPotionMessage.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/CompactSplashPotionMessage.kt @@ -3,49 +3,56 @@ package at.hannibal2.skyhanni.features.chat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.groupOrNull import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class CompactSplashPotionMessage { private val config get() = SkyHanniMod.feature.chat.compactPotionMessages - private val potionEffectPattern = - "§a§lBUFF! §fYou have gained §r(?<name>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern() - private val potionSplashEffectOthersPattern = - "§a§lBUFF! §fYou were splashed by (?<playerName>.*) §fwith §r(?<effectName>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern() - private val potionSplashEffectPattern = - "§a§lBUFF! §fYou splashed yourself with §r(?<name>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern() + private val potionEffectPatternList = listOf( + "§a§lBUFF! §fYou were splashed by (?<playerName>.*) §fwith §r(?<effectName>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern(), + "§a§lBUFF! §fYou have gained §r(?<effectName>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern(), + "§a§lBUFF! §fYou splashed yourself with §r(?<effectName>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern(), + + // Fix for Hypixel having a different message for Poisoned Candy. + // Did not make the first pattern optional to prevent conflicts with Dungeon Buffs/other things + "§a§lBUFF! §fYou have gained §r(?<effectName>§2Poisoned Candy I)§r§f!§r".toPattern(), + "§a§lBUFF! §fYou splashed yourself with §r(?<effectName>§2Poisoned Candy I)§r§f!§r".toPattern(), + "§a§lBUFF! §fYou were splashed by (?<playerName>.*) §fwith §r(?<effectName>§2Poisoned Candy I)§r§f!§r".toPattern() + ) @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { - if (!LorenzUtils.inSkyBlock || !config.enabled) return - - potionEffectPattern.matchMatcher(event.message) { - val name = group("name") - sendMessage("§a§lPotion Effect! §r$name") - event.blockedReason = "compact_potion_effect" - } - - potionSplashEffectOthersPattern.matchMatcher(event.message) { - val playerName = group("playerName").removeColor() - val effectName = group("effectName") - sendMessage("§a§lPotion Effect! §r$effectName by §b$playerName") - event.blockedReason = "compact_potion_effect" - } - - potionSplashEffectPattern.matchMatcher(event.message) { - val name = group("name") - sendMessage("§a§lPotion Effect! §r$name") - event.blockedReason = "compact_potion_effect" - } + if (!isEnabled()) return + if (!event.message.isPotionMessage()) return + event.blockedReason = "compact_potion_effect" } + private fun sendMessage(message: String) { if (config.clickableChatMessage) { - LorenzUtils.hoverableChat(message, listOf("§eClick to view your potion effects."), "/effects") + LorenzUtils.hoverableChat( + message, + listOf("§eClick to view your potion effects."), + "/effects", + prefix = false + ) } else { - LorenzUtils.chat(message) + LorenzUtils.chat(message, prefix = false) + } + } + + private fun String.isPotionMessage(): Boolean { + return potionEffectPatternList.any { + it.matchMatcher(this) { + val effectName = group("effectName") + // If splashed by a player, append their name. + val byPlayer = groupOrNull("playerName")?.let { player -> " by $player" } ?: "" + sendMessage("§a§lPotion Effect! §r$effectName$byPlayer") + } != null } } + + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt index 80c3b870d..d08dd888a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt @@ -63,6 +63,7 @@ class NonGodPotEffectDisplay { private var patternEffectsCount = "§7You have §e(?<name>\\d+) §7non-god effects\\.".toPattern() private var totalEffectsCount = 0 + // todo : cleanup and add support for poison candy I, and add support for splash / other formats @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { if (event.message == "§aYou cleared all of your active effects!") { @@ -95,6 +96,7 @@ class NonGodPotEffectDisplay { effectDuration[NonGodPotEffect.GOBLIN] = Timer(20.minutes) update() } + if (event.message == "§cThe Goblin King's §r§afoul stench §r§chas dissipated!") { effectDuration.remove(NonGodPotEffect.GOBLIN) update() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 7f5759a70..b468bc33d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -35,6 +35,7 @@ import java.text.SimpleDateFormat import java.util.Collections import java.util.Timer import java.util.TimerTask +import java.util.regex.Matcher import kotlin.properties.ReadWriteProperty import kotlin.reflect.KMutableProperty1 import kotlin.reflect.KProperty @@ -637,4 +638,12 @@ object LorenzUtils { } FMLCommonHandler.instance().handleExit(-1) } + + /** + * Get the group, otherwise, return null + * @param groupName The group name in the pattern + */ + fun Matcher.groupOrNull(groupName: String): String? { + return runCatching { this.group(groupName) }.getOrNull() + } } |