aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-17 12:28:53 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-17 12:28:53 +0100
commit00b8eb5ab91b2870f8263e1ac8e66cb973916b1c (patch)
tree78953b61dd0237b2c2740a66839b2b51dffb99b2
parentaee1bd5207a3193d05068fc046ef01e06fc1be67 (diff)
downloadskyhanni-00b8eb5ab91b2870f8263e1ac8e66cb973916b1c.tar.gz
skyhanni-00b8eb5ab91b2870f8263e1ac8e66cb973916b1c.tar.bz2
skyhanni-00b8eb5ab91b2870f8263e1ac8e66cb973916b1c.zip
Random regex code cleanup
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/model/ComposterUpgrade.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt7
5 files changed, 16 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
index 29ce97471..cd7fa0c59 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
@@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -83,7 +84,7 @@ class CollectionAPI {
val collectionValue = mutableMapOf<NEUInternalName, Long>()
private val collectionTier0Pattern = "§7Progress to .* I: .*".toPattern()
- fun isCollectionTier0(lore: List<String>) = lore.map { collectionTier0Pattern.matcher(it) }.any { it.matches() }
+ fun isCollectionTier0(lore: List<String>) = lore.any { collectionTier0Pattern.matches(it) }
fun getCollectionCounter(internalName: NEUInternalName): Long? = collectionValue[internalName]
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt
index 14651f900..6b6d343aa 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt
@@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.features.garden.composter.ComposterAPI
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class GardenComposterUpgradesData {
@@ -16,15 +17,12 @@ class GardenComposterUpgradesData {
if (event.inventoryName != "Composter Upgrades") return
for (item in event.inventoryItems.values) {
val itemName = item.name ?: continue
- val matcher = ComposterUpgrade.regex.matcher(itemName)
- if (!matcher.matches()) continue
-
- if (matcher.groupCount() != 0) {
- val name = matcher.group("name")
- val level = matcher.group("level")?.romanToDecimalIfNeeded() ?: 0
+ ComposterUpgrade.regex.matchMatcher(itemName) {
+ val name = group("name")
+ val level = group("level")?.romanToDecimalIfNeeded() ?: 0
val composterUpgrade = ComposterUpgrade.getByName(name)!!
ComposterAPI.composterUpgrades?.put(composterUpgrade, level)
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
index 59d250b0a..8417bc786 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
@@ -21,6 +21,7 @@ import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import com.google.gson.annotations.Expose
import net.minecraft.item.ItemStack
@@ -32,6 +33,7 @@ object SackAPI {
private var lastOpenedInventory = ""
var inSackInventory = false
+
// TODO USE SH-REPO
private val sackPattern = "^(.* Sack|Enchanted .* Sack)$".toPattern()
private val numPattern =
@@ -66,7 +68,7 @@ object SackAPI {
val inventoryName = event.inventoryName
val isNewInventory = inventoryName != lastOpenedInventory
lastOpenedInventory = inventoryName
- val match = sackPattern.matcher(inventoryName).matches()
+ val match = sackPattern.matches(inventoryName)
if (!match) return
val stacks = event.inventoryItems
isRuneSack = inventoryName == "Runes Sack"
diff --git a/src/main/java/at/hannibal2/skyhanni/data/model/ComposterUpgrade.kt b/src/main/java/at/hannibal2/skyhanni/data/model/ComposterUpgrade.kt
index 4712689dc..627bfdef7 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/model/ComposterUpgrade.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/model/ComposterUpgrade.kt
@@ -10,9 +10,10 @@ enum class ComposterUpgrade(val displayName: String, val slotNumber: Int) {
companion object {
private fun regexValues() = entries.joinToString("|") { it.displayName }
+
// TODO USE SH-REPO
val regex = "§a(?<name>${regexValues()})(?: (?<level>.*))?".toPattern()
fun getByName(name: String) = entries.firstOrNull { it.displayName == name }
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt
index 966f8ad06..81426c90f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt
@@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.toLorenzVec
@@ -25,8 +26,8 @@ class SpawnTimers {
private val arachneAltarLocation = LorenzVec(-283f, 51f, -179f)
private var arachneSpawnTime = SimpleTimeMark.farPast()
- private val arachneFragmentMessage = "^☄ [a-z0-9_]{2,22} placed an arachne's calling! something is awakening! \\(4/4\\)\$".toRegex()
- private val arachneCrystalMessage = "^☄ [a-z0-9_]{2,22} placed an arachne crystal! something is awakening!$".toRegex()
+ private val arachneFragmentMessage = "^☄ [a-z0-9_]{2,22} placed an arachne's calling! something is awakening! \\(4/4\\)\$".toPattern()
+ private val arachneCrystalMessage = "^☄ [a-z0-9_]{2,22} placed an arachne crystal! something is awakening!$".toPattern()
private var saveNextTickParticles = false
private var particleCounter = 0
private var tickTime: Long = 0
@@ -95,4 +96,4 @@ class SpawnTimers {
}
fun isEnabled() = IslandType.SPIDER_DEN.isInIsland() && LorenzUtils.skyBlockArea == "Arachne's Sanctuary" && config.showArachneSpawnTimer
-} \ No newline at end of file
+}