aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-02-22 21:54:12 +0100
committerGitHub <noreply@github.com>2024-02-22 21:54:12 +0100
commit7bde14535264d20e37c5c085f8a03db3275044b5 (patch)
tree7b5a2852057fd89dd1a1622f2f25c1808938677c /src/main/java
parent3994a15d86eee42023e3715a671c85de243ea226 (diff)
downloadskyhanni-7bde14535264d20e37c5c085f8a03db3275044b5.tar.gz
skyhanni-7bde14535264d20e37c5c085f8a03db3275044b5.tar.bz2
skyhanni-7bde14535264d20e37c5c085f8a03db3275044b5.zip
Removed duplicate pet level detection logic. #1027
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt17
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt4
5 files changed, 20 insertions, 28 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt
index d5efd3735..2a0f97ae2 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt
@@ -12,13 +12,22 @@ object PetAPI {
)
private val petItemName by patternGroup.pattern(
"item.name",
- "§.\\[Lvl (?<level>\\d)] (?<name>.*)"
+ "(?:§.)*\\[Lvl (?<level>\\d+)] (?<name>.*)"
)
private val neuRepoPetItemName by patternGroup.pattern(
"item.name.neu.format",
"(§f§f)?§7\\[Lvl 1➡(100|200)] (?<name>.*)"
)
+ private val ignoredPetStrings = listOf(
+ "Archer",
+ "Berserk",
+ "Mage",
+ "Tank",
+ "Healer",
+ "➡",
+ )
+
fun isPetMenu(inventoryTitle: String): Boolean = petMenuPattern.matches(inventoryTitle)
// Contains color code + name and for older SkyHanni users maybe also the pet level
@@ -40,4 +49,10 @@ object PetAPI {
return null
}
+
+ fun getPetLevel(nameWithLevel: String): Int? = petItemName.matchMatcher(nameWithLevel) {
+ group("level").toInt()
+ }
+
+ fun hasPetName(name: String): Boolean = petItemName.matches(name) && !ignoredPetStrings.any { name.contains(it) }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt
index 75a4063a2..bc3f52ef2 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt
@@ -53,10 +53,6 @@ object ItemDisplayOverlayFeatures {
private val config get() = SkyHanniMod.feature.inventory
private val patternGroup = RepoPattern.group("inventory.item.overlay")
- private val petLevelPattern by patternGroup.pattern(
- "pet.level",
- "\\[Lvl (?<level>\\d+)] .*"
- )
private val masterSkullPattern by patternGroup.pattern(
"masterskull",
"(.*)Master Skull - Tier ."
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<NEUInternalName, String>() // 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<ItemStack> {
@@ -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 (?<level>\\d+)] .*"
- )
val readAmountBeforePattern by patternGroup.pattern(
"item.amount.front",
"(?: *§8(\\+§\\w)?(?<amount>[\\d.km,]+)(x )?)?(?<name>.*)"