From f8a612dd9f6f8fac1887c5fcaa765291c036693b Mon Sep 17 00:00:00 2001 From: Mikecraft1224 <85994411+Mikecraft1224@users.noreply.github.com> Date: Sat, 18 May 2024 11:48:33 +0200 Subject: Fixed ReplaceRomanNumerals replacing the word "I" in dialogue (#1755) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../skyhanni/features/misc/ReplaceRomanNumerals.kt | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt index 3a93588b6..c770a1fab 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt @@ -4,16 +4,16 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.hypixel.chat.event.SystemMessageEvent import at.hannibal2.skyhanni.events.ChatHoverEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.features.inventory.patternGroup import at.hannibal2.skyhanni.mixins.hooks.GuiChatHook import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import at.hannibal2.skyhanni.utils.StringUtils.applyIfPossible import at.hannibal2.skyhanni.utils.StringUtils.isRoman +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraft.event.ClickEvent import net.minecraft.event.HoverEvent import net.minecraft.util.ChatComponentText -import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -21,6 +21,16 @@ class ReplaceRomanNumerals { // Using toRegex here since toPattern doesn't seem to provide the necessary functionality private val splitRegex = "((§\\w)|(\\s+)|(\\W))+|(\\w*)".toRegex() + // + /** + * REGEX-TEST: §eSelect an option: §r§a[§aOk, then what?§a] + */ + private val isSelectOptionPattern by patternGroup.pattern( + "string.isselectoption", + "§eSelect an option: .*" + ) + + // TODO: Remove after pr 1717 is ready and switch to ItemHoverEvent @SubscribeEvent(priority = EventPriority.LOWEST) fun onTooltip(event: LorenzToolTipEvent) { if (!isEnabled()) return @@ -44,12 +54,14 @@ class ReplaceRomanNumerals { @SubscribeEvent fun onSystemMessage(event: SystemMessageEvent) { - if (!isEnabled()) return + if (!isEnabled() || event.message.isSelectOption()) return event.applyIfPossible { it.transformLine() } } + private fun String.isSelectOption(): Boolean = isSelectOptionPattern.matches(this) + private fun String.transformLine() = splitRegex.findAll(this).map { it.value }.joinToString("") { - it.takeIf { it.isValidRomanNumeral() }?.coloredRomanToDecimal() ?: it + it.takeIf { it.isValidRomanNumeral() && it.removeFormatting().romanToDecimal() != 2000 }?.coloredRomanToDecimal() ?: it } private fun String.removeFormatting() = removeColor().replace(",", "") -- cgit