aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-05-09 12:04:22 +0200
committerGitHub <noreply@github.com>2024-05-09 12:04:22 +0200
commit1275efbfd79b59661920baca0a2ae852da907d7e (patch)
treefc53a786b4000075575737680f88ffccd474495b /src/main/java/at/hannibal2/skyhanni
parente0c95e803d0b5269333dae739d14067305f4baa3 (diff)
downloadskyhanni-1275efbfd79b59661920baca0a2ae852da907d7e.tar.gz
skyhanni-1275efbfd79b59661920baca0a2ae852da907d7e.tar.bz2
skyhanni-1275efbfd79b59661920baca0a2ae852da907d7e.zip
Fix: Mining Event Error Spam (#1746)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventDisplay.kt22
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/eventtracker/MiningEventTracker.kt50
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt29
4 files changed, 82 insertions, 23 deletions
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<String>()
+ private var display = listOf<String>()
private val islandEventData: MutableMap<IslandType, MiningIslandEventInfo> = mutableMapOf()
@@ -31,11 +31,19 @@ object MiningEventDisplay {
}
private fun updateDisplay() {
- display.clear()
+ display = emptyList()
updateEvents()
}
private fun updateEvents() {
+ val list = mutableListOf<String>()
+
+ 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<RunningEventType>, 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<RunningEventType>, 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 (?<event>.+) §e§lACTIVE IN (?<area>.+) §e§lfor §a§l(?<time>\\S+)§r"
)
+
// TODO add test messages
private val eventStartedPattern by patternGroup.pattern(
"started",
@@ -55,6 +59,12 @@ class MiningEventTracker {
private var canRequestAt = SimpleTimeMark.farPast()
+ companion object {
+ var apiErrorCount = 0
+
+ val apiError get() = apiErrorCount > 0
+ }
+
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
eventEndTime = SimpleTimeMark.farPast()
@@ -136,13 +146,28 @@ class MiningEventTracker {
LorenzUtils.getPlayerUuid()
)
val miningEventJson = ConfigManager.gson.toJson(miningEventData)
+
+ if (apiError) {
+ ChatUtils.debug("blocked sending mining event data: api error")
+ return
+ }
SkyHanniMod.coroutineScope.launch {
sendData(miningEventJson)
}
}
private fun sendData(json: String) {
- val response = APIUtil.postJSON("https://api.soopy.dev/skyblock/chevents/set", json)
+ val response = try {
+ APIUtil.postJSON("https://api.soopy.dev/skyblock/chevents/set", json)
+ } catch (e: IOException) {
+ if (LorenzUtils.debug) {
+ ErrorManager.logErrorWithData(
+ e, "Sending mining event data was unsuccessful",
+ "sentData" to json
+ )
+ }
+ return
+ }
if (!response.success) return
val formattedResponse = ConfigManager.gson.fromJson<MiningEventDataReceive>(response.data)
@@ -156,20 +181,39 @@ class MiningEventTracker {
}
}
+ @SubscribeEvent
+ fun onIslandChange(event: IslandChangeEvent) {
+ if (apiError) {
+ canRequestAt = SimpleTimeMark.now()
+ }
+ }
+
private fun fetchData() {
canRequestAt = SimpleTimeMark.now() + defaultCooldown
SkyHanniMod.coroutineScope.launch {
- val data = APIUtil.getJSONResponse("https://api.soopy.dev/skyblock/chevents/get")
+ val data = try {
+ APIUtil.getJSONResponse("https://api.soopy.dev/skyblock/chevents/get")
+ } catch (e: Exception) {
+ apiErrorCount++
+ canRequestAt = SimpleTimeMark.now() + 20.minutes
+ if (LorenzUtils.debug) {
+ ErrorManager.logErrorWithData(
+ e, "Receiving mining event data was unsuccessful",
+ )
+ }
+ return@launch
+ }
val miningEventData = ConfigManager.gson.fromJson(data, MiningEventDataReceive::class.java)
if (!miningEventData.success) {
ErrorManager.logErrorWithData(
- Exception("PostFailure"), "Sending mining event data was unsuccessful",
+ Exception("PostFailure"), "Receiving mining event data was unsuccessful",
"cause" to miningEventData.cause,
"recievedData" to data
)
return@launch
}
+ apiErrorCount = 0
canRequestAt = SimpleTimeMark.now() + miningEventData.data.updateIn.milliseconds
diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt
index 95507c2b2..54fe13054 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt
@@ -58,7 +58,9 @@ object ErrorManager {
fun skyHanniError(message: String, vararg extraData: Pair<String, Any?>): Nothing {
val exception = IllegalStateException(message)
- logErrorWithData(exception, message, extraData = extraData)
+ println("silent SkyHanni error:")
+ println("message: '$message'")
+ println("extraData: \n${buildExtraDataString(extraData)}")
throw exception
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
index 46a0d7b57..bf2384373 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
@@ -65,6 +65,8 @@ object APIUtil {
try {
return parser.parse(retSrc)
} catch (e: JsonSyntaxException) {
+ val name = e.javaClass.name
+ val message = "$name: ${e.message}"
if (e.message?.contains("Use JsonReader.setLenient(true)") == true) {
println("MalformedJsonException: Use JsonReader.setLenient(true)")
println(" - getJSONResponse: '$urlString'")
@@ -78,15 +80,17 @@ object APIUtil {
}
)
}
- ErrorManager.logErrorWithData(
- e, "502 Bad Gateway",
+ ErrorManager.skyHanniError(
+ "SkyHanni Connection Error",
+ "error message" to "$message(502 Bad Gateway)",
"apiName" to apiName,
"urlString" to urlString,
"returnedData" to retSrc
)
} else {
- ErrorManager.logErrorWithData(
- e, "$apiName error",
+ ErrorManager.skyHanniError(
+ "SkyHanni Connection Error",
+ "error message" to message,
"apiName" to apiName,
"urlString" to urlString,
"returnedData" to retSrc
@@ -95,16 +99,17 @@ object APIUtil {
}
}
}
- } catch (throwable: Throwable) {
+ } catch (e: Throwable) {
if (silentError) {
- throw throwable
- } else {
- ErrorManager.logErrorWithData(
- throwable, "$apiName error for url: '$urlString'",
- "apiName" to apiName,
- "urlString" to urlString,
- )
+ throw e
}
+ val name = e.javaClass.name
+ val message = "$name: ${e.message}"
+ ErrorManager.skyHanniError(
+ "SkyHanni Connection Error",
+ "error message" to message,
+ "urlString" to urlString,
+ )
} finally {
client.close()
}