From 7bde14535264d20e37c5c085f8a03db3275044b5 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Thu, 22 Feb 2024 21:54:12 +0100 Subject: Removed duplicate pet level detection logic. #1027 --- src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 15 ++------------- .../hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt | 8 ++------ .../java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt | 4 ---- 3 files changed, 4 insertions(+), 23 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index ab0d695fd..80939e492 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -29,15 +29,6 @@ object ItemUtils { private val itemNameCache = mutableMapOf() // internal name -> item name - private val ignoredPetStrings = listOf( - "Archer", - "Berserk", - "Mage", - "Tank", - "Healer", - "➡", - ) - fun ItemStack.cleanName() = this.displayName.removeColor() fun isSack(stack: ItemStack) = stack.getInternalName().endsWith("_SACK") && stack.cleanName().endsWith(" Sack") @@ -64,8 +55,6 @@ object ItemUtils { fun isRecombobulated(stack: ItemStack) = stack.isRecombobulated() - fun isPet(name: String): Boolean = UtilsPatterns.petLevelPattern.matches(name) && !ignoredPetStrings.any { name.contains(it) } - fun maxPetLevel(name: String) = if (name.contains("Golden Dragon")) 200 else 100 fun getItemsInInventory(withCursorItem: Boolean = false): List { @@ -217,7 +206,7 @@ object ItemUtils { val name = this.name ?: "" val cleanName = this.cleanName() - if (isPet(cleanName)) { + if (PetAPI.hasPetName(cleanName)) { return getPetRarity(this) to ItemCategory.PET } @@ -260,7 +249,7 @@ object ItemUtils { private fun getItemCategory(itemCategory: String, name: String, cleanName: String = name.removeColor()) = if (itemCategory.isEmpty()) when { UtilsPatterns.abiPhonePattern.matches(name) -> ItemCategory.ABIPHONE - isPet(cleanName) -> ItemCategory.PET + PetAPI.hasPetName(cleanName) -> ItemCategory.PET UtilsPatterns.enchantedBookPattern.matches(name) -> ItemCategory.ENCHANTED_BOOK UtilsPatterns.potionPattern.matches(name) -> ItemCategory.POTION UtilsPatterns.sackPattern.matches(name) -> ItemCategory.SACK diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt index e4bc8b074..404a3a258 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt @@ -1,12 +1,12 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.config.ConfigManager +import at.hannibal2.skyhanni.data.PetAPI import at.hannibal2.skyhanni.mixins.hooks.ItemStackCachedData import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import com.google.gson.JsonObject import net.minecraft.item.Item @@ -92,11 +92,7 @@ object SkyBlockItemModifierUtils { @Suppress("CAST_NEVER_SUCCEEDS") inline val ItemStack.cachedData get() = (this as ItemStackCachedData).skyhanni_cachedData - fun ItemStack.getPetLevel(): Int { - return UtilsPatterns.petLevelPattern.matchMatcher(this.displayName) { - group("level").toInt() - } ?: 0 - } + fun ItemStack.getPetLevel(): Int = PetAPI.getPetLevel(displayName)?: 0 fun ItemStack.getMaxPetLevel() = if (this.getInternalName() == "GOLDEN_DRAGON;4".asInternalName()) 200 else 100 diff --git a/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt b/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt index 20a4f3db4..7f19388d4 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt @@ -41,10 +41,6 @@ object UtilsPatterns { "item.name.potion", ".*Potion" ) - val petLevelPattern by patternGroup.pattern( - "item.petlevel", - "(?:§f§f)?(?:§7)?\\[Lvl (?\\d+)] .*" - ) val readAmountBeforePattern by patternGroup.pattern( "item.amount.front", "(?: *§8(\\+§\\w)?(?[\\d.km,]+)(x )?)?(?.*)" -- cgit