diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
3 files changed, 39 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt index 37849d79a..996d19a93 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt @@ -1,7 +1,9 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal +import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.allLettersFirstUppercase import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -27,6 +29,9 @@ object ItemNameResolver { resolveEnchantmentByName(itemName)?.let { return itemNameCache.getOrPut(lowercase) { fixEnchantmentName(it) } } + resolveEnchantmentByCleanName(itemName)?.let { + return itemNameCache.getOrPut(lowercase) { it } + } if (itemName.endsWith("gemstone", ignoreCase = true)) { val split = lowercase.split(" ") if (split.size == 3) { @@ -68,6 +73,28 @@ object ItemNameResolver { return internalName } + private fun resolveEnchantmentByCleanName(itemName: String): NEUInternalName? { + UtilsPatterns.cleanEnchantedNamePattern.matchMatcher(itemName) { + val name = group("name") + val level = group("level").romanToDecimalIfNecessary() + val rawInternalName = "$name;$level".uppercase() + + var internalName = fixEnchantmentName(rawInternalName) + internalName.getItemStackOrNull()?.let { + return internalName + } + + internalName = fixEnchantmentName("ULTIMATE_$rawInternalName") + internalName.getItemStackOrNull()?.let { + return internalName + } + + return null + } + return null + } + + // does not work without color codes, or with roman numbers // Taken and edited from NEU private fun resolveEnchantmentByName(enchantmentName: String) = UtilsPatterns.enchantmentNamePattern.matchMatcher(enchantmentName) { @@ -87,7 +114,7 @@ object ItemNameResolver { // Workaround for duplex private val duplexPattern = "ULTIMATE_DUPLEX;(?<tier>.*)".toPattern() - private fun fixEnchantmentName(originalName: String): NEUInternalName { + fun fixEnchantmentName(originalName: String): NEUInternalName { duplexPattern.matchMatcher(originalName) { val tier = group("tier") return "ULTIMATE_REITERATE;$tier".asInternalName() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 168a12d95..cc1a4362b 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -126,7 +126,7 @@ object ItemUtils { return NEUInternalName.WISP_POTION } val internalName = NEUItems.getInternalName(this)?.replace("ULTIMATE_ULTIMATE_", "ULTIMATE_") - return internalName?.asInternalName() + return internalName?.let { ItemNameResolver.fixEnchantmentName(it) } } fun ItemStack.isVanilla() = NEUItems.isVanillaItem(this) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt b/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt index 8bb09e6fc..9ce7a32c5 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt @@ -49,6 +49,16 @@ object UtilsPatterns { "^(?<format>(?:§.)*)(?<name>[^§]+) (?<level>[IVXL]+)(?: Book)?$" ) + /** + * REGEX-TEST: duplex i + * REGEX-TEST: ultimate wise v + * REGEX-TEST: chimera 2 + */ + val cleanEnchantedNamePattern by patternGroup.pattern( + "item.enchantment.clean.name", + "(?i)(?<name>.*) (?<level>[IVXL]+|[0-9]+)" + ) + val potionPattern by patternGroup.pattern( "item.name.potion", ".*Potion" |