aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorWalker Selby <git@walkerselby.com>2023-12-03 19:18:06 -0800
committerGitHub <noreply@github.com>2023-12-04 04:18:06 +0100
commit1cf1f68672d07767ed93150dd32094234eddd70c (patch)
tree6a57fdedca12fc61f688d4f1aa96e120866dc6ad /src/main/java/at/hannibal2/skyhanni/utils
parent66fc6034b563b30854de121385d67140f605004e (diff)
downloadskyhanni-1cf1f68672d07767ed93150dd32094234eddd70c.tar.gz
skyhanni-1cf1f68672d07767ed93150dd32094234eddd70c.tar.bz2
skyhanni-1cf1f68672d07767ed93150dd32094234eddd70c.zip
Internal Change: Remove String.matchRegex() function Usages (#641)
Code cleanup and removed .matchRegex() #641
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt29
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt4
2 files changed, 16 insertions, 17 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>? {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index ccfe97b42..f8ab9d092 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -7,7 +7,6 @@ import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiUtilRenderComponents
import net.minecraft.util.ChatComponentText
import net.minecraft.util.IChatComponent
-import org.intellij.lang.annotations.Language
import java.util.Base64
import java.util.NavigableMap
import java.util.UUID
@@ -77,9 +76,6 @@ object StringUtils {
return toString().replace("-", "")
}
- @Deprecated("Do not create a regex pattern each time.", ReplaceWith("toPattern()"))
- fun String.matchRegex(@Language("RegExp") regex: String): Boolean = regex.toRegex().matches(this)
-
private fun String.removeAtBeginning(text: String): String =
if (this.startsWith(text)) substring(text.length) else this