diff options
| author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-03-22 18:04:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-22 18:04:45 +0100 |
| commit | a8973b851ad4d3edb0e6c605eb7aea29c6e66938 (patch) | |
| tree | 4bb7e04fdc48022fb7d9bdcd42915078bf4f7952 /src/main/java/at/hannibal2/skyhanni/features | |
| parent | 6231ce3132dd22b539ed76d5999d281d9109ae0b (diff) | |
| download | skyhanni-a8973b851ad4d3edb0e6c605eb7aea29c6e66938.tar.gz skyhanni-a8973b851ad4d3edb0e6c605eb7aea29c6e66938.tar.bz2 skyhanni-a8973b851ad4d3edb0e6c605eb7aea29c6e66938.zip | |
Improvement: Load Trophy Fishing from NEU (#1123)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: Cal <cwolfson58@gmail.com>
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt | 37 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt | 3 |
2 files changed, 37 insertions, 3 deletions
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<String, MutableMap<TrophyRarity, Int>>? + val fish: MutableMap<String, MutableMap<TrophyRarity, Int>>? 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<String, TrophyFishInfo>() 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) |
