aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt17
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt28
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt86
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chat/PlayerDeathMessages.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonData.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt18
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt35
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt49
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt29
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenTeleportPadCompactName.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt59
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt31
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt30
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt20
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/CompactSplashPotionMessage.kt23
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailykuudra/DailyKuudraBossHelper.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/QuestLoader.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/miniboss/DailyMiniBossHelper.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/HideMobNames.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiIngameHook.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt22
39 files changed, 332 insertions, 361 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
index 074120d66..08010207a 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
@@ -9,12 +9,13 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUItems
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class CollectionAPI {
- private val counterPattern = "(?:.*) §e(.*)§6\\/(?:.*)".toPattern()
- private val singleCounterPattern = "§7Total Collected: §e(.*)".toPattern()
+ private val counterPattern = "(?:.*) §e(?<amount>.*)§6\\/(?:.*)".toPattern()
+ private val singleCounterPattern = "§7Total Collected: §e(?<amount>.*)".toPattern()
// private val hypixelApiHasWrongItems = listOf(
// "WOOL",
@@ -60,9 +61,8 @@ class CollectionAPI {
if (inventoryName.endsWith(" Collection")) {
val stack = event.inventoryItems[4] ?: return
for (line in stack.getLore()) {
- val matcher = singleCounterPattern.matcher(line)
- if (matcher.matches()) {
- val counter = matcher.group(1).replace(",", "").toLong()
+ singleCounterPattern.matchMatcher(line) {
+ val counter = group("amount").replace(",", "").toLong()
val name = inventoryName.split(" ").dropLast(1).joinToString(" ")
collectionValue[name] = counter
}
@@ -85,9 +85,8 @@ class CollectionAPI {
}
for (line in lore) {
- val matcher = counterPattern.matcher(line)
- if (matcher.matches()) {
- val counter = matcher.group(1).replace(",", "").toLong()
+ counterPattern.matchMatcher(line) {
+ val counter = group("amount").replace(",", "").toLong()
collectionValue[name] = counter
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
index f4c2802f2..d07172609 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
@@ -5,12 +5,13 @@ import at.hannibal2.skyhanni.events.CropMilestoneUpdateEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class GardenCropMilestones {
- private val cropPattern = "§7Harvest §f(.*) §7on .*".toPattern()
- private val totalPattern = "§7Total: §a(.*)".toPattern()
+ private val cropPattern = "§7Harvest §f(?<name>.*) §7on .*".toPattern()
+ private val totalPattern = "§7Total: §a(?<name>.*)".toPattern()
// Add when api support is there
// @SubscribeEvent
@@ -41,14 +42,12 @@ class GardenCropMilestones {
for ((_, stack) in event.inventoryItems) {
var crop: CropType? = null
for (line in stack.getLore()) {
- var matcher = cropPattern.matcher(line)
- if (matcher.matches()) {
- val name = matcher.group(1)
- crop = CropType.getByNameOrNull(name) ?: continue
+ cropPattern.matchMatcher(line) {
+ val name = group("name")
+ crop = CropType.getByNameOrNull(name)
}
- matcher = totalPattern.matcher(line)
- if (matcher.matches()) {
- val amount = matcher.group(1).replace(",", "").toLong()
+ totalPattern.matchMatcher(line) {
+ val amount = group("name").replace(",", "").toLong()
crop?.setCounter(amount)
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
index c6d540ecb..11435ae96 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
@@ -9,13 +9,13 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class SkillExperience {
-
- private val actionBarPattern = "(?:.*)§3\\+(?:.*) (.*) \\((.*)\\/(.*)\\)(?:.*)".toPattern()
- private val inventoryPattern = "(?:.*) §e(.*)§6\\/(?:.*)".toPattern()
+ private val actionBarPattern = "(?:.*)§3\\+(?:.*) (?<skill>.*) \\((?<overflow>.*)\\/(?<needed>.*)\\)(?:.*)".toPattern()
+ private val inventoryPattern = "(?:.*) §e(?<number>.*)§6\\/(?:.*)".toPattern()
@SubscribeEvent
fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) {
@@ -38,15 +38,14 @@ class SkillExperience {
fun onActionBar(event: LorenzActionBarEvent) {
if (!LorenzUtils.inSkyBlock) return
- val matcher = actionBarPattern.matcher(event.message)
- if (!matcher.matches()) return
-
- val skill = matcher.group(1).lowercase()
- val overflow = matcher.group(2).formatNumber()
- val neededForNextLevel = matcher.group(3).formatNumber()
- val nextLevel = getLevelForExpExactly(neededForNextLevel)
- val baseExp = getExpForLevel(nextLevel - 1)
- skillExp[skill] = baseExp + overflow
+ actionBarPattern.matchMatcher(event.message) {
+ val skill = group("skill").lowercase()
+ val overflow = group("overflow").formatNumber()
+ val neededForNextLevel = group("needed").formatNumber()
+ val nextLevel = getLevelForExpExactly(neededForNextLevel)
+ val baseExp = getExpForLevel(nextLevel - 1)
+ skillExp[skill] = baseExp + overflow
+ }
}
@SubscribeEvent
@@ -70,9 +69,8 @@ class SkillExperience {
val skillName = split[0].lowercase()
val level = split[1].romanToDecimal()
val baseExp = getExpForLevel(level)
- val matcher = inventoryPattern.matcher(line)
- if (matcher.matches()) {
- val rawNumber = matcher.group(1)
+ inventoryPattern.matchMatcher(line) {
+ val rawNumber = group("number")
val overflow = rawNumber.formatNumber()
val experience = baseExp + overflow
skillExp[skillName] = experience
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt
index e3f50ad0b..3fce3b4d3 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt
@@ -6,15 +6,16 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.OSUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Pattern
class BazaarCancelledBuyOrderClipboard {
- private val patternLastAmount = Pattern.compile("§a(.*)§7x")
+ private val patternLastAmount = Pattern.compile("§a(?<amount>.*)§7x")
private val patternCancelledMessage =
- "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(.*) coins §r§7from cancelling Buy Order!".toPattern()
+ "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?<coins>.*) coins §r§7from cancelling Buy Order!".toPattern()
private var latestAmount: String? = null
@@ -29,7 +30,7 @@ class BazaarCancelledBuyOrderClipboard {
for (line in stack.getLore()) {
val matcher = patternLastAmount.matcher(line)
if (matcher.find()) {
- latestAmount = matcher.group(1)
+ latestAmount = matcher.group("amount")
}
}
}
@@ -38,13 +39,9 @@ class BazaarCancelledBuyOrderClipboard {
fun onChat(event: LorenzChatEvent) {
if (!isEnabled()) return
- val message = event.message
-
- val matcher = patternCancelledMessage.matcher(message)
- if (matcher.matches()) {
+ patternCancelledMessage.matchMatcher(event.message) {
event.blockedReason = "bazaar cancelled buy order clipbaord"
- val coins = matcher.group(1)
-
+ val coins = group("coins")
LorenzUtils.chat("§e[SkyHanni] Bazaar buy order cancelled. $latestAmount saved to clipboard. ($coins coins)")
latestAmount?.let { OSUtils.copyToClipboard(it.replace(",", "")) }
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
index 1e00d8c22..fa0dd8187 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
@@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
import net.minecraft.inventory.Slot
@@ -43,13 +44,12 @@ class BazaarOrderHelper {
if (slot.stack == null) continue
val itemName = slot.stack.name ?: continue
- val matcher = bazaarItemNamePattern.matcher(itemName)
- if (!matcher.matches()) continue
+ bazaarItemNamePattern.matchMatcher(itemName) {
+ val buyOrSell = group("type").let { (it == "BUY") to (it == "SELL") }
+ if (buyOrSell.let { !it.first && !it.second }) return
- val buyOrSell = matcher.group("type").let { (it == "BUY") to (it == "SELL") }
- if (buyOrSell.let { !it.first && !it.second }) continue
-
- highlightItem(matcher.group("name"), slot, buyOrSell)
+ highlightItem(group("name"), slot, buyOrSell)
+ }
}
}
@@ -62,14 +62,13 @@ class BazaarOrderHelper {
val itemLore = slot.stack.getLore()
for (line in itemLore) {
- if (filledPattern.matcher(line).matches()) {
+ filledPattern.matchMatcher(line) {
slot highlight LorenzColor.GREEN
return
}
- val matcher = pricePattern.matcher(line)
- if (matcher.matches()) {
- val price = matcher.group("number").replace(",", "").toDouble()
+ pricePattern.matchMatcher(line) {
+ val price = group("number").replace(",", "").toDouble()
if (buyOrSell.first && price < data.sellPrice || buyOrSell.second && price > data.buyPrice) {
slot highlight LorenzColor.GOLD
return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt
index cc4faeaeb..229c3fc69 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt
@@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiChat
@@ -27,7 +28,7 @@ class BingoCardDisplay {
private var tick = 0
private var display = listOf<String>()
private val config get() = SkyHanniMod.feature.bingo
- private val goalCompletePattern = "§6§lBINGO GOAL COMPLETE! §r§e(.*)".toPattern()
+ private val goalCompletePattern = "§6§lBINGO GOAL COMPLETE! §r§e(?<name>.*)".toPattern()
init {
update()
@@ -179,9 +180,8 @@ class BingoCardDisplay {
if (!LorenzUtils.isBingoProfile) return
if (!config.cardDisplay) return
- val matcher = goalCompletePattern.matcher(event.message)
- if (matcher.matches()) {
- val name = matcher.group(1)
+ goalCompletePattern.matchMatcher(event.message) {
+ val name = group("name")
personalGoals.filter { it.displayName == name }
.forEach {
it.done = true
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt
index 28faaf877..472fe1a81 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt
@@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.features.bingo.nextstep.*
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matchRegex
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -22,9 +23,9 @@ class BingoNextStepHelper {
private val itemIslandRequired = mutableMapOf<String, IslandVisitStep>()
private val itemRequired = mutableMapOf<String, NextStep>()
private val islands = mutableMapOf<IslandType, IslandVisitStep>()
- private val collectionPattern = "Reach ([0-9]+(?:,\\d+)*) (.*) Collection\\.".toPattern()
- private val crystalPattern = "Obtain a (\\w+) Crystal in the Crystal Hollows\\.".toPattern()
- private val skillPattern = "Obtain level (.*) in the (.*) Skill.".toPattern()
+ private val collectionPattern = "Reach (?<amount>[0-9]+(?:,\\d+)*) (?<name>.*) Collection\\.".toPattern()
+ private val crystalPattern = "Obtain a (?<name>\\w+) Crystal in the Crystal Hollows\\.".toPattern()
+ private val skillPattern = "Obtain level (?<level>.*) in the (?<skill>.*) Skill.".toPattern()
companion object {
private val finalSteps = mutableListOf<NextStep>()
@@ -219,49 +220,52 @@ class BingoNextStepHelper {
dirty = false
for (goal in personalGoals) {
- val description = goal.description.removeColor()
+ readDescription(goal.description.removeColor())
+ }
- val collectionMatcher = collectionPattern.matcher(description)
- if (collectionMatcher.matches()) {
- val amount = collectionMatcher.group(1).replace(",", "").toInt()
- val name = collectionMatcher.group(2)
+ updateResult()
+ }
- val collectionStep = CollectionStep(name, amount).apply { finalSteps.add(this) }
- createItemIslandRequirement(name, collectionStep)
- continue
- }
- if (description == "Craft an Emerald Ring.") {
- CraftStep("Emerald Ring").apply { finalSteps.add(this) } requires ItemsStep(
- "32x Enchanted Emerald",
- "Emerald",
- 160 * 32,
- mapOf("Emerald" to 1, "Enchanted Emerald" to 160)
- ).apply { this requires IslandType.DWARVEN_MINES.getStep() }
- }
- if (description == "Obtain a Mathematical Hoe Blueprint.") {
- CraftStep("Mathematical Hoe Blueprint").apply { finalSteps.add(this) } requires ItemsStep(
- "32x Jacob's Ticket",
- "Jacob's Ticket",
- 32,
- mapOf("Jacob's Ticket" to 1)
- ).apply { this requires IslandType.GARDEN.getStep() }.addItemRequirements()
- }
- val crystalMatcher = crystalPattern.matcher(description)
- if (crystalMatcher.matches()) {
- val crystal = crystalMatcher.group(1)
- ChatMessageStep("Obtain a $crystal Crystal").apply { finalSteps.add(this) } requires IslandType.CRYSTAL_HOLLOWS.getStep()
- }
- val matcher = skillPattern.matcher(description)
- if (matcher.matches()) {
- val level = matcher.group(1).toInt()
- val skillName = matcher.group(2)
- SkillLevelStep(skillName, level).apply { finalSteps.add(this) }
- }
+ private fun readDescription(description: String) {
+ collectionPattern.matchMatcher(description) {
+ val amount = group("amount").replace(",", "").toInt()
+ val name = group("name")
+
+ val collectionStep = CollectionStep(name, amount).apply { finalSteps.add(this) }
+ createItemIslandRequirement(name, collectionStep)
+ return
+ }
- println("No help for goal: '$description'")
+ if (description == "Craft an Emerald Ring.") {
+ CraftStep("Emerald Ring").apply { finalSteps.add(this) } requires ItemsStep(
+ "32x Enchanted Emerald",
+ "Emerald",
+ 160 * 32,
+ mapOf("Emerald" to 1, "Enchanted Emerald" to 160)
+ ).apply { this requires IslandType.DWARVEN_MINES.getStep() }
}
- updateResult()
+ if (description == "Obtain a Mathematical Hoe Blueprint.") {
+ CraftStep("Mathematical Hoe Blueprint").apply { finalSteps.add(this) } requires ItemsStep(
+ "32x Jacob's Ticket",
+ "Jacob's Ticket",
+ 32,
+ mapOf("Jacob's Ticket" to 1)
+ ).apply { this requires IslandType.GARDEN.getStep() }.addItemRequirements()
+ }
+
+ crystalPattern.matchMatcher(description) {
+ val crystal = group("name")
+ ChatMessageStep("Obtain a $crystal Crystal").apply { finalSteps.add(this) } requires IslandType.CRYSTAL_HOLLOWS.getStep()
+ }
+
+ skillPattern.matchMatcher(description) {
+ val level = group("level").toInt()
+ val skill = group("skill")
+ SkillLevelStep(skill, level).apply { finalSteps.add(this) }
+ }
+
+ println("No help for goal: '$description'")
}
@SubscribeEvent
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt
index 6fb885ff2..62077f08c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt
@@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe
@@ -21,7 +22,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
class MinionCraftHelper {
- private var minionNamePattern = "(.*) Minion (.*)".toPattern()
+ private var minionNamePattern = "(?<name>.*) Minion (?<number>.*)".toPattern()
private var tick = 0
private var display = listOf<String>()
private var hasMinionInInventory = false
@@ -75,11 +76,11 @@ class MinionCraftHelper {
): MutableList<String> {
val newDisplay = mutableListOf<String>()
for ((minionName, minionId) in minions) {
- val matcher = minionNamePattern.matcher(minionName)
- if (!matcher.matches()) continue
- val cleanName = matcher.group(1).removeColor()
- val number = matcher.group(2).romanToDecimalIfNeeded()
- addMinion(cleanName, number, minionId, otherItems, newDisplay)
+ minionNamePattern.matchMatcher(minionName) {
+ val cleanName = group("name").removeColor()
+ val number = group("number").romanToDecimalIfNeeded()
+ addMinion(cleanName, number, minionId, otherItems, newDisplay)
+ }
}
return newDisplay
}
@@ -273,7 +274,7 @@ class MinionCraftHelper {
if (event.inventoryName != "Crafted Minions") return
for ((_, b) in event.inventoryItems) {
- val name = b.name?: continue
+ val name = b.name ?: continue
if (!name.startsWith("§e")) continue
val internalName = NEUItems.getInternalName("$name I")
diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerDeathMessages.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerDeathMessages.kt
index 1de8f09a2..2bfb0c9cf 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerDeathMessages.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerDeathMessages.kt
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager
import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.getLorenzVec
import net.minecraft.client.Minecraft
@@ -18,7 +19,7 @@ class PlayerDeathMessages {
private val lastTimePlayerSeen = mutableMapOf<String, Long>()
//§c ☠ §r§7§r§bZeroHazel§r§7 was killed by §r§8§lAshfang§r§7§r§7.
- private val pattern = "§c ☠ §r§7§r§.(.+)§r§7 (.+)".toPattern()
+ private val deathMessagePattern = "§c ☠ §r§7§r§.(?<name>.+)§r§7 (?<reason>.+)".toPattern()
@SubscribeEvent
fun onTick(event: TickEvent.ClientTickEvent) {
@@ -34,12 +35,11 @@ class PlayerDeathMessages {
if (!LorenzUtils.inSkyBlock) return
val message = event.message
- val matcher = pattern.matcher(message)
- if (matcher.matches()) {
- val name = matcher.group(1)
+ deathMessagePattern.matchMatcher(message) {
+ val name = group("name")
if (SkyHanniMod.feature.markedPlayers.highlightInChat && !LorenzUtils.inDungeons && !LorenzUtils.inKuudraFight) {
if (MarkedPlayerManager.isMarkedPlayer(name)) {
- val reason = matcher.group(2).removeColor()
+ val reason = group("reason").removeColor()
LorenzUtils.chat(" §c☠ §e$name §7$reason")
event.blockedReason = "marked_player_death"
return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonData.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonData.kt
index 00db6d6b8..230e80dd2 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonData.kt
@@ -5,14 +5,14 @@ import at.hannibal2.skyhanni.events.DungeonBossRoomEnterEvent
import at.hannibal2.skyhanni.events.DungeonEnterEvent
import at.hannibal2.skyhanni.events.DungeonStartEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
class DungeonData {
-
- private val pattern = " §7⏣ §cThe Catacombs §7\\((.*)\\)".toPattern()
+ private val floorPattern = " §7⏣ §cThe Catacombs §7\\((?<floor>.*)\\)".toPattern()
companion object {
var dungeonFloor: String? = null
@@ -66,9 +66,8 @@ class DungeonData {
if (event.phase != TickEvent.Phase.START) return
if (dungeonFloor == null) {
for (line in ScoreboardData.sidebarLinesFormatted) {
- val matcher = pattern.matcher(line)
- if (matcher.matches()) {
- val floor = matcher.group(1)
+ floorPattern.matchMatcher(line) {
+ val floor = group("floor")
dungeonFloor = floor
DungeonEnterEvent(floor).postAndCatch()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt
index 91b347145..4f5ca684f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonLevelColor.kt
@@ -4,12 +4,12 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class DungeonLevelColor {
-
- private val pattern = " §.(.*)§f: §e(.*)§b \\(§e(.*)§b\\)".toPattern()
+ private val pattern = " §.(?<playerName>.*)§f: §e(?<className>.*)§b \\(§e(?<level>.*)§b\\)".toPattern()
@SubscribeEvent
fun onItemTooltip(event: ItemTooltipEvent) {
@@ -24,14 +24,14 @@ class DungeonLevelColor {
var index = 0
for (line in stack.getLore()) {
index++
- val matcher = pattern.matcher(line)
- if (!matcher.matches()) continue
- val playerName = matcher.group(1)
- val className = matcher.group(2)
- val level = matcher.group(3).toInt()
- val color = getColor(level)
- event.toolTip[index] = " §b$playerName§f: §e$className $color$level"
+ pattern.matchMatcher(line) {
+ val playerName = group("playerName")
+ val className = group("className")
+ val level = group("level").toInt()
+ val color = getColor(level)
+ event.toolTip[index] = " §b$playerName§f: §e$className $color$level"
+ }
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt
index fb6453add..3539e40af 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt
@@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Pattern
@@ -19,34 +20,28 @@ class GardenCropMilestoneFix {
@SubscribeEvent
fun onChatMessage(event: LorenzChatEvent) {
- val matcher = levelUpPattern.matcher(event.message)
- if (!matcher.matches()) return
+ levelUpPattern.matchMatcher(event.message) {
+ val cropName = group("crop")
+ val crop = CropType.getByNameOrNull(cropName) ?: return
- val cropName = matcher.group("crop")
- val crop = CropType.getByNameOrNull(cropName)
- if (crop == null) {
- LorenzUtils.debug("GardenCropMilestoneFix: crop is null: '$cropName'")
- return
- }
+ val tier = group("tier").romanToDecimalIfNeeded()
- val tier = matcher.group("tier").romanToDecimalIfNeeded()
-
- val crops = GardenCropMilestones.getCropsForTier(tier)
- changedValue(crop, crops, "level up chat message")
+ val crops = GardenCropMilestones.getCropsForTier(tier)
+ changedValue(crop, crops, "level up chat message")
+ }
}
@SubscribeEvent
fun onTabListUpdate(event: TabListUpdateEvent) {
for (line in event.tabList) {
- val matcher = tabListPattern.matcher(line)
- if (!matcher.matches()) continue
-
- val tier = matcher.group("tier").toInt()
- val percentage = matcher.group("percentage").toDouble()
- val cropName = matcher.group("crop")
+ tabListPattern.matchMatcher(line) {
+ val tier = group("tier").toInt()
+ val percentage = group("percentage").toDouble()
+ val cropName = group("crop")
- check(cropName, tier, percentage)
- return
+ check(cropName, tier, percentage)
+ return
+ }
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt
index 6c4abadb8..38b31b57e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt
@@ -10,22 +10,23 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.math.roundToInt
class GardenLevelDisplay {
private val config get() = SkyHanniMod.feature.garden
- private val expToNextLevelPattern = "(?:.*) §e(.*)§6\\/(?:.*)".toPattern()
+ private val expToNextLevelPattern = "(?:.*) §e(?<nextLevelExp>.*)§6\\/(?:.*)".toPattern()
private val overflowPattern = ".*§r §6(?<overflow>.*) XP".toPattern()
- private val namePattern = "Garden Level (.*)".toPattern()
+ private val namePattern = "Garden Level (?<currentLevel>.*)".toPattern()
private var gardenExp
get() = SkyHanniMod.feature.hidden.gardenExp
set(value) {
SkyHanniMod.feature.hidden.gardenExp = value
}
private var display = ""
- private var visitorRewardPattern = " {4}§r§8\\+§r§2(.*) §r§7Garden Experience".toPattern()
+ private var visitorRewardPattern = " {4}§r§8\\+§r§2(?<exp>.*) §r§7Garden Experience".toPattern()
@SubscribeEvent
fun onProfileJoin(event: ProfileJoinEvent) {
@@ -36,10 +37,8 @@ class GardenLevelDisplay {
fun onChatMessage(event: LorenzChatEvent) {
if (!isEnabled()) return
- val matcher = visitorRewardPattern.matcher(event.message)
- if (matcher.matches()) {
- val moreExp = matcher.group(1).toInt()
- gardenExp += moreExp
+ visitorRewardPattern.matchMatcher(event.message) {
+ gardenExp += group("exp").toInt()
update()
}
}
@@ -50,28 +49,24 @@ class GardenLevelDisplay {
if (event.inventoryName != "Desk") return
val item = event.inventoryItems[4]!!
- val name = item.name!!.removeColor()
- val nameMatcher = namePattern.matcher(name)
- if (!nameMatcher.matches()) return
- val currentLevel = nameMatcher.group(1).romanToDecimalIfNeeded()
- var nextLevelExp = 0
- for (line in item.getLore()) {
- var matcher = expToNextLevelPattern.matcher(line)
- if (matcher.matches()) {
- nextLevelExp = matcher.group(1).replace(",", "").toDouble().roundToInt()
- break
- }
- matcher = overflowPattern.matcher(line)
- if (matcher.matches()) {
- val overflow = matcher.group("overflow").replace(",", "").toDouble().roundToInt()
- gardenExp = overflow
- update()
- return
+ namePattern.matchMatcher(item.name!!.removeColor()) {
+ val currentLevel = group("currentLevel").romanToDecimalIfNeeded()
+ var nextLevelExp = 0
+ for (line in item.getLore()) {
+ expToNextLevelPattern.matchMatcher(line) {
+ nextLevelExp = group("nextLevelExp").replace(",", "").toDouble().roundToInt()
+ }
+ overflowPattern.matchMatcher(line) {
+ val overflow = group("overflow").replace(",", "").toDouble().roundToInt()
+ gardenExp = overflow
+ update()
+ return
+ }
}
+ val expForLevel = getExpForLevel(currentLevel).toInt()
+ gardenExp = expForLevel + nextLevelExp
+ update()
}
- val expForLevel = getExpForLevel(currentLevel).toInt()
- gardenExp = expForLevel + nextLevelExp
- update()
}
private fun update() {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
index 7b9e52d14..c7ea644cb 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
@@ -10,10 +10,12 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderSingleLineWithItems
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
import at.hannibal2.skyhanni.utils.SoundUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeUtils
import io.github.moulberry.notenoughupdates.util.SkyBlockTime
import kotlinx.coroutines.launch
+import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import org.lwjgl.opengl.Display
@@ -31,9 +33,9 @@ class GardenNextJacobContest {
private var tick = 0
private var contests = mutableMapOf<Long, FarmingContest>()
private var inCalendar = false
- private val patternDay = "§aDay (.*)".toPattern()
- private val patternMonth = "(.*), Year (.*)".toPattern()
- private val patternCrop = "§e○ §7(.*)".toPattern()
+ private val patternDay = "§aDay (?<day>.*)".toPattern()
+ private val patternMonth = "(?<month>.*), Year (?<year>.*)".toPattern()
+ private val patternCrop = "§e○ §7(?<crop>.*)".toPattern()
private val maxContestsPerYear = 124
private val contestDuration = 1_000 * 60 * 20
@@ -92,17 +94,16 @@ class GardenNextJacobContest {
if (lore[0] != "§7To Calendar and Events") return
inCalendar = true
- readCalendar(event)
- }
- private fun readCalendar(event: InventoryOpenEvent) {
- val inventoryName = event.inventoryName
+ patternMonth.matchMatcher(event.inventoryName) {
+ val month = LorenzUtils.getSBMonthByName(group("month"))
+ val year = group("year").toInt()
- val matcher = patternMonth.matcher(inventoryName)
- if (!matcher.matches()) return
- val month = LorenzUtils.getSBMonthByName(matcher.group(1))
- val year = matcher.group(2).toInt()
+ readCalendar(event.inventoryItems.values, year, month)
+ }
+ }
+ private fun readCalendar(items: MutableCollection<ItemStack>, year: Int, month: Int) {
if (contests.isNotEmpty()) {
val contest = contests.values.first()
val endTime = contest.endTime
@@ -113,7 +114,7 @@ class GardenNextJacobContest {
}
}
- for (item in event.inventoryItems.values) {
+ for (item in items) {
val lore = item.getLore()
if (!lore.any { it.contains("§6§eJacob's Farming Contest") }) continue
@@ -121,13 +122,13 @@ class GardenNextJacobContest {
val matcherDay = patternDay.matcher(name)
if (!matcherDay.matches()) continue
- val day = matcherDay.group(1).toInt()
+ val day = matcherDay.group("day").toInt()
val startTime = SkyBlockTime(year, month, day).toMillis()
val crops = mutableListOf<CropType>()
for (line in lore) {
val matcherCrop = patternCrop.matcher(line)
if (!matcherCrop.matches()) continue
- crops.add(CropType.getByName(matcherCrop.group(1)))
+ crops.add(CropType.getByName(matcherCrop.group("crop")))
}
val contest = FarmingContest(startTime + contestDuration, crops)
contests[startTime] = contest
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt
index d131aa91a..8653502d1 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt
@@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.renderables.Renderable
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign
@@ -22,7 +23,7 @@ class GardenOptimalSpeed {
private val configCustomSpeed get() = config.optimalSpeedCustom
private var currentSpeed = 100
private var optimalSpeed = -1
- private val currentSpeedPattern = " Speed: §r§f✦(.*)".toPattern()
+ private val currentSpeedPattern = " Speed: §r§f✦(?<speed>.*)".toPattern()
private var lastWarnTime = 0L
private var cropInHand: CropType? = null
private var rancherOverlayList: List<List<Any?>> = emptyList()
@@ -30,9 +31,8 @@ class GardenOptimalSpeed {
@SubscribeEvent
fun onTabListUpdate(event: TabListUpdateEvent) {
for (line in event.tabList) {
- val matcher = currentSpeedPattern.matcher(line)
- if (matcher.matches()) {
- currentSpeed = matcher.group(1).toInt()
+ currentSpeedPattern.matchMatcher(line) {
+ currentSpeed = group("speed").toInt()
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenTeleportPadCompactName.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenTeleportPadCompactName.kt
index 4dcd73745..a23177f39 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenTeleportPadCompactName.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenTeleportPadCompactName.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.client.event.RenderLivingEvent
@@ -8,7 +9,7 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class GardenTeleportPadCompactName {
- private val patternName = "§.✦ §aWarp To (.*)".toPattern()
+ private val patternName = "§.✦ §aWarp To (?<name>.*)".toPattern()
private val patternNoName = "§.✦ §cNo Destination".toPattern()
@SubscribeEvent(priority = EventPriority.HIGH)
@@ -19,13 +20,12 @@ class GardenTeleportPadCompactName {
val name = entity.name
- if (patternNoName.matcher(name).matches()) {
+ patternNoName.matchMatcher(name) {
event.isCanceled = true
}
- val matcher = patternName.matcher(name)
- if (matcher.matches()) {
- entity.customNameTag = matcher.group(1)
+ patternName.matchMatcher(name) {
+ entity.customNameTag = group("name")
}
}
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt
index ba9cbe9a1..763186a03 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt
@@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.TimeUtils
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration
@@ -115,9 +116,8 @@ class ComposterDisplay {
if (next) {
if (line == "") break
for (type in DataType.values()) {
- val matcher = type.pattern.matcher(line)
- if (matcher.matches()) {
- newData[type] = matcher.group(1)
+ type.pattern.matchMatcher(line) {
+ newData[type] = group(1)
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt
index aaccea8bd..b8a7a4fc3 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterInventoryNumbers.kt
@@ -6,12 +6,13 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class ComposterInventoryNumbers {
- private val valuePattern = "(?:.*) §e(.*)§6\\/(.*)".toPattern()
- private val compostsPattern = "§7§7Compost Available: §a(.*)".toPattern()
+ private val valuePattern = "(?:.*) §e(?<having>.*)§6\\/(?<total>.*)".toPattern()
+ private val compostsPattern = "§7§7Compost Available: §a(?<amount>.*)".toPattern()
@SubscribeEvent
fun onRenderItemTip(event: RenderInventoryItemTipEvent) {
@@ -27,45 +28,41 @@ class ComposterInventoryNumbers {
// Composts Available
if (slotNumber == 22) {
for (line in stack.getLore()) {
- val matcher = compostsPattern.matcher(line)
- if (!matcher.matches()) continue
-
- val total = matcher.group(1).replace(",", "").toInt()
- if (total <= 64) continue
-
- event.offsetY = -2
- event.offsetX = -20
- event.stackTip = "§6${total.addSeparators()}"
- return
+ compostsPattern.matchMatcher(line) {
+ val total = group("amount").replace(",", "").toInt()
+ event.offsetY = -2
+ event.offsetX = -20
+ event.stackTip = "§6${total.addSeparators()}"
+ return
+ }
}
}
// Organic Matter or Fuel
if (slotNumber == 46 || slotNumber == 52) {
for (line in stack.getLore()) {
- val matcher = valuePattern.matcher(line)
- if (!matcher.matches()) continue
+ valuePattern.matchMatcher(line) {
+ val having = group("having").removeColor().replace(",", "").toDouble().toInt()
+ val havingFormat = NumberUtil.format(having)
+ val total = group("total").removeColor()
- val having = matcher.group(1).removeColor().replace(",", "").toDouble().toInt()
- val havingFormat = NumberUtil.format(having)
- val total = matcher.group(2).removeColor()
+ val color = if (slotNumber == 46) {
+ // Organic Matter
+ event.offsetY = -95
+ event.offsetX = 5
+ event.alignLeft = false
+ "§e"
+ } else {
+ // Fuel
+ event.offsetY = -76
+ event.offsetX = -20
+ "§a"
+ }
- val color = if (slotNumber == 46) {
- // Organic Matter
- event.offsetY = -95
- event.offsetX = 5
- event.alignLeft = false
- "§e"
- } else {
- // Fuel
- event.offsetY = -76
- event.offsetX = -20
- "§a"
+ event.stackTip = "$color$havingFormat/$total"
+ return
}
-
- event.stackTip = "$color$havingFormat/$total"
- return
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
index 3e98858d8..3cdc0b699 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
@@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.jsonobjects.GardenJson
import at.hannibal2.skyhanni.utils.renderables.Renderable
@@ -120,10 +121,9 @@ class ComposterOverlay {
for (upgrade in ComposterUpgrade.values()) {
event.itemStack?.name?.let {
if (it.contains(upgrade.displayName)) {
- val matcher = ComposterUpgrade.regex.matcher(it)
- matcher.matches()
- val level = matcher.group("level")?.romanToDecimalIfNeeded() ?: 0
- maxLevel = level == 25
+ maxLevel = ComposterUpgrade.regex.matchMatcher(it) {
+ group("level")?.romanToDecimalIfNeeded() ?: 0
+ } == 25
extraComposterUpgrade = upgrade
update()
return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt
index 0bf7be4da..c62b0c84d 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenInventoryNumbers.kt
@@ -8,13 +8,14 @@ import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
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 GardenInventoryNumbers {
private val config get() = SkyHanniMod.feature.garden
- private var patternTierProgress = "§7Progress to Tier (.*): §e(?:.*)".toPattern()
- private var patternUpgradeTier = "§7Current Tier: §[ea](.*)§7/§a.*".toPattern()
+ private var patternTierProgress = "§7Progress to Tier (?<tier>.*): §e(?:.*)".toPattern()
+ private var patternUpgradeTier = "§7Current Tier: §[ea](?<tier>.*)§7/§a.*".toPattern()
@SubscribeEvent
fun onRenderItemTip(event: RenderItemTipEvent) {
@@ -26,7 +27,7 @@ class GardenInventoryNumbers {
event.stack.getLore()
.map { patternTierProgress.matcher(it) }
.filter { it.matches() }
- .map { it.group(1).romanToDecimalIfNeeded() - 1 }
+ .map { it.group("tier").romanToDecimalIfNeeded() - 1 }
.forEach { event.stackTip = "" + it }
}
@@ -36,7 +37,7 @@ class GardenInventoryNumbers {
event.stack.getLore()
.map { patternUpgradeTier.matcher(it) }
.filter { it.matches() }
- .map { it.group(1) }
+ .map { it.group("tier") }
.forEach { event.stackTip = "" + it }
}
@@ -44,9 +45,8 @@ class GardenInventoryNumbers {
if (!config.numberComposterUpgrades) return
event.stack.name?.let {
- val matcher = ComposterUpgrade.regex.matcher(it)
- if (matcher.matches()) {
- val level = matcher.group("level")?.romanToDecimalIfNeeded() ?: 0
+ ComposterUpgrade.regex.matchMatcher(it) {
+ val level = group("level")?.romanToDecimalIfNeeded() ?: 0
event.stackTip = "$level"
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt
index dcb018404..5dc226327 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.RenderInventoryItemTipEvent
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class GardenTeleportPadInventoryNumber {
@@ -57,7 +58,7 @@ class GardenTeleportPadInventoryNumber {
}
private var inTeleportPad = false
- private val pattern = "§.(.*) teleport pad".toPattern()
+ private val pattern = "§.(?<number>.*) teleport pad".toPattern()
@SubscribeEvent
fun onInventoryOpen(event: InventoryOpenEvent) {
@@ -71,13 +72,12 @@ class GardenTeleportPadInventoryNumber {
if (!inTeleportPad) return
val name = event.stack.name?.lowercase() ?: return
- val matcher = pattern.matcher(name)
- if (!matcher.matches()) return
- val text = matcher.group(1)
- numbers[text]?.let {
- event.stackTip = "$it"
- return
+ pattern.matchMatcher(name) {
+ val text = group("number")
+ numbers[text]?.let {
+ event.stackTip = "$it"
+ }
}
}
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt
index 3a83ff92b..f6138e079 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt
@@ -13,10 +13,11 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class SkyMartCopperPrice {
- private val pattern = "§c(.*) Copper".toPattern()
+ private val pattern = "§c(?<amount>.*) Copper".toPattern()
private var display = listOf<List<Any>>()
private val config get() = SkyHanniMod.feature.garden
@@ -33,25 +34,23 @@ class SkyMartCopperPrice {
val table = mutableMapOf<Pair<String, String>, Pair<Double, String>>()
for (stack in event.inventoryItems.values) {
for (line in stack.getLore()) {
- val matcher = pattern.matcher(line)
- if (!matcher.matches()) continue
-
val internalName = stack.getInternalName()
val lowestBin = NEUItems.getPrice(internalName)
if (lowestBin == -1.0) continue
+ pattern.matchMatcher(line) {
+ val amount = group("amount").replace(",", "").toInt()
+ val factor = lowestBin / amount
+ val perFormat = NumberUtil.format(factor)
+ val priceFormat = NumberUtil.format(lowestBin)
+ val amountFormat = NumberUtil.format(amount)
- val amount = matcher.group(1).replace(",", "").toInt()
- val factor = lowestBin / amount
- val perFormat = NumberUtil.format(factor)
- val priceFormat = NumberUtil.format(lowestBin)
- val amountFormat = NumberUtil.format(amount)
-
- val name = stack.nameWithEnchantment!!
- val advancedStats = if (config.skyMartCopperPriceAdvancedStats) {
- " §7(§6$priceFormat §7/ §c$amountFormat Copper§7)"
- } else ""
- val pair = Pair("$name§f:", "§6§l$perFormat$advancedStats")
- table[pair] = Pair(factor, internalName)
+ val name = stack.nameWithEnchantment!!
+ val advancedStats = if (config.skyMartCopperPriceAdvancedStats) {
+ " §7(§6$priceFormat §7/ §c$amountFormat Copper§7)"
+ } else ""
+ val pair = Pair("$name§f:", "§6§l$perFormat$advancedStats")
+ table[pair] = Pair(factor, internalName)
+ }
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
index 3823d80b8..6066608ec 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
@@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RenderUtils.drawString
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.renderables.Renderable
import io.github.moulberry.notenoughupdates.events.SlotClickEvent
@@ -41,8 +42,8 @@ class GardenVisitorFeatures {
private var lastClickedNpc = 0
private var tick = 0
private val newVisitorArrivedMessage = ".* §r§ehas arrived on your §r§bGarden§r§e!".toPattern()
- private val copperPattern = " §8\\+§c(.*) Copper".toPattern()
- private val gardenExperiencePattern = " §8\\+§2(.*) §7Garden Experience".toPattern()
+ private val copperPattern = " §8\\+§c(?<amount>.*) Copper".toPattern()
+ private val gardenExperiencePattern = " §8\\+§2(?<amount>.*) §7Garden Experience".toPattern()
private val visitorChatMessagePattern = "§e\\[NPC] (§.)?(?<name>.*)§f: §r§f.*".toPattern()
private val config get() = SkyHanniMod.feature.garden
private val logger = LorenzLogger("garden/visitors")
@@ -335,17 +336,15 @@ class GardenVisitorFeatures {
}
if (config.visitorCopperPrice) {
- val matcher = copperPattern.matcher(line)
- if (matcher.matches()) {
- val coppers = matcher.group(1).replace(",", "").toInt()
+ copperPattern.matchMatcher(line) {
+ val coppers = group("amount").replace(",", "").toInt()
val pricePerCopper = NumberUtil.format((totalPrice / coppers).toInt())
list[i + itemsWithSpeedCounter] = "$line §7(price per §6$pricePerCopper§7)"
}
}
if (config.visitorExperiencePrice) {
- val matcher = gardenExperiencePattern.matcher(line)
- if (matcher.matches()) {
- val gardenExp = matcher.group(1).replace(",", "").toInt()
+ gardenExperiencePattern.matchMatcher(line) {
+ val gardenExp = group("amount").replace(",", "").toInt()
val pricePerCopper = NumberUtil.format((totalPrice / gardenExp).toInt())
list[i + itemsWithSpeedCounter] = "$line §7(price per §6$pricePerCopper§7)"
}
@@ -480,16 +479,13 @@ class GardenVisitorFeatures {
}
}
- private fun hideVisitorMessage(message: String): Boolean {
- val matcher = visitorChatMessagePattern.matcher(message)
- if (!matcher.matches()) return false
+ private fun hideVisitorMessage(message: String) = visitorChatMessagePattern.matchMatcher(message) {
+ val name = group("name")
+ if (name == "Spaceman") return false
+ if (name == "Beth") return false
- val name = matcher.group("name")
- if (name == "Spaceman") return false
- if (name == "Beth") return false
-
- return visitors.keys.any { it.removeColor() == name }
- }
+ return visitors.keys.any { it.removeColor() == name }
+ } ?: false
private fun update() {
checkVisitorsReady()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt
index 3e5ffa6bb..3535c31cd 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt
@@ -8,14 +8,15 @@ import at.hannibal2.skyhanni.events.VisitorArrivalEvent
import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.TimeUtils
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.math.roundToLong
class GardenVisitorTimer {
- private val patternNextVisitor = " Next Visitor: §r§b(.*)".toPattern()
- private val patternVisitors = "§b§lVisitors: §r§f\\((\\d)\\)".toPattern()
+ private val patternNextVisitor = " Next Visitor: §r§b(?<time>.*)".toPattern()
+ private val patternVisitors = "§b§lVisitors: §r§f\\((?<amount>\\d)\\)".toPattern()
private var render = ""
private var lastMillis = 0L
private var lastVisitors: Int = -1
@@ -38,9 +39,9 @@ class GardenVisitorTimer {
var millis = visitorInterval
var queueFull = false
for (line in event.tabList) {
- var matcher = patternNextVisitor.matcher(line)
+ val matcher = patternNextVisitor.matcher(line)
if (matcher.matches()) {
- val rawTime = matcher.group(1)
+ val rawTime = matcher.group("time")
millis = TimeUtils.getMillis(rawTime)
} else if (line == " Next Visitor: §r§c§lQueue Full!") {
queueFull = true
@@ -49,9 +50,8 @@ class GardenVisitorTimer {
return
}
- matcher = patternVisitors.matcher(line)
- if (matcher.matches()) {
- visitorsAmount = matcher.group(1).toInt()
+ patternVisitors.matchMatcher(line) {
+ visitorsAmount = group("amount").toInt()
}
}
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 90bc84b19..1b6b3915c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt
@@ -12,14 +12,15 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils.between
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matchRegex
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class ItemDisplayOverlayFeatures {
- private val wishingCompassPattern = "§7Remaining Uses: §e(.*)§8/§e3".toPattern()
- private val rangerBootsSpeedCapPattern = "§7Current Speed Cap: §a(.*)".toPattern()
+ private val wishingCompassPattern = "§7Remaining Uses: §e(?<amount>.*)§8/§e3".toPattern()
+ private val rangerBootsSpeedCapPattern = "§7Current Speed Cap: §a(?<cap>.*)".toPattern()
private val petLevelPattern = "\\[Lvl (?<level>.*)] (?:.*)".toPattern()
@SubscribeEvent
@@ -70,9 +71,8 @@ class ItemDisplayOverlayFeatures {
val chestName = InventoryUtils.openInventoryName()
if (!chestName.endsWith("Sea Creature Guide")) {
if (ItemUtils.isPet(itemName)) {
- val matcher = petLevelPattern.matcher(itemName)
- if (matcher.matches()) {
- val level = matcher.group("level").toInt()
+ petLevelPattern.matchMatcher(itemName) {
+ val level = group("level").toInt()
if (level != ItemUtils.maxPetLevel(itemName)) {
return "$level"
}
@@ -101,9 +101,8 @@ class ItemDisplayOverlayFeatures {
if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(7)) {
if (itemName.contains("Wishing Compass")) {
for (line in item.getLore()) {
- val matcher = wishingCompassPattern.matcher(line)
- if (matcher.matches()) {
- val uses = matcher.group(1)
+ wishingCompassPattern.matchMatcher(line) {
+ val uses = group("amount")
if (uses != "3") {
return uses
}
@@ -155,9 +154,8 @@ class ItemDisplayOverlayFeatures {
if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(11)) {
if (item.getInternalName() == "RANCHERS_BOOTS") {
for (line in item.getLore()) {
- val matcher = rangerBootsSpeedCapPattern.matcher(line)
- if (matcher.matches()) {
- return matcher.group(1)
+ rangerBootsSpeedCapPattern.matchMatcher(line) {
+ return group("cap")
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt
index f3ec32f1e..02f7d0ee0 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt
@@ -9,12 +9,12 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class StatsTuning {
-
- private val patternStatPoints = "§7Stat has: §e(\\d+) point(s)?".toPattern()
+ private val patternStatPoints = "§7Stat has: §e(?<amount>\\d+) points?".toPattern()
@SubscribeEvent
fun onRenderItemTip(event: RenderInventoryItemTipEvent) {
@@ -85,9 +85,8 @@ class StatsTuning {
if (SkyHanniMod.feature.inventory.statsTuningPoints) {
if (inventoryName == "Stats Tuning") {
for (line in stack.getLore()) {
- val matcher = patternStatPoints.matcher(line)
- if (matcher.matches()) {
- val points = matcher.group(1)
+ patternStatPoints.matchMatcher(line) {
+ val points = group("amount")
event.stackTip = points
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt
index 382a3d8ed..4c0cd3937 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt
@@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
import at.hannibal2.skyhanni.utils.RenderUtils.drawString
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matchRegex
import net.minecraft.client.Minecraft
import net.minecraft.entity.EntityLivingBase
@@ -38,7 +39,7 @@ class MinionFeatures {
private var lastCoinsRecived = 0L
private var lastMinionPickedUp = 0L
private var coinsPerDay = ""
- private val minionUpgradePattern = "§aYou have upgraded your Minion to Tier (.*)".toPattern()
+ private val minionUpgradePattern = "§aYou have upgraded your Minion to Tier (?<tier>.*)".toPattern()
@SubscribeEvent
fun onConfigLoad(event: ConfigLoadEvent) {
@@ -199,9 +200,8 @@ class MinionFeatures {
lastMinionPickedUp = System.currentTimeMillis()
}
- val matcher = minionUpgradePattern.matcher(message)
- if (matcher.matches()) {
- val newTier = matcher.group(1).romanToDecimalIfNeeded()
+ minionUpgradePattern.matchMatcher(message) {
+ val newTier = group("tier").romanToDecimalIfNeeded()
minions[lastMinion]?.let {
val minionName = getMinionName(it.displayName, newTier)
it.displayName = minionName
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CompactSplashPotionMessage.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CompactSplashPotionMessage.kt
index b5851136b..932cdb1bf 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/CompactSplashPotionMessage.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CompactSplashPotionMessage.kt
@@ -3,32 +3,29 @@ package at.hannibal2.skyhanni.features.misc
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraft.util.ChatComponentText
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class CompactSplashPotionMessage {
-
- private val POTION_EFFECT_PATTERN =
- "§a§lBUFF! §fYou have gained §r(.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern()
-
- private val POTION_EFFECT_OTHERS_PATTERN =
- "§a§lBUFF! §fYou were splashed by (.*) §fwith §r(.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern()
+ private val potionEffectPattern =
+ "§a§lBUFF! §fYou have gained §r(?<name>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern()
+ private val potionEffectOthersPattern =
+ "§a§lBUFF! §fYou were splashed by (?<playerName>.*) §fwith §r(?<effectName>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern()
@SubscribeEvent
fun onChatMessage(event: LorenzChatEvent) {
if (!LorenzUtils.inSkyBlock || !SkyHanniMod.feature.chat.compactPotionMessage) return
- var matcher = POTION_EFFECT_PATTERN.matcher(event.message)
- if (matcher.matches()) {
- val name = matcher.group(1)
+ potionEffectPattern.matchMatcher(event.message) {
+ val name = group("name")
event.chatComponent = ChatComponentText("§a§lPotion Effect! §r$name")
}
- matcher = POTION_EFFECT_OTHERS_PATTERN.matcher(event.message)
- if (matcher.matches()) {
- val playerName = matcher.group(1).removeColor()
- val effectName = matcher.group(2)
+ potionEffectOthersPattern.matchMatcher(event.message) {
+ val playerName = group("playerName").removeColor()
+ val effectName = group("effectName")
event.chatComponent = ChatComponentText("§a§lPotion Effect! §r$effectName by §b$playerName")
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt
index 4cdbffab5..ff7c4e6fd 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt
@@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.sorted
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.TimeUnit
import at.hannibal2.skyhanni.utils.TimeUtils
import net.minecraft.network.play.server.S30PacketWindowItems
@@ -43,7 +44,7 @@ class NonGodPotEffectDisplay {
"GABAGOEY" to "§9Gabagoey Mixin",
)
- private var patternEffectsCount = "§7You have §e(\\d+) §7non-god effects\\.".toPattern()
+ private var patternEffectsCount = "§7You have §e(?<name>\\d+) §7non-god effects\\.".toPattern()
private var totalEffectsCount = 0
@SubscribeEvent
@@ -174,9 +175,8 @@ class NonGodPotEffectDisplay {
activeEffects["§2Mushed Glowy Tonic I"] = System.currentTimeMillis() + duration
update()
}
- val matcher = patternEffectsCount.matcher(line)
- if (matcher.matches()) {
- val group = matcher.group(1)
+ patternEffectsCount.matchMatcher(line) {
+ val group = group("name")
effectsCount = group.toInt()
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt
index ac73c33cf..93c05ee32 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt
@@ -116,14 +116,14 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?)
var slayerLevel = ""
var bossAlive = "spawning"
val slayerRegex =
- Pattern.compile("((?:\\w| )*) ([IV]+)") // Samples: Revenant Horror I; Tarantula Broodfather IV
+ Pattern.compile("(?<name>(?:\\w| )*) (?<level>[IV]+)") // Samples: Revenant Horror I; Tarantula Broodfather IV
for (line in ScoreboardData.sidebarLinesFormatted) {
val noColorLine = line.removeColor()
val match = slayerRegex.matcher(noColorLine)
if (match.matches()) {
- slayerName = match.group(1)
- slayerLevel = match.group(2)
+ slayerName = match.group("name")
+ slayerLevel = match.group("level")
} else if (noColorLine == "Slay the boss!") bossAlive = "slaying"
else if (noColorLine == "Boss slain!") bossAlive = "slain"
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailykuudra/DailyKuudraBossHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailykuudra/DailyKuudraBossHelper.kt
index c6bb2d7bc..6b8da38e4 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailykuudra/DailyKuudraBossHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailykuudra/DailyKuudraBossHelper.kt
@@ -12,12 +12,13 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class DailyKuudraBossHelper(private val reputationHelper: CrimsonIsleReputationHelper) {
val kuudraTiers = mutableListOf<KuudraTier>()
- private val pattern = " Kuudra's Hollow \\(T(.*)\\)".toPattern()
+ private val pattern = " Kuudra's Hollow \\(T(?<tier>.*)\\)".toPattern()
private var kuudraLocation: LorenzVec? = null
private var allKuudraDone = true
@@ -46,9 +47,8 @@ class DailyKuudraBossHelper(private val reputationHelper: CrimsonIsleReputationH
if (message != " §r§6§lKUUDRA DOWN!") return
for (line in ScoreboardData.sidebarLines) {
- val matcher = pattern.matcher(line)
- if (matcher.matches()) {
- val tier = matcher.group(1).toInt()
+ pattern.matchMatcher(line) {
+ val tier = group("tier").toInt()
val kuudraTier = getByTier(tier)!!
finished(kuudraTier)
return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/QuestLoader.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/QuestLoader.kt
index 82b83105a..22b1523d9 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/QuestLoader.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/QuestLoader.kt
@@ -33,6 +33,7 @@ class QuestLoader(private val dailyQuestHelper: DailyQuestHelper) {
val amount: Int
val name: String
+ // TODO use regex
if (text.contains(" §r§8x")) {
val split = text.split(" §r§8x")
name = split[0]
diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/miniboss/DailyMiniBossHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/miniboss/DailyMiniBossHelper.kt
index 23c704811..56ba49a4d 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/miniboss/DailyMiniBossHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/miniboss/DailyMiniBossHelper.kt
@@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -29,7 +30,7 @@ class DailyMiniBossHelper(private val reputationHelper: CrimsonIsleReputationHel
val message = event.message
for (miniBoss in miniBosses) {
- if (miniBoss.pattern.matcher(message).matches()) {
+ miniBoss.pattern.matchMatcher(message) {
finished(miniBoss)
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/HideMobNames.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/HideMobNames.kt
index 5b2931c88..34a98bb43 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/HideMobNames.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/HideMobNames.kt
@@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.slayer
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.client.event.RenderLivingEvent
@@ -41,7 +42,7 @@ class HideMobNames {
}
private fun addMobToHide(bossName: String) {
- patterns.add("§8\\[§7Lv(\\d+)§8] §c$bossName§r §[ae](.+)§f/§a(.+)§c❤".toPattern())
+ patterns.add("§8\\[§7Lv(?:\\d+)§8] §c$bossName§r §[ae](?<min>.+)§f/§a(?<max>.+)§c❤".toPattern())
}
@SubscribeEvent(priority = EventPriority.HIGH)
@@ -72,10 +73,9 @@ class HideMobNames {
private fun shouldNameBeHidden(name: String): Boolean {
for (pattern in patterns) {
- val matcher = pattern.matcher(name)
- if (matcher.matches()) {
- val min = matcher.group(2)
- val max = matcher.group(3)
+ pattern.matchMatcher(name) {
+ val min = group("min")
+ val max = group("max")
if (min == max || min == "0") {
return true
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt b/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt
index edb2bc2ac..9aa9b2cf2 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/summonings/SummoningMobManager.kt
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.*
import at.hannibal2.skyhanni.utils.*
import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraft.client.Minecraft
import net.minecraft.entity.EntityLiving
import net.minecraft.entity.EntityLivingBase
@@ -39,8 +40,7 @@ class SummoningMobManager {
if (!LorenzUtils.inSkyBlock) return
val message = event.message
- val matcher = spawnPatter.matcher(message)
- if (matcher.matches()) {
+ spawnPatter.matchMatcher(message) {
if (SkyHanniMod.feature.summonings.summoningMobDisplay) {
event.blockedReason = "summoning_soul"
}
@@ -79,8 +79,7 @@ class SummoningMobManager {
Minecraft.getMinecraft().theWorld.loadedEntityList.filter { it is EntityArmorStand && it !in summoningMobNametags }
.forEach {
val name = it.displayName.unformattedText
- val matcher = healthPattern.matcher(name)
- if (matcher.matches()) {
+ healthPattern.matchMatcher(name) {
val playerName = LorenzUtils.getPlayerName()
if (name.contains(playerName)) {
summoningMobNametags.add(it as EntityArmorStand)
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiIngameHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiIngameHook.kt
index 424c3659f..5eb964f62 100644
--- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiIngameHook.kt
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiIngameHook.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.mixins.hooks
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraft.client.gui.FontRenderer
private val piggyPattern = "Piggy: (?<coins>.*)".toPattern()
@@ -18,9 +19,8 @@ fun drawString(
}
}
if (SkyHanniMod.feature.misc.hidePiggyScoreboard) {
- val matcher = piggyPattern.matcher(text)
- if (matcher.matches()) {
- val coins = matcher.group("coins")
+ piggyPattern.matchMatcher(text) {
+ val coins = group("coins")
return instance.drawString("Purse: $coins", x, y, color)
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
index 0b197e0d9..8c653edd7 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Marker
@@ -118,7 +119,7 @@ class MinecraftConsoleFilter(private val loggerConfigName: String) : Filter {
// }
// }
if (SkyHanniMod.feature.dev.filterBiomeIdBounds) {
- if (patternBiomeIdBounds.matcher(formattedMessage).matches()) {
+ patternBiomeIdBounds.matchMatcher(formattedMessage) {
filterConsole("Biome ID bounds")
return Filter.Result.DENY
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index 721547ef4..76da79bc5 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.utils.ItemBlink.checkBlinkItem
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import io.github.moulberry.notenoughupdates.NEUManager
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe
@@ -32,15 +33,12 @@ object NEUItems {
return itemNameCache[itemName]!!
}
- val matcher = turboBookPattern.matcher(itemName)
- var internalName = if (matcher.matches()) {
- val type = matcher.group("name")
- val level = matcher.group("level").romanToDecimal()
+ var internalName = turboBookPattern.matchMatcher(itemName) {
+ val type = group("name")
+ val level = group("level").romanToDecimal()
val name = turboCheck(type).uppercase()
"TURBO_$name;$level"
- } else {
- ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) ?: return null
- }
+ } ?: ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) ?: return null
// This fixes a NEU bug with §9Hay Bale (cosmetic item)
// TODO remove workaround when this is fixed in neu
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
index 138c70804..df780b300 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
@@ -1,7 +1,8 @@
package at.hannibal2.skyhanni.utils
-object TimeUtils {
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+object TimeUtils {
private val pattern =
"(?:(?<y>\\d+) ?y(?:\\w* ?)?)?(?:(?<d>\\d+) ?d(?:\\w* ?)?)?(?:(?<h>\\d+) ?h(?:\\w* ?)?)?(?:(?<m>\\d+) ?m(?:\\w* ?)?)?(?:(?<s>\\d+) ?s(?:\\w* ?)?)?".toPattern()
@@ -54,15 +55,12 @@ object TimeUtils {
}
// TODO: use kotlin Duration
- fun getMillis(string: String): Long {
- val matcher = pattern.matcher(string.lowercase().trim())
- if (!matcher.matches()) return tryAlternativeFormat(string)
-
- val years = matcher.group("y")?.toLong() ?: 0L
- val days = matcher.group("d")?.toLong() ?: 0L
- val hours = matcher.group("h")?.toLong() ?: 0L
- val minutes = matcher.group("m")?.toLong() ?: 0L
- val seconds = matcher.group("s")?.toLong() ?: 0L
+ fun getMillis(string: String) = pattern.matchMatcher(string.lowercase().trim()) {
+ val years = group("y")?.toLong() ?: 0L
+ val days = group("d")?.toLong() ?: 0L
+ val hours = group("h")?.toLong() ?: 0L
+ val minutes = group("m")?.toLong() ?: 0L
+ val seconds = group("s")?.toLong() ?: 0L
var millis = 0L
millis += seconds * 1000
@@ -71,8 +69,8 @@ object TimeUtils {
millis += days * 24 * 60 * 60 * 1000
millis += (years * 365.25 * 24 * 60 * 60 * 1000).toLong()
- return millis
- }
+ millis
+ } ?: tryAlternativeFormat(string)
private fun tryAlternativeFormat(string: String): Long {
val split = string.split(":")