summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-06-22 13:00:47 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-06-22 13:00:47 +0200
commit3e7aa9855489888283b6c53ce14002fe38d04dbe (patch)
tree9300e8176ac357f0c5637209196dd65f4c287d5c /src/main/java/at/hannibal2/skyhanni/data
parent47ac0f99f9d482c3ab3baf794d9ebf03fbee3d6b (diff)
downloadskyhanni-3e7aa9855489888283b6c53ce14002fe38d04dbe.tar.gz
skyhanni-3e7aa9855489888283b6c53ce14002fe38d04dbe.tar.bz2
skyhanni-3e7aa9855489888283b6c53ce14002fe38d04dbe.zip
better error handling
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/MayorElection.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt18
4 files changed, 11 insertions, 23 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt
index 30f88f48e..b5a2d2b92 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt
@@ -21,8 +21,6 @@ class EntityMovementData {
}
}
- var tick = 0
-
@SubscribeEvent
fun onTick(event: TickEvent.ClientTickEvent) {
if (!LorenzUtils.inSkyBlock) return
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MayorElection.kt b/src/main/java/at/hannibal2/skyhanni/data/MayorElection.kt
index ddd208db1..7c4cfd7c1 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/MayorElection.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/MayorElection.kt
@@ -1,11 +1,10 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.jsonobjects.MayorJson
-import com.google.gson.GsonBuilder
-import io.github.moulberry.moulconfig.observer.PropertyTypeAdapterFactory
import io.github.moulberry.notenoughupdates.util.SkyBlockTime
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -17,10 +16,6 @@ class MayorElection {
private var tick = 0
private var lastUpdate = 0L
- private val gson = GsonBuilder().setPrettyPrinting()
- .registerTypeAdapterFactory(PropertyTypeAdapterFactory())
- .create()
-
companion object {
var rawMayorData: MayorJson? = null
var candidates = mapOf<Int, MayorJson.Candidate>()
@@ -52,7 +47,7 @@ class MayorElection {
SkyHanniMod.coroutineScope.launch {
val url = "https://api.hypixel.net/resources/skyblock/election"
val jsonObject = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) }
- rawMayorData = gson.fromJson(jsonObject, MayorJson::class.java)
+ rawMayorData = ConfigManager.gson.fromJson(jsonObject, MayorJson::class.java)
val data = rawMayorData ?: return@launch
val map = mutableMapOf<Int, MayorJson.Candidate>()
map put data.mayor.election.getPairs()
diff --git a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt
index 2dc65f358..e1d6aa933 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt
@@ -1,10 +1,9 @@
package at.hannibal2.skyhanni.data.repo
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
-import com.google.gson.Gson
-import com.google.gson.GsonBuilder
import com.google.gson.JsonObject
import net.minecraft.client.Minecraft
import org.apache.commons.io.FileUtils
@@ -15,7 +14,7 @@ import java.util.concurrent.CompletableFuture
import java.util.concurrent.atomic.AtomicBoolean
class RepoManager(private val configLocation: File) {
- val gson: Gson = GsonBuilder().setPrettyPrinting().create()
+ private val gson get() = ConfigManager.gson
private var latestRepoCommit: String? = null
private val repoLocation: File = File(configLocation, "repo")
diff --git a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt
index 3e67adcac..9719c70ff 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt
@@ -79,17 +79,13 @@ object RepoUtils {
fun <T> getConstant(repo: File, constant: String, gson: Gson, clazz: Class<T>?): T? {
if (repo.exists()) {
val jsonFile = File(repo, "constants/$constant.json")
- try {
- BufferedReader(
- InputStreamReader(
- FileInputStream(jsonFile),
- StandardCharsets.UTF_8
- )
- ).use { reader ->
- return gson.fromJson(reader, clazz)
- }
- } catch (e: Exception) {
- return null
+ BufferedReader(
+ InputStreamReader(
+ FileInputStream(jsonFile),
+ StandardCharsets.UTF_8
+ )
+ ).use { reader ->
+ return gson.fromJson(reader, clazz)
}
}
return null