Skip to content

Commit

Permalink
misc: try-catch api stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Apr 14, 2023
1 parent 306d83e commit b9990b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod_name = EvergreenHUD
mod_id = evergreenhud
mod_version = 1.0.0-beta4
mod_version = 1.0.0-beta5

polyfrost.defaults.loom=0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ object PinkuluAPIManager {
fun initialize() {
EventManager.INSTANCE.register(this)
Multithreading.runAsync {
rawJson = NetworkUtils.getJsonElement("https://maps.pinkulu.com/trans-rights-are-human-rights.json").asJsonArray // so true bestie
try {
rawJson = NetworkUtils.getJsonElement("https://maps.pinkulu.com/trans-rights-are-human-rights.json").asJsonArray // so true bestie
} catch (e: Exception) {
e.printStackTrace()
}
}
}

Expand Down Expand Up @@ -47,10 +51,14 @@ object PinkuluAPIManager {

private fun checkCached() {
if (rawJson == null) return
val locraw = LocrawUtil.INSTANCE.locrawInfo
if (locraw == null || locraw.mapName.isNullOrBlank() || locraw.gameType == null) return
if (cachedMap == null || (cachedMap!!.get("name").asString != locraw.mapName && cachedMap!!.get("gameType").asString != locraw.gameType.serverName)) {
cachedMap = rawJson!!.firstOrNull { it.asJsonObject.get("name").asString == locraw.mapName && it.asJsonObject.get("gameType").asString == locraw.gameType.serverName }?.asJsonObject
try {
val locraw = LocrawUtil.INSTANCE.locrawInfo
if (locraw == null || locraw.mapName.isNullOrBlank() || locraw.gameType == null) return
if (cachedMap == null || (cachedMap!!.get("name").asString != locraw.mapName && cachedMap!!.get("gameType").asString != locraw.gameType.serverName)) {
cachedMap = rawJson!!.firstOrNull { it.asJsonObject.get("name").asString == locraw.mapName && it.asJsonObject.get("gameType").asString == locraw.gameType.serverName }?.asJsonObject
}
} catch (e: Exception) {
cachedMap = null
}
}
}

0 comments on commit b9990b0

Please sign in to comment.