aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java2
-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
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/RepositoryReloadEvent.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt37
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/GardenJson.java14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/MayorJson.java (renamed from src/main/java/at/hannibal2/skyhanni/utils/MayorData.java)4
8 files changed, 59 insertions, 39 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index 734e4921a..76633751e 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -145,7 +145,7 @@ public class SkyHanniMod {
loadModule(new GuiEditManager());
loadModule(UpdateManager.INSTANCE);
loadModule(new CropAccessoryData());
- loadModule(new MayorElectionData());
+ loadModule(new MayorElection());
loadModule(new GardenComposterUpgradesData());
// APIs
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 {
diff --git a/src/main/java/at/hannibal2/skyhanni/events/RepositoryReloadEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/RepositoryReloadEvent.kt
index 06fbc93d6..5cfd59aa1 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/RepositoryReloadEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/RepositoryReloadEvent.kt
@@ -5,8 +5,9 @@ import com.google.gson.Gson
import com.google.gson.JsonObject
import java.io.File
-class RepositoryReloadEvent(private val repoLocation: File, val gson: Gson): LorenzEvent() {
- fun getConstant(constant: String): JsonObject? {
- return RepoUtils.getConstant(repoLocation, constant, gson)
- }
+class RepositoryReloadEvent(val repoLocation: File, val gson: Gson): LorenzEvent() {
+ fun getConstant(constant: String) = getConstant<JsonObject>(constant)
+
+ inline fun <reified T : Any> getConstant(constant: String) =
+ RepoUtils.getConstant(repoLocation, constant, gson, T::class.java)
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
index 0e0271b52..adbe90245 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
@@ -17,12 +17,14 @@ import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.jsonobjects.GardenJson
import at.hannibal2.skyhanni.utils.renderables.Renderable
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
+import java.util.*
import kotlin.math.ceil
import kotlin.time.Duration
import kotlin.time.DurationUnit
@@ -64,6 +66,8 @@ class ComposterOverlay {
var inInventory = false
}
+ var garden: GardenJson? = null
+
@SubscribeEvent
fun onInventoryClose(event: GuiContainerEvent.CloseWindowEvent) {
inInventory = false
@@ -128,6 +132,12 @@ class ComposterOverlay {
}
private fun update() {
+ if (organicMatterFactors.isEmpty()) {
+ organicMatterDisplay =
+ Collections.singletonList(listOf("§cSkyHanni composter error:", "§cRepo data not loaded!"))
+ return
+ }
+
if (inComposter) {
organicMatterDisplay = drawOrganicMatterDisplay()
fuelExtraDisplay = drawFuelExtraDisplay()
@@ -380,28 +390,29 @@ class ComposterOverlay {
}
@SubscribeEvent
+ fun onRepoReload(event: io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent) {
+ updateOrganicMatterFactors()
+ }
+
+ @SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
- try {
- val garden = event.getConstant("Garden")!!
+ garden = event.getConstant<GardenJson>("Garden")!!
+ updateOrganicMatterFactors()
+ }
- val baseValues = mutableMapOf<String, Double>()
- for ((name, value) in garden["organic_matter"].asJsonObject.entrySet()) {
- baseValues[name] = value.asDouble
- }
- organicMatterFactors = updateOrganicMatterFactors(baseValues)
+ private fun updateOrganicMatterFactors() {
+ try {
+ val garden = this.garden ?: return
+ organicMatterFactors = updateOrganicMatterFactors(garden.organic_matter)
+ fuelFactors = garden.fuel
- val fuelMap = mutableMapOf<String, Double>()
- for ((name, value) in garden["fuel"].asJsonObject.entrySet()) {
- fuelMap[name] = value.asDouble
- }
- fuelFactors = fuelMap
} catch (e: Exception) {
e.printStackTrace()
LorenzUtils.error("error in RepositoryReloadEvent")
}
}
- private fun updateOrganicMatterFactors(baseValues: MutableMap<String, Double>): Map<String, Double> {
+ private fun updateOrganicMatterFactors(baseValues: Map<String, Double>): Map<String, Double> {
val map = mutableMapOf<String, Double>()
for ((internalName, _) in NotEnoughUpdates.INSTANCE.manager.itemInformation) {
if (internalName.endsWith("_BOOTS")) continue
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
index 7145c77d2..7b644578a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
@@ -5,7 +5,7 @@ import at.hannibal2.skyhanni.data.ClickType
import at.hannibal2.skyhanni.data.GardenCropMilestones
import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter
import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.setCounter
-import at.hannibal2.skyhanni.data.MayorElectionData
+import at.hannibal2.skyhanni.data.MayorElection
import at.hannibal2.skyhanni.data.TitleUtils
import at.hannibal2.skyhanni.events.*
import at.hannibal2.skyhanni.features.garden.CropType
@@ -151,8 +151,8 @@ class GardenCropMilestoneDisplay {
private fun finneganPerkActive(): Boolean {
val forcefullyEnabledAlwaysFinnegan = config.forcefullyEnabledAlwaysFinnegan
- val perkActive = MayorElectionData.isPerkActive("Finnegan", "Farming Simulator")
- MayorElectionData.currentCandidate?.let {
+ val perkActive = MayorElection.isPerkActive("Finnegan", "Farming Simulator")
+ MayorElection.currentCandidate?.let {
}
return forcefullyEnabledAlwaysFinnegan || perkActive
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/GardenJson.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/GardenJson.java
new file mode 100644
index 000000000..0a5a76c43
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/GardenJson.java
@@ -0,0 +1,14 @@
+package at.hannibal2.skyhanni.utils.jsonobjects;
+
+import com.google.gson.annotations.Expose;
+
+import java.util.Map;
+
+public class GardenJson {
+
+ @Expose
+ public Map<String, Double> organic_matter;
+
+ @Expose
+ public Map<String, Double> fuel;
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MayorData.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/MayorJson.java
index 1c73572d4..813020bc1 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/MayorData.java
+++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/MayorJson.java
@@ -1,10 +1,10 @@
-package at.hannibal2.skyhanni.utils;
+package at.hannibal2.skyhanni.utils.jsonobjects;
import com.google.gson.annotations.Expose;
import java.util.ArrayList;
-public class MayorData {
+public class MayorJson {
@Expose
public boolean success;
@Expose