diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index 5c85c97eca2b..a3d569b5d9f0 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.data.jsonobjects.local.KnownFeaturesJson import at.hannibal2.skyhanni.data.jsonobjects.local.VisualWordsJson import at.hannibal2.skyhanni.events.LorenzEvent import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity +import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.misc.update.UpdateManager import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils @@ -150,6 +151,15 @@ class ConfigManager { return reader.nextString().toLong().asTimeMark() } }.nullSafe()) + .registerTypeAdapter(CropType::class.java, object : TypeAdapter() { + override fun write(out: JsonWriter, value: CropType?) { + out.value(value?.name) + } + + override fun read(reader: JsonReader): CropType { + return CropType.valueOf(reader.nextString()) + } + }) .enableComplexMapKeySerialization() } diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.java index c37ba1dd0993..0091eb72eacd 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.java @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.config.storage; +import at.hannibal2.skyhanni.features.garden.CropType; import at.hannibal2.skyhanni.features.misc.visualwords.VisualWord; import at.hannibal2.skyhanni.utils.LorenzVec; import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker; @@ -50,4 +51,11 @@ public class Storage { @Expose public List blacklistedUsers = new ArrayList<>(); + + @Expose + public CropType lastCropBroken = null; + + @Expose + public String lastSkillObtained = null; + } 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 1dc506047355..3e3206cd5b09 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 @@ -26,6 +26,7 @@ data class EliteLeaderboardJson( data class EliteLeaderboard( @Expose val rank: Int, + @Expose val amount: Long, @Expose val upcomingRank: Int, @Expose val upcomingPlayers: List ) @@ -45,11 +46,6 @@ 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 811421456c21..21ee8dd0b189 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,7 +4,6 @@ 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 @@ -36,9 +35,9 @@ 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 -import kotlin.time.Duration.Companion.seconds object FarmingCollectionDisplay { @@ -46,7 +45,6 @@ object FarmingCollectionDisplay { private var checkDuration = 10.minutes private var worldSwapRefresh = true - private var settingToggleCooldown = SimpleTimeMark.farPast() @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { @@ -74,8 +72,11 @@ object FarmingCollectionDisplay { private var currentCollections = mutableMapOf() private var lastFetchedCrop: CropType? = null - private var lastBrokenCrop: CropType? = null - private var hasFetchedCollection = false + private var lastBrokenCrop: CropType? + get() = SkyHanniMod.feature.storage.lastCropBroken + set(value) { + SkyHanniMod.feature.storage.lastCropBroken = value + } private var lastLeaderboardFetch = SimpleTimeMark.farPast() private var display = emptyList() @@ -99,10 +100,7 @@ object FarmingCollectionDisplay { @SubscribeEvent fun onConfigLoad(event: ConfigLoadEvent) { config.crop.afterChange { - if (settingToggleCooldown.passedSince() < 30.seconds) { - settingToggleCooldown = SimpleTimeMark.now() - lastLeaderboardFetch = SimpleTimeMark.farPast() - } + lastLeaderboardFetch = SimpleTimeMark.farPast() } } @@ -111,13 +109,6 @@ object FarmingCollectionDisplay { if (!isEnabled()) return if (profileID == null) return - if (!hasFetchedCollection) { - SkyHanniMod.coroutineScope.launch { - getCurrentCollection() - } - hasFetchedCollection = true - } - if (lastLeaderboardFetch.passedSince() > checkDuration) { lastLeaderboardFetch = SimpleTimeMark.now() val crop = if (config.crop.get() == CropDisplay.AUTO) { @@ -172,7 +163,6 @@ object FarmingCollectionDisplay { } private fun resetData() { - hasFetchedCollection = false lastLeaderboardFetch = SimpleTimeMark.farPast() collectionRanks.clear() collectionPlacements.clear() @@ -217,7 +207,6 @@ object FarmingCollectionDisplay { listOf("§bClick to refresh."), onClick = { lastLeaderboardFetch = SimpleTimeMark.farPast() - hasFetchedCollection = false ChatUtils.chat("Collection leaderboard updating...") } ) @@ -260,6 +249,7 @@ object FarmingCollectionDisplay { } collectionPlacements[crop] = placements lastFetchedCrop = crop + currentCollections[crop] = data.amount } catch (e: Exception) { ErrorManager.logErrorWithData( @@ -274,37 +264,17 @@ 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 a12862f26eef..4ece4d134e4d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillRankDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/skillprogress/SkillRankDisplay.kt @@ -5,7 +5,6 @@ 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 @@ -31,6 +30,7 @@ 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 @@ -41,7 +41,6 @@ object SkillRankDisplay { private var checkDuration = 10.minutes private var worldSwapRefresh = true - private var settingToggleCooldown = SimpleTimeMark.farPast() @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { @@ -60,9 +59,13 @@ object SkillRankDisplay { private val skillRanks = mutableMapOf() private var currentSkills = mutableMapOf() - private var lastSkillGained: String? = null + private var lastSkillGained: String? + get() = SkyHanniMod.feature.storage.lastSkillObtained + set(value) { + SkyHanniMod.feature.storage.lastSkillObtained = value + } + private var lastSkillFetched: String? = null - private var hasFetchedSkills = false private var lastLeaderboardFetch = SimpleTimeMark.farPast() private var lastXPGained = SimpleTimeMark.farPast() @@ -87,10 +90,7 @@ object SkillRankDisplay { @SubscribeEvent fun onConfigLoad(event: ConfigLoadEvent) { config.skill.afterChange { - if (settingToggleCooldown.passedSince() < 30.seconds) { - settingToggleCooldown = SimpleTimeMark.now() - lastLeaderboardFetch = SimpleTimeMark.farPast() - } + lastLeaderboardFetch = SimpleTimeMark.farPast() } } @@ -99,13 +99,6 @@ object SkillRankDisplay { if (!isEnabled()) return if (profileID == null) return - if (!hasFetchedSkills) { - SkyHanniMod.coroutineScope.launch { - getCurrentSkills() - } - hasFetchedSkills = true - } - if (lastLeaderboardFetch.passedSince() > checkDuration) { lastLeaderboardFetch = SimpleTimeMark.now() val skill = if (config.skill.get() == SkillDisplay.AUTO) { @@ -152,7 +145,6 @@ object SkillRankDisplay { } private fun resetData() { - hasFetchedSkills = false lastLeaderboardFetch = SimpleTimeMark.farPast() skillRanks.clear() skillPlacements.clear() @@ -197,7 +189,6 @@ object SkillRankDisplay { listOf("§bClick to refresh."), onClick = { lastLeaderboardFetch = SimpleTimeMark.farPast() - hasFetchedSkills = false ChatUtils.chat("Skills leaderboard updating...") } ) @@ -240,6 +231,7 @@ object SkillRankDisplay { } skillPlacements[skill] = placements lastSkillFetched = skill + currentSkills[skill] = data.amount } catch (e: Exception) { ErrorManager.logErrorWithData( @@ -254,29 +246,9 @@ object SkillRankDisplay { } } - 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, - ) - } + @SubscribeEvent + fun playerLogout(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) { + SkyHanniMod.feature.storage.lastSkillObtained = lastSkillGained } private fun isEnabled() = config.display && LorenzUtils.inSkyBlock