From 22e21badc099cab973b78785856aad7e458b63c7 Mon Sep 17 00:00:00 2001 From: Obsidian <108832807+Obsidianninja11@users.noreply.github.com> Date: Sun, 27 Oct 2024 06:33:40 -0800 Subject: Fix: Compact stash (#2821) Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../skyhanni/config/features/chat/StashConfig.java | 7 ++- .../skyhanni/features/chat/StashCompact.kt | 68 ++++++++++------------ 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java index 738f24c93..378242b7b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java @@ -23,6 +23,11 @@ public class StashConfig { @ConfigEditorInfoText public String notice = ""; + @Expose + @ConfigOption(name = "Hide Added Messages", desc = "Hide the messages when something is added to your stash.") + @ConfigEditorBoolean + public boolean hideAddedMessages = true; + @Expose @ConfigOption(name = "Hide Duplicate Warnings", desc = "Hide duplicate warnings for previously reported stash counts.") @ConfigEditorBoolean @@ -30,7 +35,7 @@ public class StashConfig { @Expose @ConfigOption(name = "Hide Low Warnings", desc = "Hide warnings with a total count below this number.") - @ConfigEditorSlider(minValue = 0, maxValue = 1000000, minStep = 100) + @ConfigEditorSlider(minValue = 0, maxValue = 1_000_000, minStep = 100) public int hideLowWarningsThreshold = 0; @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt index 4c0a574fe..be8c2cc07 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -6,8 +6,8 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NumberUtil.formatIntOrNull -import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt +import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.StringUtils @@ -63,66 +63,62 @@ object StashCompact { private val config get() = SkyHanniMod.feature.chat.filterType.stashMessages - private var lastMaterialCount = 0 - private var lastDifferingMaterialsCount = 0 - private var lastType = "" + private var currentMessage: StashMessage? = null + private var lastMessage: StashMessage? = null - private var lastSentMaterialCount = 0 - private var lastSentType = "" + data class StashMessage(val materialCount: Int, val type: String) { + var differingMaterialsCount: Int? = null + } @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return - genericAddedToStashPattern.matchMatcher(event.message) { - event.blockedReason = "stash_compact" - } - + // TODO make a system for detecting message "groups" (multiple consecutive messages) materialCountPattern.matchMatcher(event.message) { - groupOrNull("count")?.formatIntOrNull()?.let { count -> - lastMaterialCount = count - } + currentMessage = StashMessage(group("count").formatInt(), group("type")) event.blockedReason = "stash_compact" } differingMaterialsCountPattern.matchMatcher(event.message) { - groupOrNull("count")?.formatIntOrNull()?.let { count -> - lastDifferingMaterialsCount = count - } - groupOrNull("type")?.let { type -> - lastType = type - } + currentMessage?.differingMaterialsCount = group("count").formatInt() event.blockedReason = "stash_compact" } if (pickupStashPattern.matches(event.message)) { event.blockedReason = "stash_compact" - if (lastMaterialCount <= config.hideLowWarningsThreshold) return - if (config.hideDuplicateCounts && lastMaterialCount == lastSentMaterialCount && lastType == lastSentType) return + val current = currentMessage ?: return + if (current.materialCount <= config.hideLowWarningsThreshold) return + if (config.hideDuplicateCounts && current == lastMessage) return - sendCompactedStashMessage() + current.sendCompactedStashMessage() } - } - private fun sendCompactedStashMessage() { - val typeNameFormat = StringUtils.pluralize(lastMaterialCount, lastType) - val typeStringExtra = lastDifferingMaterialsCount.let { - if (it == 0) "." else ", §etotalling §6$it ${StringUtils.pluralize(it, "type")}§6." + if (!config.hideAddedMessages) return + genericAddedToStashPattern.matchMatcher(event.message) { + event.blockedReason = "stash_compact" } + } + + private fun StashMessage.sendCompactedStashMessage() { + val typeNameFormat = StringUtils.pluralize(materialCount, type) + val (mainColor, accentColor) = if (type == "item") "§e" to "§6" else "§b" to "§3" + val typeStringExtra = differingMaterialsCount?.let { + ", ${mainColor}totalling $accentColor$it ${StringUtils.pluralize(it, "type")}$mainColor" + }.orEmpty() + val action = if (config.useViewStash) "view" else "pickup" ChatUtils.clickableChat( - "§eYou have §6$lastMaterialCount §e$typeNameFormat in stash§6$typeStringExtra " + - "§eClick to ${if (config.useViewStash) "§6view" else "§6pickup"} §eyour stash!", + "${mainColor}You have $accentColor${materialCount.shortFormat()} $mainColor$typeNameFormat in stash$typeStringExtra. " + + "${mainColor}Click to $accentColor$action ${mainColor}your stash!", onClick = { - if (config.useViewStash) HypixelCommands.viewStash(lastType) + if (config.useViewStash) HypixelCommands.viewStash(type) else HypixelCommands.pickupStash() }, + hover = "§eClick to $action your $type stash!", ) - lastSentMaterialCount = lastMaterialCount - lastSentType = lastType - // Dirty, but item stash doesn't always have differing materials count, - // and we don't compare this value to the last one, so we can reset it here - lastDifferingMaterialsCount = 0 + currentMessage = null + lastMessage = this } private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled -- cgit