diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index ae9c24092..420f3decb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.cachedData import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import com.google.gson.GsonBuilder import com.google.gson.JsonObject @@ -25,6 +25,20 @@ import kotlin.time.Duration.Companion.seconds object ItemUtils { + // TODO USE SH-REPO + private val patternInFront = "(?: *§8(\\+§\\w)?(?<amount>[\\d.km,]+)(x )?)?(?<name>.*)".toPattern() + private val patternBehind = "(?<name>(?:['\\w-]+ ?)+)(?:§8x(?<amount>[\\d,]+))?".toPattern() + private val petLevelPattern = "\\[Lvl (.*)] (.*)".toPattern() + + 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") @@ -51,14 +65,7 @@ object ItemUtils { fun isRecombobulated(stack: ItemStack) = stack.isRecombobulated() - fun isPet(name: String): Boolean = name.matchRegex("\\[Lvl (.*)] (.*)") && !listOf( - "Archer", - "Berserk", - "Mage", - "Tank", - "Healer", - "➡", - ).any { name.contains(it) } + fun isPet(name: String): Boolean = petLevelPattern.matches(name) && !ignoredPetStrings.any { name.contains(it) } fun maxPetLevel(name: String) = if (name.contains("Golden Dragon")) 200 else 100 @@ -253,10 +260,6 @@ object ItemUtils { fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName()?.equals("SKYBLOCK_MENU") ?: false - // TODO USE SH-REPO - private val patternInFront = "(?: *§8(\\+§[\\w])?(?<amount>[\\d.km,]+)(x )?)?(?<name>.*)".toPattern() - private val patternBehind = "(?<name>(?:['\\w-]+ ?)+)(?:§8x(?<amount>[\\d,]+))?".toPattern() - private val itemAmountCache = mutableMapOf<String, Pair<String, Int>>() fun readItemAmount(originalInput: String): Pair<String, Int>? { |