aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-09-12 08:57:22 +0200
committerGitHub <noreply@github.com>2024-09-12 08:57:22 +0200
commit996b70464766ca017de65b85b0574b0ed6eccab4 (patch)
tree212613973e517d1017ff10c834c6b299641e0be7
parente350ade0d86955ce1a865f4286cd208d54693777 (diff)
downloadskyhanni-996b70464766ca017de65b85b0574b0ed6eccab4.tar.gz
skyhanni-996b70464766ca017de65b85b0574b0ed6eccab4.tar.bz2
skyhanni-996b70464766ca017de65b85b0574b0ed6eccab4.zip
Fix: Duplex (#2501)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemNameResolver.kt29
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt10
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"