diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/other/EliteBotJson.kt b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/other/EliteBotJson.kt index 3e3206cd5b09..0ab14948bf14 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/other/EliteBotJson.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/other/EliteBotJson.kt @@ -46,7 +46,14 @@ data class PestWeightData( @Expose @SerializedName("values") val pestWeights: Map> ) +data class EliteCollectionGraphEntry( + @Expose val timestamp: Long, + @Expose val crops: Map, +) + data class EliteSkillGraphEntry( @Expose val timestamp: Long, @Expose val skills: Map, ) + + diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingCollectionDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingCollectionDisplay.kt index 21ee8dd0b189..b151bc1b2496 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingCollectionDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingCollectionDisplay.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.config.features.garden.EliteFarmingCollectionConfig.CropDisplay import at.hannibal2.skyhanni.data.ClickType +import at.hannibal2.skyhanni.data.jsonobjects.other.EliteCollectionGraphEntry import at.hannibal2.skyhanni.data.jsonobjects.other.EliteLeaderboard import at.hannibal2.skyhanni.data.jsonobjects.repo.EliteAPISettingsJson import at.hannibal2.skyhanni.events.BlockClickEvent @@ -35,7 +36,6 @@ import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonWriter import kotlinx.coroutines.launch import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.network.FMLNetworkEvent import java.util.UUID import kotlin.time.Duration.Companion.minutes @@ -72,6 +72,8 @@ object FarmingCollectionDisplay { private var currentCollections = mutableMapOf() private var lastFetchedCrop: CropType? = null + private var hasCollectionBeenFetched = false + private var lastBrokenCrop: CropType? get() = SkyHanniMod.feature.storage.lastCropBroken set(value) { @@ -163,6 +165,7 @@ object FarmingCollectionDisplay { } private fun resetData() { + hasCollectionBeenFetched = false lastLeaderboardFetch = SimpleTimeMark.farPast() collectionRanks.clear() collectionPlacements.clear() @@ -251,6 +254,10 @@ object FarmingCollectionDisplay { lastFetchedCrop = crop currentCollections[crop] = data.amount + if (!hasCollectionBeenFetched && data.amount == 0L) { + hasCollectionBeenFetched = true + getCurrentCollection() + } } catch (e: Exception) { ErrorManager.logErrorWithData( e, @@ -264,17 +271,37 @@ object FarmingCollectionDisplay { } } + private fun getCurrentCollection() { + if (profileID == null) return + val url = + "https://api.elitebot.dev/Graph/${LorenzUtils.getPlayerUuid()}/${profileID!!.toDashlessUUID()}/crops?days=1" + val response = APIUtil.getJSONResponseAsElement(url) + + try { + val data = eliteCollectionApiGson.fromJson>(response) + + data.sortBy { it.timestamp } + currentCollections = data.lastOrNull()?.crops?.toMutableMap() ?: mutableMapOf() + + } catch (e: Exception) { + ErrorManager.logErrorWithData( + e, + "Error loading user farming collection\n" + + "§eLoading the farming collection data from elitebot.dev failed!\n" + + "§eYou can re-enter the garden to try to fix the problem.\n" + + "§cIf this message repeats, please report it on Discord!\n", + "url" to url, + "apiResponse" to response, + ) + } + } + private fun getEliteBotLeaderboardForCrop(crop: CropType) = when (crop) { CropType.NETHER_WART -> "netherwart" CropType.SUGAR_CANE -> "sugarcane" else -> crop.simpleName } - @SubscribeEvent - fun playerLogout(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) { - SkyHanniMod.feature.storage.lastCropBroken = lastBrokenCrop - } - private fun isEnabled() = config.display && LorenzUtils.inSkyBlock && (GardenAPI.inGarden() || config.showOutsideGarden) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillRankDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillRankDisplay.kt index 4ece4d134e4d..da23b14a1c6f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillRankDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillRankDisplay.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.config.features.skillprogress.EliteSkillsDisplayConfig.SkillDisplay import at.hannibal2.skyhanni.data.SkillExperience import at.hannibal2.skyhanni.data.jsonobjects.other.EliteLeaderboard +import at.hannibal2.skyhanni.data.jsonobjects.other.EliteSkillGraphEntry import at.hannibal2.skyhanni.data.jsonobjects.repo.EliteAPISettingsJson import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent @@ -30,7 +31,6 @@ import at.hannibal2.skyhanni.utils.fromJson import at.hannibal2.skyhanni.utils.renderables.Renderable import kotlinx.coroutines.launch import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.network.FMLNetworkEvent import java.util.UUID import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds @@ -68,6 +68,7 @@ object SkillRankDisplay { private var lastSkillFetched: String? = null private var lastLeaderboardFetch = SimpleTimeMark.farPast() private var lastXPGained = SimpleTimeMark.farPast() + private var hasSkillsBeenFetched = false private var display = emptyList() @@ -145,6 +146,7 @@ object SkillRankDisplay { } private fun resetData() { + hasSkillsBeenFetched = false lastLeaderboardFetch = SimpleTimeMark.farPast() skillRanks.clear() skillPlacements.clear() @@ -233,6 +235,10 @@ object SkillRankDisplay { lastSkillFetched = skill currentSkills[skill] = data.amount + if (!hasSkillsBeenFetched && data.amount == 0L) { + hasSkillsBeenFetched = true + getCurrentSkills() + } } catch (e: Exception) { ErrorManager.logErrorWithData( e, @@ -246,9 +252,29 @@ object SkillRankDisplay { } } - @SubscribeEvent - fun playerLogout(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) { - SkyHanniMod.feature.storage.lastSkillObtained = lastSkillGained + private fun getCurrentSkills() { + if (profileID == null) return + val url = + "https://api.elitebot.dev/Graph/${LorenzUtils.getPlayerUuid()}/${profileID!!.toDashlessUUID()}/skills?days=1" + val response = APIUtil.getJSONResponseAsElement(url) + + try { + val data = eliteCollectionApiGson.fromJson>(response) + + data.sortBy { it.timestamp } + currentSkills = data.lastOrNull()?.skills?.toMutableMap() ?: mutableMapOf() + + } catch (e: Exception) { + ErrorManager.logErrorWithData( + e, + "Error loading user skill\n" + + "§eLoading the skill data from elitebot.dev failed!\n" + + "§eYou can switch worlds to try to fix the problem.\n" + + "§cIf this message repeats, please report it on Discord!\n", + "url" to url, + "apiResponse" to response, + ) + } } private fun isEnabled() = config.display && LorenzUtils.inSkyBlock