diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-17 12:28:53 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-17 12:28:53 +0100 |
commit | 00b8eb5ab91b2870f8263e1ac8e66cb973916b1c (patch) | |
tree | 78953b61dd0237b2c2740a66839b2b51dffb99b2 /src/main/java/at/hannibal2/skyhanni/data | |
parent | aee1bd5207a3193d05068fc046ef01e06fc1be67 (diff) | |
download | skyhanni-00b8eb5ab91b2870f8263e1ac8e66cb973916b1c.tar.gz skyhanni-00b8eb5ab91b2870f8263e1ac8e66cb973916b1c.tar.bz2 skyhanni-00b8eb5ab91b2870f8263e1ac8e66cb973916b1c.zip |
Random regex code cleanup
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
3 files changed, 10 insertions, 9 deletions
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 +} |