From 92a4d14deaa7a4bc9cfb5426f9b493ee78a14f56 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 20 Feb 2024 19:07:53 +0100 Subject: Fishing Tracker using SH Repo over NEU recipes. (#1026) --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 - .../at/hannibal2/skyhanni/events/LorenzEvent.kt | 2 +- .../fishing/tracker/FishingProfitTracker.kt | 32 +++++++++- .../tracker/FishingTrackerCategoryManager.kt | 72 ---------------------- .../skyhanni/test/command/ErrorManager.kt | 38 +++++++++--- 5 files changed, 60 insertions(+), 86 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingTrackerCategoryManager.kt (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 062740d2d..e95f05d5d 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -144,7 +144,6 @@ import at.hannibal2.skyhanni.features.fishing.SharkFishCounter import at.hannibal2.skyhanni.features.fishing.ShowFishingItemName import at.hannibal2.skyhanni.features.fishing.ThunderSparksHighlight import at.hannibal2.skyhanni.features.fishing.tracker.FishingProfitTracker -import at.hannibal2.skyhanni.features.fishing.tracker.FishingTrackerCategoryManager import at.hannibal2.skyhanni.features.fishing.tracker.SeaCreatureTracker import at.hannibal2.skyhanni.features.fishing.trophy.GeyserFishing import at.hannibal2.skyhanni.features.fishing.trophy.OdgerWaypoint @@ -658,7 +657,6 @@ class SkyHanniMod { loadModule(GetFromSacksTabComplete) loadModule(SlayerProfitTracker) loadModule(FishingProfitTracker) - loadModule(FishingTrackerCategoryManager) loadModule(SeaCreatureTracker) loadModule(SlayerItemsOnGround()) loadModule(RestorePieceOfWizardPortalLore()) diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt index c83ec95aa..c1a655e29 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt @@ -47,7 +47,7 @@ abstract class LorenzEvent : Event() { val callerName = listener.toString().split(" ")[1].split("@")[0].split(".").last() val errorName = throwable::class.simpleName ?: "error" val message = "Caught an $errorName at $eventName in $callerName: '${throwable.message}'" - ErrorManager.logError(throwable, message, ignoreErrorCache) + ErrorManager.logErrorWithData(throwable, message, ignoreErrorCache = ignoreErrorCache) } onError(throwable) if (stopOnFirstError) break diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt index 9d901f08a..1c5e6f7b6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt @@ -1,12 +1,15 @@ package at.hannibal2.skyhanni.features.fishing.tracker import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.jsonobjects.repo.FishingProfitItemsJson import at.hannibal2.skyhanni.events.FishingBobberCastEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.ItemAddEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.fishing.FishingAPI +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.DelayedRun @@ -18,6 +21,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -91,6 +95,13 @@ object FishingProfitTracker { private val nameAll: CategoryName = "All" private var currentCategory: CategoryName = nameAll + private var itemCategories = mapOf>() + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + itemCategories = event.getConstant("FishingProfitItems").categories + } + private fun getCurrentCategories(data: Data): Map { val map = mutableMapOf() map[nameAll] = data.items.size @@ -125,6 +136,7 @@ object FishingProfitTracker { private fun MutableList>.addCategories(data: Data): (NEUInternalName) -> Boolean { val amounts = getCurrentCategories(data) + checkMissingItems(data) val list = amounts.keys.toList() if (currentCategory !in list) { currentCategory = nameAll @@ -151,6 +163,24 @@ object FishingProfitTracker { return filter } + private fun checkMissingItems(data: Data) { + val missingItems = mutableListOf() + for (internalName in data.items.keys) { + if (itemCategories.none { internalName in it.value }) { + missingItems.add(internalName) + } + } + if (missingItems.isNotEmpty()) { + val label = StringUtils.pluralize(missingItems.size, "item", withNumber = true) + ErrorManager.logErrorStateWithData( + "Loaded $label not in a fishing category", + "Found items missing in itemCategories", + "missingItems" to missingItems, + noStackTrace = true + ) + } + } + @SubscribeEvent fun onItemAdd(event: ItemAddEvent) { if (!isEnabled()) return @@ -200,8 +230,6 @@ object FishingProfitTracker { addCatch() } - private val itemCategories get() = FishingTrackerCategoryManager.itemCategories - private fun isAllowedItem(internalName: NEUInternalName) = itemCategories.any { internalName in it.value } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingTrackerCategoryManager.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingTrackerCategoryManager.kt deleted file mode 100644 index 8c240799f..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingTrackerCategoryManager.kt +++ /dev/null @@ -1,72 +0,0 @@ -package at.hannibal2.skyhanni.features.fishing.tracker - -import at.hannibal2.skyhanni.data.jsonobjects.repo.FishingProfitItemsJson -import at.hannibal2.skyhanni.events.RepositoryReloadEvent -import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName -import at.hannibal2.skyhanni.utils.NEUItems -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -object FishingTrackerCategoryManager { - - var itemCategories = mapOf>() - - private var shItemCategories = mapOf>() - private var neuItemCategories = mapOf>() - - @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - shItemCategories = event.getConstant("FishingProfitItems").categories - updateItemCategories() - } - - private fun updateItemCategories() { - itemCategories = shItemCategories + neuItemCategories - } - - @SubscribeEvent - fun onNeuRepoReload(event: io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent) { - val totalDrops = mutableListOf() - val dropCategories = mutableMapOf>() - for ((seaCreature, data) in NEUItems.allNeuRepoItems().filter { it.key.endsWith("_SC") }) { - val asJsonObject = data.getAsJsonArray("recipes")[0].asJsonObject - val drops = asJsonObject.getAsJsonArray("drops") - .map { it.asJsonObject.get("id").asString }.map { it.split(":").first() } - val asJsonArray = asJsonObject.get("extra") - val extra = asJsonArray?.let { - asJsonArray.asJsonArray.toList() - .map { it.toString() } - .filter { !it.contains("Fishing Skill") && !it.contains("Requirements:") && !it.contains("Fished from water") } - .joinToString(" + ") - } ?: "null" - val category = if (extra.contains("Fishing Festival")) { - "Fishing Festival" - } else if (extra.contains("Spooky Festival")) { - "Spooky Festival" - } else if (extra.contains("Jerry's Workshop")) { - "Jerry's Workshop" - } else if (extra.contains("Oasis")) { - "Oasis" - } else if (extra.contains("Magma Fields") || extra.contains("Precursor Remnants") || - extra.contains("Goblin Holdout") - ) { - "Crystal Hollows" - } else if (extra.contains("Crimson Isle Lava")) { - "Crimson Isle Lava" - } else { - if (extra.isNotEmpty()) { - println("unknown extra: $extra = $seaCreature ($drops)") - } - "Water" - } + " Sea Creatures" - for (drop in drops) { - if (drop !in totalDrops) { - totalDrops.add(drop) - dropCategories.getOrPut(category) { mutableListOf() }.add(drop.asInternalName()) - } - } - } - neuItemCategories = dropCategories - updateItemCategories() - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt index ca9449419..29b296baf 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt @@ -49,26 +49,38 @@ object ErrorManager { @Deprecated("Use data as well", ReplaceWith("logErrorStateWithData()")) fun logErrorState(userMessage: String, internalMessage: String) { - logError(IllegalStateException(internalMessage), userMessage, false) + logError(IllegalStateException(internalMessage), userMessage, ignoreErrorCache = false, noStackTrace = false) } - fun logErrorStateWithData(userMessage: String, internalMessage: String, vararg extraData: Pair) { - logError(IllegalStateException(internalMessage), userMessage, false, *extraData) + fun logErrorStateWithData( + userMessage: String, + internalMessage: String, + vararg extraData: Pair, + ignoreErrorCache: Boolean = false, + noStackTrace: Boolean = false, + ) { + logError(IllegalStateException(internalMessage), userMessage, ignoreErrorCache, noStackTrace, *extraData) } @Deprecated("Use data as well", ReplaceWith("logErrorWithData()")) fun logError(throwable: Throwable, message: String) { - logError(throwable, message, false) + logError(throwable, message, ignoreErrorCache = false, noStackTrace = false) } - fun logErrorWithData(throwable: Throwable, message: String, vararg extraData: Pair) { - logError(throwable, message, false, *extraData) + fun logErrorWithData( + throwable: Throwable, + message: String, + vararg extraData: Pair, + ignoreErrorCache: Boolean = false, + ) { + logError(throwable, message, ignoreErrorCache, noStackTrace = false, *extraData) } - fun logError( + private fun logError( throwable: Throwable, message: String, ignoreErrorCache: Boolean, + noStackTrace: Boolean, vararg extraData: Pair, ) { val error = Error(message, throwable) @@ -83,8 +95,16 @@ object ErrorManager { cache.add(pair) } - val fullStackTrace = throwable.getCustomStackTrace(true).joinToString("\n") - val stackTrace = throwable.getCustomStackTrace(false).joinToString("\n").removeSpam() + val fullStackTrace: String + val stackTrace: String + + if (noStackTrace) { + fullStackTrace = "" + stackTrace = "" + } else { + fullStackTrace = throwable.getCustomStackTrace(true).joinToString("\n") + stackTrace = throwable.getCustomStackTrace(false).joinToString("\n").removeSpam() + } val randomId = UUID.randomUUID().toString() val extraDataString = buildExtraDataString(extraData) -- cgit