From 1275efbfd79b59661920baca0a2ae852da907d7e Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Thu, 9 May 2024 12:04:22 +0200 Subject: Fix: Mining Event Error Spam (#1746) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../mining/eventtracker/MiningEventDisplay.kt | 22 +++++++--- .../mining/eventtracker/MiningEventTracker.kt | 50 ++++++++++++++++++++-- .../skyhanni/test/command/ErrorManager.kt | 4 +- .../java/at/hannibal2/skyhanni/utils/APIUtil.kt | 29 +++++++------ 4 files changed, 82 insertions(+), 23 deletions(-) (limited to 'src/main/java/at') 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 dcb244009..6a65b6302 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 @@ -14,7 +14,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object MiningEventDisplay { private val config get() = SkyHanniMod.feature.mining.miningEvent - private var display = mutableListOf() + private var display = listOf() private val islandEventData: MutableMap = mutableMapOf() @@ -31,11 +31,19 @@ object MiningEventDisplay { } private fun updateDisplay() { - display.clear() + display = emptyList() updateEvents() } private fun updateEvents() { + val list = mutableListOf() + + if (MiningEventTracker.apiError) { + val count = MiningEventTracker.apiErrorCount + list.add("§cMining Event API Error! ($count)") + list.add("§cSwap servers to try again!") + } + islandEventData.forEach { (islandType, eventDetails) -> val shouldShow = when (config.showType) { MiningEventConfig.ShowType.DWARVEN -> islandType == IslandType.DWARVEN_MINES @@ -53,15 +61,15 @@ object MiningEventDisplay { if (shouldShow) { val upcomingEvents = formatUpcomingEvents(eventDetails.islandEvents, eventDetails.lastEvent) - display.add("§a${islandType.displayName}§8: $upcomingEvents") + list.add("§a${islandType.displayName}§8: $upcomingEvents") } } + display = list } private fun formatUpcomingEvents(events: List, lastEvent: MiningEventType?): String { val upcoming = events.filter { !it.endsAt.asTimeMark().isInPast() } - .map { if (it.isDoubleEvent) "${it.event} §8-> ${it.event}" else it.event.toString() } - .toMutableList() + .map { if (it.isDoubleEvent) "${it.event} §8-> ${it.event}" else it.event.toString() }.toMutableList() if (upcoming.isEmpty()) upcoming.add("§7???") if (config.passedEvents && upcoming.size < 4) lastEvent?.let { upcoming.add(0, it.toPastString()) } @@ -85,8 +93,8 @@ object MiningEventDisplay { } } - private fun shouldDisplay() = LorenzUtils.inSkyBlock && config.enabled && !ReminderUtils.isBusy() && - !(!config.outsideMining && !LorenzUtils.inAdvancedMiningIsland()) + 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 bd1d284bd..b0c870fa2 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 @@ -7,11 +7,13 @@ import at.hannibal2.skyhanni.data.BossbarData import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.BossbarUpdateEvent +import at.hannibal2.skyhanni.events.IslandChangeEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.SecondPassedEvent import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.APIUtil +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.SimpleTimeMark @@ -22,6 +24,7 @@ import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import com.google.gson.JsonPrimitive import kotlinx.coroutines.launch import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.io.IOException import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds @@ -38,6 +41,7 @@ class MiningEventTracker { "bossbar.active", "§e§lEVENT (?.+) §e§lACTIVE IN (?.+) §e§lfor §a§l(?