aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt20
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/Mayors.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/jsonobjects/local/MayorJson.java70
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/jsonobjects/other/MayorJson.kt32
4 files changed, 46 insertions, 82 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt
index ef9850a4c..083e7bcdc 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt
@@ -4,11 +4,13 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.data.Mayor.Companion.setAssumeMayor
import at.hannibal2.skyhanni.data.Mayor.Companion.setAssumeMayorJson
-import at.hannibal2.skyhanni.data.jsonobjects.local.MayorJson
+import at.hannibal2.skyhanni.data.jsonobjects.other.MayorCandidate
+import at.hannibal2.skyhanni.data.jsonobjects.other.MayorElection
+import at.hannibal2.skyhanni.data.jsonobjects.other.MayorJson
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
-import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.CollectionUtils.put
import at.hannibal2.skyhanni.utils.ConditionalUtils.onToggle
@@ -17,6 +19,7 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark
import at.hannibal2.skyhanni.utils.SkyBlockTime
import at.hannibal2.skyhanni.utils.StringUtils.matches
+import at.hannibal2.skyhanni.utils.fromJson
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -43,7 +46,7 @@ object MayorAPI {
private var dispatcher = Dispatchers.IO
private var rawMayorData: MayorJson? = null
- var candidates = mapOf<Int, MayorJson.Candidate>()
+ var candidates = mapOf<Int, MayorCandidate>()
private set
var currentMayor: Mayor? = null
private set
@@ -66,9 +69,8 @@ object MayorAPI {
fun mayorNameWithColorCode(input: String) = mayorNameToColorCode(input) + input
@SubscribeEvent
- fun onTick(event: LorenzTickEvent) {
+ fun onSecondPassed(event: SecondPassedEvent) {
if (!LorenzUtils.onHypixel) return
-
if (event.repeatSeconds(2)) {
checkHypixelAPI()
getTimeTillNextMayor()
@@ -121,9 +123,9 @@ object MayorAPI {
SkyHanniMod.coroutineScope.launch {
val url = "https://api.hypixel.net/v2/resources/skyblock/election"
val jsonObject = withContext(dispatcher) { APIUtil.getJSONResponse(url) }
- rawMayorData = ConfigManager.gson.fromJson(jsonObject, MayorJson::class.java)
+ rawMayorData = ConfigManager.gson.fromJson<MayorJson>(jsonObject)
val data = rawMayorData ?: return@launch
- val map = mutableMapOf<Int, MayorJson.Candidate>()
+ val map = mutableMapOf<Int, MayorCandidate>()
map put data.mayor.election.getPairs()
data.current?.let {
map put data.current.getPairs()
@@ -133,9 +135,9 @@ object MayorAPI {
}
}
- private fun MayorJson.Election.getPairs() = year + 1 to candidates.bestCandidate()
+ private fun MayorElection.getPairs() = year + 1 to candidates.bestCandidate()
- private fun List<MayorJson.Candidate>.bestCandidate() = maxBy { it.votes }
+ private fun List<MayorCandidate>.bestCandidate() = maxBy { it.votes }
@SubscribeEvent
fun onConfigReload(event: ConfigLoadEvent) {
diff --git a/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt b/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt
index 1be03c363..1d851661b 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt
@@ -1,7 +1,7 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.data.MayorAPI.foxyExtraEventPattern
-import at.hannibal2.skyhanni.data.jsonobjects.local.MayorJson
+import at.hannibal2.skyhanni.data.jsonobjects.other.MayorPerk
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
@@ -43,7 +43,7 @@ enum class Mayor(
fun getMayorFromName(name: String): Mayor? = entries.firstOrNull { it.mayorName == name }
- fun setAssumeMayorJson(name: String, perksJson: ArrayList<MayorJson.Perk>): Mayor? {
+ fun setAssumeMayorJson(name: String, perksJson: List<MayorPerk>): Mayor? {
val mayor = getMayorFromName(name)
if (mayor == null) {
ErrorManager.logErrorStateWithData(
@@ -72,7 +72,7 @@ enum class Mayor(
}
}
- private fun MayorJson.Perk.renameIfFoxyExtraEventPerkFound(): String? {
+ private fun MayorPerk.renameIfFoxyExtraEventPerkFound(): String? {
val foxyExtraEventPairs = mapOf(
"Spooky Festival" to "Extra Event (Spooky)",
"Mining Fiesta" to "Extra Event (Mining)",
diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/local/MayorJson.java b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/local/MayorJson.java
deleted file mode 100644
index 6525e59d3..000000000
--- a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/local/MayorJson.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package at.hannibal2.skyhanni.data.jsonobjects.local;
-
-import com.google.gson.annotations.Expose;
-
-import java.util.ArrayList;
-
-public class MayorJson {
- @Expose
- public boolean success;
- @Expose
- public long lastUpdated;
- @Expose
- public Mayor mayor;
- @Expose
- public Election current;
-
- public class Candidate {
- @Expose
- public String key;
- @Expose
- public String name;
- @Expose
- public ArrayList<Perk> perks;
- @Expose
- public int votes;
-
- @Override
- public String toString() {
- return "Candidate{" +
- "key='" + key + '\'' +
- ", name='" + name + '\'' +
- ", perks=" + perks +
- ", votes=" + votes +
- '}';
- }
- }
-
- public class Election {
- @Expose
- public int year;
- @Expose
- public ArrayList<Candidate> candidates;
- }
-
- public class Mayor {
- @Expose
- public String key;
- @Expose
- public String name;
- @Expose
- public ArrayList<Perk> perks;
- @Expose
- public Election election;
- }
-
- public static class Perk {
- @Expose
- public String name;
- @Expose
- public String description;
-
- @Override
- public String toString() {
- return "Perk{" +
- "name='" + name + '\'' +
- ", description='" + description + '\'' +
- '}';
- }
- }
-}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/other/MayorJson.kt b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/other/MayorJson.kt
new file mode 100644
index 000000000..d8f0df279
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/other/MayorJson.kt
@@ -0,0 +1,32 @@
+package at.hannibal2.skyhanni.data.jsonobjects.other
+
+import com.google.gson.annotations.Expose
+
+data class MayorJson(
+ @Expose val mayor: MayorInfo,
+ @Expose val current: MayorElection?,
+)
+
+data class MayorInfo(
+ @Expose val key: String,
+ @Expose val name: String,
+ @Expose val perks: List<MayorPerk>,
+ @Expose val election: MayorElection,
+)
+
+data class MayorElection(
+ @Expose val year: Int,
+ @Expose val candidates: List<MayorCandidate>,
+)
+
+data class MayorCandidate(
+ @Expose val key: String,
+ @Expose val name: String,
+ @Expose val perks: List<MayorPerk>,
+ @Expose val votes: Int,
+)
+
+data class MayorPerk(
+ @Expose val name: String,
+ @Expose val description: String,
+)