aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-11 12:43:44 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-11 12:43:44 +0200
commitc3caf0b538747d46d02f38a2d2182c821ef1b0f0 (patch)
tree0937fa184e3cbd7f03f41a9b037446db61673e6e /src/main/java/at/hannibal2/skyhanni/utils
parenteaa9df9d3242d3df86000d302f38bc73fa941db4 (diff)
downloadskyhanni-c3caf0b538747d46d02f38a2d2182c821ef1b0f0.tar.gz
skyhanni-c3caf0b538747d46d02f38a2d2182c821ef1b0f0.tar.bz2
skyhanni-c3caf0b538747d46d02f38a2d2182c821ef1b0f0.zip
Added support for lower case names and common typos in /shtrackcollection
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index ac9b2da2b..69687535b 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.utils.ItemBlink.checkBlinkItem
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import io.github.moulberry.notenoughupdates.NEUManager
import io.github.moulberry.notenoughupdates.NEUOverlay
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
@@ -26,14 +27,42 @@ object NEUItems {
private val multiplierCache = mutableMapOf<String, Pair<String, Int>>()
private val recipesCache = mutableMapOf<String, Set<NeuRecipe>>()
private val enchantmentNamePattern = Pattern.compile("^(?<format>(?:§.)+)(?<name>[^§]+) (?<level>[IVXL]+)$")
+ private var allItemsCache = mapOf<String, String>() // item name -> internal name
fun getInternalName(itemName: String): String {
return getInternalNameOrNull(itemName) ?: throw Error("getInternalName is null for '$itemName'")
}
+ fun getInternalNameOrNullIgnoreCase(itemName: String): String? {
+ val lowercase = itemName.removeColor().lowercase()
+ if (itemNameCache.containsKey(lowercase)) {
+ return itemNameCache[lowercase]!!
+ }
+
+ if (allItemsCache.isEmpty()) {
+ allItemsCache = readAllNeuItems()
+ }
+ allItemsCache[lowercase]?.let {
+ itemNameCache[lowercase] = it
+ return it
+ }
+
+ return null
+ }
+
+ private fun readAllNeuItems(): Map<String, String> {
+ val map = mutableMapOf<String, String>()
+ for (internalName in manager.itemInformation.keys) {
+ val name = manager.createItem(internalName).displayName.removeColor().lowercase()
+ map[name] = internalName
+ }
+ return map
+ }
+
fun getInternalNameOrNull(itemName: String): String? {
- if (itemNameCache.containsKey(itemName)) {
- return itemNameCache[itemName]!!
+ val lowercase = itemName.lowercase()
+ if (itemNameCache.containsKey(lowercase)) {
+ return itemNameCache[lowercase]!!
}
resolveEnchantmentByName(itemName)?.let {
@@ -48,7 +77,7 @@ object NEUItems {
internalName = "HAY_BLOCK"
}
- itemNameCache[itemName] = internalName
+ itemNameCache[lowercase] = internalName
return internalName
}