aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorObsidian <108832807+Obsidianninja11@users.noreply.github.com>2024-10-27 06:33:40 -0800
committerGitHub <noreply@github.com>2024-10-27 14:33:40 +0000
commit22e21badc099cab973b78785856aad7e458b63c7 (patch)
tree475c4a2564c921b8251a1c84de7c1f733f739dab
parent1a9f6fed7297be659fe6a0f5a114bab06aedd437 (diff)
downloadSkyHanni-22e21badc099cab973b78785856aad7e458b63c7.tar.gz
SkyHanni-22e21badc099cab973b78785856aad7e458b63c7.tar.bz2
SkyHanni-22e21badc099cab973b78785856aad7e458b63c7.zip
Fix: Compact stash (#2821)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt68
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
@@ -24,13 +24,18 @@ public class StashConfig {
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
public boolean hideDuplicateCounts = true;
@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