From a8973b851ad4d3edb0e6c605eb7aea29c6e66938 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:04:45 +0100 Subject: Improvement: Load Trophy Fishing from NEU (#1123) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: Cal Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> --- .../features/fishing/trophy/TrophyFishManager.kt | 37 +++++++++++++++++++++- .../features/fishing/trophy/TrophyFishMessages.kt | 3 +- 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt index 311661ed7..78fbf6731 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt @@ -1,10 +1,13 @@ package at.hannibal2.skyhanni.features.fishing.trophy +import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.data.jsonobjects.repo.TrophyFishJson import at.hannibal2.skyhanni.data.jsonobjects.repo.TrophyFishJson.TrophyFishInfo +import at.hannibal2.skyhanni.events.NeuProfileDataLoadedEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.test.command.ErrorManager +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.StringUtils.splitLines import net.minecraft.event.HoverEvent @@ -13,6 +16,7 @@ import net.minecraft.util.ChatStyle import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object TrophyFishManager { + private val config get() = SkyHanniMod.feature.fishing.trophyFishing @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { @@ -20,9 +24,40 @@ object TrophyFishManager { trophyFishInfo = data.trophy_fish } - val fishes: MutableMap>? + val fish: MutableMap>? get() = ProfileStorageData.profileSpecific?.crimsonIsle?.trophyFishes + private var loadedNeu = false + + @SubscribeEvent + fun onNeuProfileDataLoaded(event: NeuProfileDataLoadedEvent) { + if (loadedNeu || !config.loadFromNeuPV) return + + val caughtTrophyFish = event.getCurrentPlayerData()?.trophyFish?.caught ?: return + + loadedNeu = true + + val savedFish = fish ?: return + var changed = false + + for ((fishName, apiAmount) in caughtTrophyFish) { + val rarity = TrophyRarity.getByName(fishName) ?: continue + val name = fishName.split("_").dropLast(1).joinToString("") + + val savedFishData = savedFish.getOrPut(name) { mutableMapOf() } + + val currentSavedAmount = savedFishData[rarity] ?: 0 + if (apiAmount > currentSavedAmount) { + savedFishData[rarity] = apiAmount + ChatUtils.debug("Updated trophy fishing data from NEU PV: $name $rarity: $currentSavedAmount -> $apiAmount") + changed = true + } + } + if (changed) { + ChatUtils.chat("Updated Trophy Fishing data via NEU PV!") + } + } + private var trophyFishInfo = mapOf() fun getInfo(internalName: String) = trophyFishInfo[internalName] diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt index 1a6bdfe66..c8880bdc2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt @@ -4,7 +4,6 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.features.fishing.trophyfishing.ChatMessagesConfig.DesignFormat import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager.fishes import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager.getTooltip import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.CollectionUtils.sumAllValues @@ -42,7 +41,7 @@ class TrophyFishMessages { val rawRarity = displayRarity.lowercase().removeColor() val rarity = TrophyRarity.getByName(rawRarity) ?: return - val trophyFishes = fishes ?: return + val trophyFishes = TrophyFishManager.fish ?: return val trophyFishCounts = trophyFishes.getOrPut(internalName) { mutableMapOf() } val amount = trophyFishCounts.addOrPut(rarity, 1) -- cgit