diff options
author | Vixid <52578495+VixidDev@users.noreply.github.com> | 2024-08-26 09:08:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-26 10:08:48 +0200 |
commit | 57224a6c4c4dac2eba2892f29ab4f41cee435995 (patch) | |
tree | f335f43c7c3d8d0803638eebdc4cb6478d637d58 | |
parent | ec94de0ed0af86e63f1528b7efa171f1cc2e9af4 (diff) | |
download | skyhanni-57224a6c4c4dac2eba2892f29ab4f41cee435995.tar.gz skyhanni-57224a6c4c4dac2eba2892f29ab4f41cee435995.tar.bz2 skyhanni-57224a6c4c4dac2eba2892f29ab4f41cee435995.zip |
Improvement: Enchant Parsing SBA Convert Roman Numerals and NEU Inventories compat (#1717)
Co-authored-by: Cal <cwolfson58@gmail.com>
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt | 32 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/FormattedEnchant.kt | 3 |
2 files changed, 21 insertions, 14 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt index a1aacfb0c..dbd8a3a1b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/EnchantParser.kt @@ -1,12 +1,13 @@ package at.hannibal2.skyhanni.features.misc.items.enchants import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.config.features.inventory.EnchantParsingConfig import at.hannibal2.skyhanni.config.features.inventory.EnchantParsingConfig.CommaFormat import at.hannibal2.skyhanni.events.ChatHoverEvent import at.hannibal2.skyhanni.events.ConfigLoadEvent -import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.events.item.ItemHoverEvent import at.hannibal2.skyhanni.features.chroma.ChromaManager import at.hannibal2.skyhanni.mixins.hooks.GuiChatHook import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @@ -38,7 +39,7 @@ object EnchantParser { val patternGroup = RepoPattern.group("misc.items.enchantparsing") val enchantmentPattern by patternGroup.pattern( - "enchants", "(?<enchant>[A-Za-z][A-Za-z '-]+) (?<levelNumeral>[IVXLCDM]+)(?<stacking>, |\$| \\d{1,3}(,\\d{3})*)" + "enchants", "(§9§d§l|§d§l§d§l|§9)(?<enchant>[A-Za-z][A-Za-z '-]+) (?<levelNumeral>[IVXLCDM]+|[0-9]+)(?<stacking>§9, |\$| §8\\d{1,3}(,\\d{3})*)" ) private val grayEnchantPattern by patternGroup.pattern( "grayenchants", "^(Respiration|Aqua Affinity|Depth Strider|Efficiency).*" @@ -91,10 +92,10 @@ object EnchantParser { } } - @SubscribeEvent - fun onTooltipEvent(event: LorenzToolTipEvent) { + @HandleEvent(onlyOnSkyblock = true) + fun onTooltipEvent(event: ItemHoverEvent) { // If enchants doesn't have any enchant data then we have no data to parse enchants correctly - if (!isEnabled() || !this.enchants.hasEnchantData()) return + if (!this.enchants.hasEnchantData()) return currentItem = event.itemStack @@ -220,7 +221,7 @@ object EnchantParser { val strippedLine = loreList[i].removeColor() if (startEnchant == -1) { - if (this.enchants.containsEnchantment(enchants, strippedLine)) startEnchant = i + if (this.enchants.containsEnchantment(enchants, loreList[i])) startEnchant = i } else if (strippedLine.trim().isEmpty() && endEnchant == -1) endEnchant = i - 1 } @@ -232,22 +233,27 @@ object EnchantParser { var lastEnchant: FormattedEnchant? = null for (i in startEnchant..endEnchant) { - val unformattedLine = loreList[i].removeColor() - val matcher = enchantmentPattern.matcher(unformattedLine) + val matcher = enchantmentPattern.matcher(loreList[i]) var containsEnchant = false var enchantsOnThisLine = 0 + var isRoman = true while (matcher.find()) { // Pull enchant, enchant level and stacking amount if applicable val enchant = this.enchants.getFromLore(matcher.group("enchant")) - val level = matcher.group("levelNumeral").romanToDecimal() - val stacking = if (matcher.group("stacking").trimStart().matches("[\\d,]+\$".toRegex())) { + val level = try { + // If one enchant is not a roman numeral we assume all are not roman numerals (idk a situation where this wouldn't be the case) + matcher.group("levelNumeral").toInt().also { isRoman = false } + } catch (e: NumberFormatException) { + matcher.group("levelNumeral").romanToDecimal() + } + val stacking = if (matcher.group("stacking").trimStart().removeColor().matches("[\\d,]+\$".toRegex())) { shouldBeSingleColumn = true matcher.group("stacking") } else "empty" // Last found enchant - lastEnchant = FormattedEnchant(enchant, level, stacking) + lastEnchant = FormattedEnchant(enchant, level, stacking, isRoman) if (!orderedEnchants.add(lastEnchant)) { for (e: FormattedEnchant in orderedEnchants) { @@ -275,10 +281,10 @@ object EnchantParser { // Normal is leaving the formatting as Hypixel provides it if (config.format.get() == EnchantParsingConfig.EnchantFormat.NORMAL) { normalFormatting(insertEnchants) - // Compressed is always forcing 3 enchants per line, except when there is stacking enchant progress visible + // Compressed is always forcing 3 enchants per line, except when there is stacking enchant progress visible } else if (config.format.get() == EnchantParsingConfig.EnchantFormat.COMPRESSED && !shouldBeSingleColumn) { compressedFormatting(insertEnchants) - // Stacked is always forcing 1 enchant per line + // Stacked is always forcing 1 enchant per line } else { stackedFormatting(insertEnchants) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/FormattedEnchant.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/FormattedEnchant.kt index 504415296..73cf57e7a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/FormattedEnchant.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/FormattedEnchant.kt @@ -6,6 +6,7 @@ class FormattedEnchant( private val enchant: Enchant, private val level: Int, stacking: String, + private val isRoman: Boolean ) : Comparable<FormattedEnchant> { private val stacking: String = stacking get() = "§8$field" @@ -19,7 +20,7 @@ class FormattedEnchant( fun getFormattedString(): String { val builder = StringBuilder() - builder.append(enchant.getFormattedName(level)).append(" ").append(level.toRoman()) + builder.append(enchant.getFormattedName(level)).append(" ").append(if (isRoman) level.toRoman() else level) return if (!stacking.contains("empty")) builder.append(stacking).toString() else builder.toString() } |