aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-02-20 19:07:53 +0100
committerGitHub <noreply@github.com>2024-02-20 19:07:53 +0100
commit92a4d14deaa7a4bc9cfb5426f9b493ee78a14f56 (patch)
treea6b4bc899b1aad83340e7ccb6d72012495db61f0 /src/main/java/at/hannibal2/skyhanni
parent3ab20a18d4a2be4cdba1f16cfa3d5a9276227042 (diff)
downloadskyhanni-92a4d14deaa7a4bc9cfb5426f9b493ee78a14f56.tar.gz
skyhanni-92a4d14deaa7a4bc9cfb5426f9b493ee78a14f56.tar.bz2
skyhanni-92a4d14deaa7a4bc9cfb5426f9b493ee78a14f56.zip
Fishing Tracker using SH Repo over NEU recipes. (#1026)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt32
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingTrackerCategoryManager.kt72
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt38
5 files changed, 60 insertions, 86 deletions
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<String, List<NEUInternalName>>()
+
+ @SubscribeEvent
+ fun onRepoReload(event: RepositoryReloadEvent) {
+ itemCategories = event.getConstant<FishingProfitItemsJson>("FishingProfitItems").categories
+ }
+
private fun getCurrentCategories(data: Data): Map<CategoryName, Int> {
val map = mutableMapOf<CategoryName, Int>()
map[nameAll] = data.items.size
@@ -125,6 +136,7 @@ object FishingProfitTracker {
private fun MutableList<List<Any>>.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<NEUInternalName>()
+ 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<String, List<NEUInternalName>>()
-
- private var shItemCategories = mapOf<String, List<NEUInternalName>>()
- private var neuItemCategories = mapOf<String, List<NEUInternalName>>()
-
- @SubscribeEvent
- fun onRepoReload(event: RepositoryReloadEvent) {
- shItemCategories = event.getConstant<FishingProfitItemsJson>("FishingProfitItems").categories
- updateItemCategories()
- }
-
- private fun updateItemCategories() {
- itemCategories = shItemCategories + neuItemCategories
- }
-
- @SubscribeEvent
- fun onNeuRepoReload(event: io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent) {
- val totalDrops = mutableListOf<String>()
- val dropCategories = mutableMapOf<String, MutableList<NEUInternalName>>()
- 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<String, Any?>) {
- logError(IllegalStateException(internalMessage), userMessage, false, *extraData)
+ fun logErrorStateWithData(
+ userMessage: String,
+ internalMessage: String,
+ vararg extraData: Pair<String, Any?>,
+ 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<String, Any?>) {
- logError(throwable, message, false, *extraData)
+ fun logErrorWithData(
+ throwable: Throwable,
+ message: String,
+ vararg extraData: Pair<String, Any?>,
+ 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<String, Any?>,
) {
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 = "<no stack trace>"
+ stackTrace = "<no stack trace>"
+ } else {
+ fullStackTrace = throwable.getCustomStackTrace(true).joinToString("\n")
+ stackTrace = throwable.getCustomStackTrace(false).joinToString("\n").removeSpam()
+ }
val randomId = UUID.randomUUID().toString()
val extraDataString = buildExtraDataString(extraData)