aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikecraft1224 <85994411+Mikecraft1224@users.noreply.github.com>2024-05-18 11:48:33 +0200
committerGitHub <noreply@github.com>2024-05-18 11:48:33 +0200
commitf8a612dd9f6f8fac1887c5fcaa765291c036693b (patch)
tree9f2e8c17895d66a814f9eab090dd5995aa78dde2
parentf378737cd5536acce4b956b86a27878d3c7df9ef (diff)
downloadskyhanni-f8a612dd9f6f8fac1887c5fcaa765291c036693b.tar.gz
skyhanni-f8a612dd9f6f8fac1887c5fcaa765291c036693b.tar.bz2
skyhanni-f8a612dd9f6f8fac1887c5fcaa765291c036693b.zip
Fixed ReplaceRomanNumerals replacing the word "I" in dialogue (#1755)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/ReplaceRomanNumerals.kt20
1 files changed, 16 insertions, 4 deletions
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(",", "")