aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-10-21 22:56:53 +1100
committerGitHub <noreply@github.com>2023-10-21 13:56:53 +0200
commit526365859a27d54b7ea5c07c08b301650c15ea0e (patch)
treeddf772f564d85caf3dbe73c66c032affdf69281f /src/main/java/at/hannibal2/skyhanni/data
parenta98927303854058ad2d7a0d8bb88265c54139614 (diff)
downloadskyhanni-526365859a27d54b7ea5c07c08b301650c15ea0e.tar.gz
skyhanni-526365859a27d54b7ea5c07c08b301650c15ea0e.tar.bz2
skyhanni-526365859a27d54b7ea5c07c08b301650c15ea0e.zip
Backend: Serialise all constants and add repo error messages and status (#605)
Backend: Serialise all constants and add repo error messages and status #605
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/BingoAPI.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt62
5 files changed, 69 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/BingoAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/BingoAPI.kt
index 857b73d3f..5b32a1d15 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/BingoAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/BingoAPI.kt
@@ -1,7 +1,7 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
-import at.hannibal2.skyhanni.utils.jsonobjects.BingoRanks
+import at.hannibal2.skyhanni.utils.jsonobjects.BingoRanksJson
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object BingoAPI {
@@ -9,7 +9,7 @@ object BingoAPI {
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
- ranks = event.getConstant<BingoRanks>("BingoRanks").ranks
+ ranks = event.getConstant<BingoRanksJson>("BingoRanks").ranks
}
fun getRank(text: String) = ranks.entries.find { text.contains(it.key) }?.value
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
index 02d003398..0b20821f8 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
@@ -41,7 +41,7 @@ object GardenCropMilestones {
CropMilestoneUpdateEvent().postAndCatch()
}
- private var cropMilestoneData: Map<CropType, List<Int>>? = null
+ private var cropMilestoneData: Map<CropType, List<Int>> = emptyMap()
val cropCounter: MutableMap<CropType, Long>? get() = GardenAPI.config?.cropCounter
@@ -53,14 +53,14 @@ object GardenCropMilestones {
}
fun CropType.isMaxed(): Boolean {
- val maxValue = cropMilestoneData?.get(this)?.sum() ?: 1_000_000_000 // 1 bil for now
+ val maxValue = cropMilestoneData[this]?.sum() ?: 1_000_000_000 // 1 bil for now
return getCounter() >= maxValue
}
fun getTierForCropCount(count: Long, crop: CropType): Int {
var tier = 0
var totalCrops = 0L
- val cropMilestone = cropMilestoneData?.get(crop) ?: return 0
+ val cropMilestone = cropMilestoneData[crop] ?: return 0
for (tierCrops in cropMilestone) {
totalCrops += tierCrops
if (totalCrops > count) {
@@ -72,12 +72,12 @@ object GardenCropMilestones {
return tier
}
- fun getMaxTier() = cropMilestoneData?.values?.firstOrNull()?.size ?: 0
+ fun getMaxTier() = cropMilestoneData.values.firstOrNull()?.size ?: 0
fun getCropsForTier(requestedTier: Int, crop: CropType): Long {
var totalCrops = 0L
var tier = 0
- val cropMilestone = cropMilestoneData?.get(crop) ?: return 0
+ val cropMilestone = cropMilestoneData[crop] ?: return 0
for (tierCrops in cropMilestone) {
totalCrops += tierCrops
tier++
@@ -99,7 +99,6 @@ object GardenCropMilestones {
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
- val data = event.getConstant<GardenJson>("Garden")
- cropMilestoneData = data.crop_milestones
+ cropMilestoneData = event.getConstant<GardenJson>("Garden").crop_milestones
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
index e8ca2ab3b..1d34b7202 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.data
+import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.HypixelJoinEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
@@ -102,6 +103,7 @@ class HypixelData {
checkHypixel()
if (LorenzUtils.onHypixel) {
HypixelJoinEvent().postAndCatch()
+ SkyHanniMod.repo.displayRepoStatus(true)
}
}
if (!LorenzUtils.onHypixel) return
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
index 3e5d5f321..35e664cd7 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
@@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.SackChangeEvent
import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager
+import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager.getFilletValue
import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity
import at.hannibal2.skyhanni.features.inventory.SackDisplay
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
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 363cbfd7c..593d9a652 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt
@@ -27,6 +27,20 @@ class RepoManager(private val configLocation: File) {
private val repoLocation: File = File(configLocation, "repo")
private var error = false
+ companion object {
+ val successfulConstants = mutableListOf<String>()
+ val unsuccessfulConstants = mutableListOf<String>()
+
+ private var lastConstant: String? = null
+
+ fun setlastConstant(constant: String) {
+ lastConstant?.let {
+ successfulConstants.add(it)
+ }
+ lastConstant = constant
+ }
+ }
+
fun loadRepoInformation() {
atomicShouldManuallyReload.set(true)
if (SkyHanniMod.feature.dev.repoAutoUpdate) {
@@ -66,11 +80,14 @@ class RepoManager(private val configLocation: File) {
val file = File(configLocation, "repo")
if (file.exists() && currentCommitJSON != null && currentCommitJSON["sha"].asString == latestRepoCommit
) {
- if (command) {
- LorenzUtils.chat("§e[SkyHanni] §7The repo is already up to date!")
- atomicShouldManuallyReload.set(false)
+ if (unsuccessfulConstants.isEmpty()) {
+
+ if (command) {
+ LorenzUtils.chat("§e[SkyHanni] §7The repo is already up to date!")
+ atomicShouldManuallyReload.set(false)
+ }
+ return@supplyAsync false
}
- return@supplyAsync false
}
RepoUtils.recursiveDelete(repoLocation)
repoLocation.mkdirs()
@@ -126,8 +143,16 @@ class RepoManager(private val configLocation: File) {
ErrorManager.resetCache()
Minecraft.getMinecraft().addScheduledTask {
error = false
+ successfulConstants.clear()
+ unsuccessfulConstants.clear()
+ lastConstant = null
+
RepositoryReloadEvent(repoLocation, gson).postAndCatchAndBlock(ignoreErrorCache = true) {
error = true
+ lastConstant?.let {
+ unsuccessfulConstants.add(it)
+ }
+ lastConstant = null
}
comp.complete(null)
if (answerMessage.isNotEmpty() && !error) {
@@ -138,11 +163,40 @@ class RepoManager(private val configLocation: File) {
"§e[SkyHanni] Error with the repo detected, try /shupdaterepo to fix it!",
"shupdaterepo"
)
+ if (unsuccessfulConstants.isEmpty()) {
+ unsuccessfulConstants.add("All Constants")
+ }
}
}
return comp
}
+ fun displayRepoStatus(joinEvent: Boolean) {
+ if (joinEvent) {
+ if (unsuccessfulConstants.isNotEmpty()) {
+ LorenzUtils.chat("§c[SkyHanni] §7Repo Issue! Some features may not work. Please report this error on the Discord!")
+ LorenzUtils.chat("§7Repo Auto Update Value: §c${SkyHanniMod.feature.dev.repoAutoUpdate}")
+ LorenzUtils.chat("§7If you have Repo Auto Update turned off, please try turning that on.\n§cUnsuccessful Constants §7(${unsuccessfulConstants.size}):")
+ for (constant in unsuccessfulConstants) {
+ LorenzUtils.chat(" §e- §7$constant")
+ }
+ }
+ return
+ }
+ if (unsuccessfulConstants.isEmpty() && successfulConstants.isNotEmpty()) {
+ LorenzUtils.chat("§a[SkyHanni] Repo working fine!")
+ return
+ }
+ if (successfulConstants.isNotEmpty()) LorenzUtils.chat("§a[SkyHanni] Successful Constants §7(${successfulConstants.size}):")
+ for (constant in successfulConstants) {
+ LorenzUtils.chat(" §a- §7$constant")
+ }
+ LorenzUtils.chat("§c[SkyHanni] Unsuccessful Constants §7(${unsuccessfulConstants.size}):")
+ for (constant in unsuccessfulConstants) {
+ LorenzUtils.chat(" §e- §7$constant")
+ }
+ }
+
/**
* Parses a file in to a JsonObject.
*/