diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-02-16 21:21:43 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-16 11:21:43 +0100 |
commit | f91973d60948d449cc45a4add901e6fe43aebd62 (patch) | |
tree | 4c8c77ec4a9585a821651a034ebe5bed3308a6af /src/main/java/at/hannibal2/skyhanni/features/event | |
parent | 26fe548fa9a5cfe29b130a0a5585278df3429ee9 (diff) | |
download | skyhanni-f91973d60948d449cc45a4add901e6fe43aebd62.tar.gz skyhanni-f91973d60948d449cc45a4add901e6fe43aebd62.tar.bz2 skyhanni-f91973d60948d449cc45a4add901e6fe43aebd62.zip |
Moved many regex patterns in the repo and code cleanup. #871
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/event')
7 files changed, 80 insertions, 30 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaProfitTracker.kt index a41ee2689..7724d4c5d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaProfitTracker.kt @@ -28,12 +28,13 @@ object DianaProfitTracker { private val config get() = SkyHanniMod.feature.event.diana.dianaProfitTracker private var allowedDrops = listOf<NEUInternalName>() - private val chatDugOutPattern by RepoPattern.pattern( - "diana.chat.burrow.dug", + private val patternGroup = RepoPattern.group("diana.chat") + private val chatDugOutPattern by patternGroup.pattern( + "burrow.dug", "(§eYou dug out a Griffin Burrow!|§eYou finished the Griffin burrow chain!) .*" ) - private val chatDugOutCoinsPattern by RepoPattern.pattern( - "diana.chat.coins", + private val chatDugOutCoinsPattern by patternGroup.pattern( + "coins", "§6§lWow! §r§eYou dug out §r§6(?<coins>.*) coins§r§e!" ) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt index 9276823fe..66d4f2b85 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt @@ -20,6 +20,7 @@ import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.getLorenzVec +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft import net.minecraft.client.entity.EntityOtherPlayerMP import net.minecraft.network.play.server.S02PacketChat @@ -32,10 +33,16 @@ object InquisitorWaypointShare { private val config get() = SkyHanniMod.feature.event.diana.inquisitorSharing - // TODO USE SH-REPO - private val partyPattern = - "§9Party §8> (?<playerName>.*)§f: §rx: (?<x>-?[0-9]{1,4}), y: (?<y>-?[0-9]{1,4}), z: (?<z>-?[0-9]{1,4})\\b".toPattern() - private val diedPattern = "§9Party §8> (?<playerName>.*)§f: §rInquisitor dead!".toPattern() + private val patternGroup = RepoPattern.group("diana.waypoints") + private val partyPattern by patternGroup.pattern( + "party", + "§9Party §8> (?<playerName>.*)§f: §rx: (?<x>-?[0-9]{1,4}), y: (?<y>-?[0-9]{1,4}), z: (?<z>-?[0-9]{1,4})\\b" + ) + private val diedPattern by patternGroup.pattern( + "died", + "§9Party §8> (?<playerName>.*)§f: §rInquisitor dead!" + ) + private var time = 0L private var testTime = 0L private var lastInquisitorMessage = "" diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/MythologicalCreatureTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/MythologicalCreatureTracker.kt index dbcc1574e..001a96c4a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/MythologicalCreatureTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/MythologicalCreatureTracker.kt @@ -21,23 +21,36 @@ import java.util.regex.Pattern object MythologicalCreatureTracker { - private val group = RepoPattern.group("event.diana.mythological.tracker") - - private val minotaurPattern by group.pattern("minotaur", ".* §r§eYou dug out a §r§2Minotaur§r§e!") - private val gaiaConstructPattern by group.pattern("gaiaconstruct", ".* §r§eYou dug out a §r§2Gaia Construct§r§e!") - private val minosChampionPattern by group.pattern("minoschampion", ".* §r§eYou dug out a §r§2Minos Champion§r§e!") - private val siameseLynxesPattern by group.pattern("siameselynxes", ".* §r§eYou dug out §r§2Siamese Lynxes§r§e!") - private val minosHunterPattern by group.pattern("minoshunter", ".* §r§eYou dug out a §r§2Minos Hunter§r§e!") - private val minosInquisitorPattern by group.pattern( + private val config get() = SkyHanniMod.feature.event.diana.mythologicalMobtracker + + private val patternGroup = RepoPattern.group("event.diana.mythological.tracker") + private val minotaurPattern by patternGroup.pattern( + "minotaur", + ".* §r§eYou dug out a §r§2Minotaur§r§e!" + ) + private val gaiaConstructPattern by patternGroup.pattern( + "gaiaconstruct", + ".* §r§eYou dug out a §r§2Gaia Construct§r§e!" + ) + private val minosChampionPattern by patternGroup.pattern( + "minoschampion", + ".* §r§eYou dug out a §r§2Minos Champion§r§e!" + ) + private val siameseLynxesPattern by patternGroup.pattern( + "siameselynxes", + ".* §r§eYou dug out §r§2Siamese Lynxes§r§e!" + ) + private val minosHunterPattern by patternGroup.pattern( + "minoshunter", + ".* §r§eYou dug out a §r§2Minos Hunter§r§e!" + ) + private val minosInquisitorPattern by patternGroup.pattern( "minosinquisitor", ".* §r§eYou dug out a §r§2Minos Inquisitor§r§e!" ) - private val config get() = SkyHanniMod.feature.event.diana.mythologicalMobtracker - - private val tracker = - SkyHanniTracker("Mythological Creature Tracker", { Data() }, { it.diana.mythologicalMobTracker }) - { drawDisplay(it) } + private val tracker = SkyHanniTracker("Mythological Creature Tracker", { Data() }, { it.diana.mythologicalMobTracker }) + { drawDisplay(it) } class Data : TrackerData() { diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasure.kt b/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasure.kt index 219a22285..2511b2ee1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasure.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasure.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.event.jerry.frozentreasure import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern enum class FrozenTreasure( val internalName: String, @@ -23,5 +24,11 @@ enum class FrozenTreasure( EINARY_RED_HOODIE("FROZEN_BAIT", "§cEinary's Red Hoodie", 1), ; - val pattern by lazy { "FROZEN TREASURE! You found ${displayName.removeColor()}!".toPattern() } + val chatPattern by RepoPattern.pattern( + "event.jerry.frozentreasure.item." + this.patternName(), + patternText() + ) + + private fun patternName() = name.lowercase().replace("_", "") + private fun patternText() = "FROZEN TREASURE! You found ${displayName.removeColor()}!" } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt index 7b3f236f0..f335b882c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt @@ -18,6 +18,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker import at.hannibal2.skyhanni.utils.tracker.TrackerData import com.google.gson.annotations.Expose @@ -27,16 +28,23 @@ import kotlin.concurrent.fixedRateTimer object FrozenTreasureTracker { private val config get() = SkyHanniMod.feature.event.winter.frozenTreasureTracker + + private val compactPattern by RepoPattern.pattern( + "event.jerry.frozentreasure.compact", + "COMPACT! You found an Enchanted Ice!" + ) + private var estimatedIce = 0L private var lastEstimatedIce = 0L private var icePerSecond = mutableListOf<Long>() private var icePerHour = 0 private var stoppedChecks = 0 - private var compactPattern = "COMPACT! You found an Enchanted Ice!".toPattern() private val tracker = SkyHanniTracker("Frozen Treasure Tracker", { Data() }, { it.frozenTreasureTracker }) { formatDisplay(drawDisplay(it)) } init { + FrozenTreasure.entries.forEach { it.chatPattern } + fixedRateTimer(name = "skyhanni-frozen-treasure-tracker", period = 1000) { if (!onJerryWorkshop()) return@fixedRateTimer calculateIcePerHour() @@ -120,7 +128,7 @@ object FrozenTreasureTracker { if (config.hideMessages) event.blockedReason = "frozen treasure tracker" } - for (treasure in FrozenTreasure.entries.filter { it.pattern.matches(message) }) { + for (treasure in FrozenTreasure.entries.filter { it.chatPattern.matches(message) }) { tracker.modify { it.treasuresMined += 1 it.treasureCount.addOrPut(treasure, 1) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/christmas/PresentWaypoints.kt b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/christmas/PresentWaypoints.kt index a6fa577e4..257e69f3d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/christmas/PresentWaypoints.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/christmas/PresentWaypoints.kt @@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent // todo: create abstract class for this and BasketWaypoints @@ -30,10 +31,19 @@ class PresentWaypoints { private val presentSet get() = presentLocations[HypixelData.lobbyType] private val presentEntranceSet get() = presentEntranceLocations[HypixelData.lobbyType] - // TODO use repo pattern - private val presentAlreadyFoundPattern = "§cYou have already found this present!".toPattern() - private val presentFoundPattern = "§aYou found a.*present! §r§e\\(§r§b\\d+§r§e/§r§b\\d+§r§e\\)".toPattern() - private val allFoundPattern = "§aCongratulations! You found all the presents in every lobby!".toPattern() + private val patternGroup = RepoPattern.group("event.lobby.waypoint.presents") + private val presentAlreadyFoundPattern by patternGroup.pattern( + "foundalready", + "§cYou have already found this present!" + ) + private val presentFoundPattern by patternGroup.pattern( + "found", + "§aYou found a.*present! §r§e\\(§r§b\\d+§r§e/§r§b\\d+§r§e\\)" + ) + private val allFoundPattern by patternGroup.pattern( + "foundall", + "§aCongratulations! You found all the presents in every lobby!" + ) @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/winter/UniqueGiftCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/event/winter/UniqueGiftCounter.kt index a039bd339..107156f2e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/winter/UniqueGiftCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/winter/UniqueGiftCounter.kt @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object UniqueGiftCounter { @@ -19,7 +20,10 @@ object UniqueGiftCounter { private val config get() = SkyHanniMod.feature.event.winter.uniqueGiftCounter private val storage get() = ProfileStorageData.playerSpecific?.winter - private val pattern = "§7Unique Players Gifted: §a(?<amount>.*)".toPattern() + private val giftedAmountPattern by RepoPattern.pattern( + "event.winter.uniqugifts.counter.amount", + "§7Unique Players Gifted: §a(?<amount>.*)" + ) private var display = "" @@ -31,7 +35,7 @@ object UniqueGiftCounter { val storage = storage ?: return for (line in item.getLore()) { - pattern.matchMatcher(line) { + giftedAmountPattern.matchMatcher(line) { val amount = group("amount").formatNumber().toInt() storage.amountGifted = amount update() |