aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2023-04-19 15:34:43 +0200
committerGitHub <noreply@github.com>2023-04-19 15:34:43 +0200
commitee84a09894c450c35ac619cd3870b3887059985d (patch)
tree67a3754e86c4f720a6d98370c6289c520e4ce5b9 /src/main/java/at/hannibal2/skyhanni/data
parent8161cf66231cec9a18a4db74e5334065f23f9073 (diff)
downloadSkyHanni-ee84a09894c450c35ac619cd3870b3887059985d.tar.gz
SkyHanni-ee84a09894c450c35ac619cd3870b3887059985d.tar.bz2
SkyHanni-ee84a09894c450c35ac619cd3870b3887059985d.zip
composter fix (#50)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/MayorElection.kt (renamed from src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt)19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt7
2 files changed, 10 insertions, 16 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt b/src/main/java/at/hannibal2/skyhanni/data/MayorElection.kt
index 70f30a021..04da1e777 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/MayorElection.kt
@@ -3,8 +3,7 @@ package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.MayorData
-import at.hannibal2.skyhanni.utils.MayorData.Candidate
+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
@@ -14,7 +13,7 @@ import kotlinx.coroutines.withContext
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
-class MayorElectionData {
+class MayorElection {
private var tick = 0
private var lastUpdate = 0L
@@ -23,9 +22,9 @@ class MayorElectionData {
.create()
companion object {
- var rawMayorData: MayorData? = null
- var candidates = mapOf<Int, Candidate>()
- var currentCandidate: Candidate? = null
+ var rawMayorData: MayorJson? = null
+ var candidates = mapOf<Int, MayorJson.Candidate>()
+ var currentCandidate: MayorJson.Candidate? = null
fun isPerkActive(mayor: String, perk: String): Boolean {
return currentCandidate?.let { currentCandidate ->
@@ -53,9 +52,9 @@ class MayorElectionData {
SkyHanniMod.coroutineScope.launch {
val url = "https://api.hypixel.net/resources/skyblock/election"
val jsonObject = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) }
- rawMayorData = gson.fromJson(jsonObject, MayorData::class.java)
+ rawMayorData = gson.fromJson(jsonObject, MayorJson::class.java)
val data = rawMayorData ?: return@launch
- val map = mutableMapOf<Int, Candidate>()
+ val map = mutableMapOf<Int, MayorJson.Candidate>()
map put data.mayor.election.getPairs()
data.current?.let {
map put data.current.getPairs()
@@ -81,9 +80,9 @@ class MayorElectionData {
currentCandidate = candidates[currentYear]
}
- private fun MayorData.Election.getPairs() = year + 1 to candidates.bestCandidate()
+ private fun MayorJson.Election.getPairs() = year + 1 to candidates.bestCandidate()
- private fun List<MayorData.Candidate>.bestCandidate() = maxBy { it.votes }
+ private fun List<MayorJson.Candidate>.bestCandidate() = maxBy { it.votes }
private infix fun <K, V> MutableMap<K, V>.put(pairs: Pair<K, V>) {
this[pairs.first] = pairs.second
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 969b526cc..3e67adcac 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt
@@ -1,7 +1,6 @@
package at.hannibal2.skyhanni.data.repo
import com.google.gson.Gson
-import com.google.gson.JsonObject
import java.io.*
import java.nio.charset.StandardCharsets
import java.nio.file.Files
@@ -77,11 +76,7 @@ object RepoUtils {
return false
}
- fun getConstant(repoLocation: File, constant: String, gson: Gson): JsonObject? {
- return getConstant(repoLocation, constant, gson, JsonObject::class.java)
- }
-
- private fun <T> getConstant(repo: File, constant: String, gson: Gson, clazz: Class<T>?): T? {
+ fun <T> getConstant(repo: File, constant: String, gson: Gson, clazz: Class<T>?): T? {
if (repo.exists()) {
val jsonFile = File(repo, "constants/$constant.json")
try {