From 619b69c8e06d0795f6bae9fff2d0d71c2016020f Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Wed, 27 Mar 2024 04:38:29 +1100 Subject: Improve mining tracker (#1236) --- .../skyhanni/config/ConfigUpdaterMigrator.kt | 2 +- .../config/features/mining/MiningEventConfig.java | 5 +- .../mining/eventtracker/MiningEventDisplay.kt | 59 +++++++++++----------- .../mining/eventtracker/MiningEventTracker.kt | 9 ++++ 4 files changed, 42 insertions(+), 33 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index f2d64490f..841b8c188 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -11,7 +11,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - const val CONFIG_VERSION = 28 + const val CONFIG_VERSION = 29 fun JsonElement.at(chain: List, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningEventConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningEventConfig.java index 4e8eee363..0476bb524 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningEventConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningEventConfig.java @@ -24,7 +24,7 @@ public class MiningEventConfig { @Expose @ConfigOption(name = "What to Show", desc = "Choose which island's events are shown in the gui.") @ConfigEditorDropdown - public ShowType showType = ShowType.BOTH; + public ShowType showType = ShowType.ALL; @Expose @ConfigOption(name = "Compressed Format", desc = "Compresses the event names so that they are shorter.") @@ -38,9 +38,10 @@ public class MiningEventConfig { public boolean passedEvents = false; public enum ShowType { - BOTH("Both Mining Islands"), + ALL("All Mining Islands"), CRYSTAL("Crystal Hollows Only"), DWARVEN("Dwarven Mines Only"), + MINESHAFT("Mineshaft Only"), CURRENT("Current Island Only"), ; diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventDisplay.kt index 656df781f..4e1fbcef5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventDisplay.kt @@ -16,10 +16,7 @@ object MiningEventDisplay { private val config get() = SkyHanniMod.feature.mining.miningEvent private var display = mutableListOf() - private var dwarvenEvents = listOf() - private var crystalEvents = listOf() - private var lastDwarvenEvent: MiningEventType? = null - private var lastCrystalEvent: MiningEventType? = null + private val islandEventData: MutableMap = mutableMapOf() @SubscribeEvent fun onTick(event: LorenzTickEvent) { @@ -35,31 +32,29 @@ object MiningEventDisplay { private fun updateDisplay() { display.clear() - updateEvents(IslandType.DWARVEN_MINES, dwarvenEvents, lastDwarvenEvent) - updateEvents(IslandType.CRYSTAL_HOLLOWS, crystalEvents, lastCrystalEvent) + updateEvents() } - private fun updateEvents(islandType: IslandType, events: List, lastEvent: MiningEventType?) { - val shouldShow = when (config.showType) { - MiningEventConfig.ShowType.DWARVEN -> islandType == IslandType.DWARVEN_MINES - MiningEventConfig.ShowType.CRYSTAL -> islandType == IslandType.CRYSTAL_HOLLOWS - MiningEventConfig.ShowType.CURRENT -> islandType.isInIsland() - else -> true - } + private fun updateEvents() { + islandEventData.forEach { (islandType, eventDetails) -> + val shouldShow = when (config.showType) { + MiningEventConfig.ShowType.DWARVEN -> islandType == IslandType.DWARVEN_MINES + MiningEventConfig.ShowType.CRYSTAL -> islandType == IslandType.CRYSTAL_HOLLOWS + MiningEventConfig.ShowType.MINESHAFT -> islandType == IslandType.MINESHAFT + MiningEventConfig.ShowType.CURRENT -> islandType.isInIsland() + else -> true + } - events.firstOrNull()?.let { firstEvent -> - if (firstEvent.endsAt.asTimeMark().isInPast()) { - when (islandType) { - IslandType.DWARVEN_MINES -> lastDwarvenEvent = firstEvent.event - IslandType.CRYSTAL_HOLLOWS -> lastCrystalEvent = firstEvent.event - else -> Unit + eventDetails.islandEvents.firstOrNull()?.let { firstEvent -> + if (firstEvent.endsAt.asTimeMark().isInPast()) { + eventDetails.lastEvent = firstEvent.event } } - } - if (shouldShow) { - val upcomingEvents = formatUpcomingEvents(events, lastEvent) - display.add("§a${islandType.displayName}§8: $upcomingEvents") + if (shouldShow) { + val upcomingEvents = formatUpcomingEvents(eventDetails.islandEvents, eventDetails.lastEvent) + display.add("§a${islandType.displayName}§8: $upcomingEvents") + } } } @@ -75,14 +70,16 @@ object MiningEventDisplay { fun updateData(eventData: MiningEventData) { eventData.runningEvents.forEach { (islandType, events) -> - when (islandType) { - IslandType.DWARVEN_MINES -> dwarvenEvents = - events.sortedBy { it.endsAt - it.event.defaultLength.inWholeMilliseconds } + val sorted = events.sortedBy { it.endsAt - it.event.defaultLength.inWholeMilliseconds } - IslandType.CRYSTAL_HOLLOWS -> crystalEvents = - events.filter { !it.event.dwarvenSpecific } - .sortedBy { it.endsAt - it.event.defaultLength.inWholeMilliseconds } - else -> Unit + val oldData = islandEventData[islandType] + if (oldData == null) { + //todo remove once mineshaft is on main server + if (sorted.isNotEmpty() || islandType != IslandType.MINESHAFT) { + islandEventData[islandType] = MiningIslandEventInfo(sorted) + } + } else { + oldData.islandEvents = sorted } } } @@ -90,3 +87,5 @@ object MiningEventDisplay { private fun shouldDisplay() = LorenzUtils.inSkyBlock && config.enabled && !ReminderUtils.isBusy() && !(!config.outsideMining && !LorenzUtils.inAdvancedMiningIsland()) } + +private class MiningIslandEventInfo(var islandEvents: List, var lastEvent: MiningEventType? = null) diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventTracker.kt index e4d8e31a3..9d0ce3c33 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventTracker.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.mining.eventtracker import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigManager +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.BossbarData import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.IslandType @@ -18,6 +19,7 @@ import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.TimeUtils import at.hannibal2.skyhanni.utils.fromJson import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import com.google.gson.JsonPrimitive import kotlinx.coroutines.launch import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.milliseconds @@ -171,4 +173,11 @@ class MiningEventTracker { MiningEventDisplay.updateData(miningEventData.data) } } + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.transform(29, "mining.miningEvent.showType") { element -> + if (element.asString == "BOTH") JsonPrimitive("ALL") else element + } + } } -- cgit