diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt index d283c4f2d..69e93489f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.features.mining.PowderTrackerConfig.PowderDisplayEntry import at.hannibal2.skyhanni.data.BossbarData import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.model.TabWidget import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.IslandChangeEvent @@ -21,6 +22,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.TimeUtils import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker import at.hannibal2.skyhanni.utils.tracker.TrackerData @@ -28,6 +30,7 @@ import com.google.gson.JsonArray import com.google.gson.JsonNull import com.google.gson.annotations.Expose import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration import kotlin.time.Duration.Companion.minutes @SkyHanniModule @@ -54,6 +57,14 @@ object PowderTracker { ) /** + * REGEX-TEST: Ends in: §r§b5m 27s + */ + private val tablistEventDuration by patternGroup.pattern( + "powder.duration", + "Ends in: §r§b(?<duration>.*)", + ) + + /** * REGEX-TEST: §b§lCOMPACT! §r§fYou found an §r§aEnchanted Hard Stone§r§f! */ private val compactedPattern by patternGroup.pattern( @@ -70,7 +81,8 @@ object PowderTracker { private val chestInfo = ResourceInfo(0L, 0L, 0, 0.0, mutableListOf()) private val hardStoneInfo = ResourceInfo(0L, 0L, 0, 0.0, mutableListOf()) private var doublePowder = false - private var powderTimer = "" + private var powderTimer = Duration.ZERO + private var eventEnded = false private val gemstones = listOf( "Ruby" to "§c", "Sapphire" to "§b", @@ -94,12 +106,27 @@ object PowderTracker { calculateResourceHour(chestInfo) calculateResourceHour(hardStoneInfo) - doublePowder = powderBossBarPattern.matcher(BossbarData.getBossbar()).find() - powderBossBarPattern.matchMatcher(BossbarData.getBossbar()) { - powderTimer = group("time") - doublePowder = powderTimer != "00:00" + if (TabWidget.EVENT.isActive) { + for ((index, line) in TabWidget.EVENT.lines.withIndex()) { + if (line.contains("2x Powder")) { + if (eventEnded) return + doublePowder = true + val durationLine = TabWidget.EVENT.lines.getOrNull(index + 1) ?: return + tablistEventDuration.matchMatcher(durationLine) { + val duration = group("duration") + powderTimer = TimeUtils.getDuration(duration) + tracker.update() + } + } + } + } else { + powderBossBarPattern.matchMatcher(BossbarData.getBossbar()) { + val duration = group("time") + powderTimer = TimeUtils.getDuration(duration) - tracker.update() + doublePowder = powderTimer > Duration.ZERO + tracker.update() + } } if (lastChestPicked.passedSince() > 1.minutes) { @@ -149,8 +176,14 @@ object PowderTracker { lastChestPicked = SimpleTimeMark.now() } - powderStartedPattern.matchMatcher(msg) { doublePowder = true } - powderEndedPattern.matchMatcher(msg) { doublePowder = false } + powderStartedPattern.matchMatcher(msg) { + doublePowder = true + eventEnded = false + } + powderEndedPattern.matchMatcher(msg) { + doublePowder = false + eventEnded = true + } compactedPattern.matchMatcher(msg) { tracker.modify { @@ -202,6 +235,7 @@ object PowderTracker { hardStoneInfo.stoppedChecks = 0 hardStoneInfo.perMin.clear() doublePowder = false + eventEnded = false tracker.update() } @@ -307,7 +341,7 @@ object PowderTracker { } private fun MutableList<List<Any>>.addPerHour( - map: MutableMap<PowderChestReward, Long>, + map: Map<PowderChestReward, Long>, reward: PowderChestReward, info: ResourceInfo, ) { |