From 47eae415e5feafad4a3b177b3cc124d7d83011b3 Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Tue, 1 Oct 2024 21:24:39 -0400 Subject: [PATCH 01/12] Add compacting for stash messages --- .../config/features/chat/ChatConfig.java | 6 ++ .../skyhanni/features/chat/StashCompact.kt | 89 +++++++++++++++++++ .../skyhanni/utils/HypixelCommands.kt | 4 + 3 files changed, 99 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java index 53f7aac94df8..355fcb3fb709 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java @@ -142,4 +142,10 @@ public String toString() { @ConfigEditorBoolean @FeatureToggle public boolean petRarityDropMessage = true; + + @Expose + @ConfigOption(name = "Compact Stash Warnings", desc = "Compact the Stash warnings into a single line of text.") + @ConfigEditorBoolean + @FeatureToggle + public boolean compactStashWarnings = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt new file mode 100644 index 000000000000..e9763e7be305 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -0,0 +1,89 @@ +package at.hannibal2.skyhanni.features.chat + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.HypixelCommands +import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull +import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher +import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object StashCompact { + + // + private val patternGroup = RepoPattern.group("stash.compact") + + /** + * REGEX-TEST: §f §7You have §3226 §7materials stashed away! + */ + private val materialCountPattern by patternGroup.pattern( + "material.count", + "§f *§7You have §3(?[\\d,]) §7materials stashed away!.*", + ) + + /** + * REGEX-TEST: §f §8(This totals 1 type of material stashed!) + */ + private val differingMaterialsCountPattern by patternGroup.pattern( + "differing.materials.count", + "§f *§8(This totals (?[\\d,]) type of material stashed!).*", + ) + + /** + * REGEX-TEST: §f §3§l>>> §3§lCLICK HERE§b to pick them up! §3§l<<< + */ + private val pickupStashPattern by patternGroup.pattern( + "pickup.stash", + "§f *§3§l>>> §3§lCLICK HERE§b to pick them up! §3§l<<<.*", + ) + // + + private val config get() = SkyHanniMod.feature.chat + + private var lastMaterialCount = 0 + private var lastDifferingMaterialsCount = 0 + + private var lastSentMaterialCount = 0 + private var lastSentDifferingMaterialsCount = 0 + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!config.compactStashWarnings) return + val message = event.message + materialCountPattern.matchMatcher(event.message) { + groupOrNull("count")?.replace(",", "")?.toIntOrNull()?.let { count -> + lastMaterialCount = count + } + event.blockedReason = "stash_compact" + } + + differingMaterialsCountPattern.matchMatcher(event.message) { + groupOrNull("count")?.replace(",", "")?.toIntOrNull()?.let { count -> + lastDifferingMaterialsCount = count + } + event.blockedReason = "stash_compact" + } + + if(pickupStashPattern.matches(message)) { + event.blockedReason = "stash_compact" + if (lastMaterialCount != lastSentMaterialCount || lastDifferingMaterialsCount != lastSentDifferingMaterialsCount) { + sendCompactedStashMessage() + lastSentMaterialCount = lastMaterialCount + lastSentDifferingMaterialsCount = lastDifferingMaterialsCount + } + } + } + + private fun sendCompactedStashMessage() { + ChatUtils.clickableChat( + "§7You have §3${lastMaterialCount} §7materials in stash, §8totalling $lastDifferingMaterialsCount types. §3Click to pickup§7.", + onClick = { + HypixelCommands.pickupStash() + } + ) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt index c148e93e80fd..cfbc5fba0fce 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt @@ -158,6 +158,10 @@ object HypixelCommands { send("cb $uuid") } + fun pickupStash() { + send("pickupstash") + } + private fun send(command: String) { @Suppress("DEPRECATION") // TODO rename function From b86fab33c6c5a01e3b6d5acca9ce0b14b3a8c051 Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Tue, 1 Oct 2024 21:30:59 -0400 Subject: [PATCH 02/12] Pluralizer --- .../java/at/hannibal2/skyhanni/features/chat/StashCompact.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 e9763e7be305..e81ebf4312b0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -80,7 +81,9 @@ object StashCompact { private fun sendCompactedStashMessage() { ChatUtils.clickableChat( - "§7You have §3${lastMaterialCount} §7materials in stash, §8totalling $lastDifferingMaterialsCount types. §3Click to pickup§7.", + "§7You have §3${lastMaterialCount} §7${StringUtils.pluralize(lastMaterialCount, "material")} in stash, " + + "§8totalling $lastDifferingMaterialsCount ${StringUtils.pluralize(lastDifferingMaterialsCount, "type")}. " + + "§3Click to pickup§7.", onClick = { HypixelCommands.pickupStash() } From c1980eee3369ef52ae8cbec2d8df884511812e37 Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:05:40 -0400 Subject: [PATCH 03/12] This is better --- .../config/features/chat/ChatConfig.java | 24 +++++++++-- .../skyhanni/features/chat/StashCompact.kt | 40 +++++++++++++++---- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java index 355fcb3fb709..2af6f230e941 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java @@ -6,6 +6,7 @@ import io.github.notenoughupdates.moulconfig.annotations.Category; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; import org.lwjgl.input.Keyboard; @@ -145,7 +146,24 @@ public String toString() { @Expose @ConfigOption(name = "Compact Stash Warnings", desc = "Compact the Stash warnings into a single line of text.") - @ConfigEditorBoolean - @FeatureToggle - public boolean compactStashWarnings = true; + @ConfigEditorDropdown + public StashCompactType compactStashWarnings = StashCompactType.COMPACT; + + public enum StashCompactType { + NONE("None (Show all)"), + COMPACT("Compact"), + HIDE("Hide Completely"), + ; + + private final String name; + + StashCompactType(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + } } 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 e81ebf4312b0..30080e81aa10 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.chat import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.features.chat.ChatConfig import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils @@ -20,18 +21,20 @@ object StashCompact { /** * REGEX-TEST: §f §7You have §3226 §7materials stashed away! + * REGEX-TEST: §f §7You have §31,000 §7items stashed away! */ private val materialCountPattern by patternGroup.pattern( "material.count", - "§f *§7You have §3(?[\\d,]) §7materials stashed away!.*", + "§f *§7You have §3(?[\\d,]+) (§.)+(?item|material)s? stashed away!.*", ) /** * REGEX-TEST: §f §8(This totals 1 type of material stashed!) + * REGEX-TEST: §f §8(This totals 2 types of items stashed!) */ private val differingMaterialsCountPattern by patternGroup.pattern( "differing.materials.count", - "§f *§8(This totals (?[\\d,]) type of material stashed!).*", + "§f *§8(This totals (?[\\d,]+) type of (§.)+(?item|material)s? stashed!).*", ) /** @@ -39,22 +42,38 @@ object StashCompact { */ private val pickupStashPattern by patternGroup.pattern( "pickup.stash", - "§f *§3§l>>> §3§lCLICK HERE§b to pick them up! §3§l<<<.*", + "§f *§3§l>>> §3§lCLICK HERE§b to pick (?:them|it) up! §3§l<<<.*", ) + + /** + * REGEX-TEST: §eOne or more items didn't fit in your inventory and were added to your item stash! §6Click here to pick them up! + * REGEX-TEST: §eOne or more materials didn't fit in your inventory and were added to your material stash! §6Click here to pick them up! + */ + private val genericAddedToStashPattern by patternGroup.pattern( + "generic", + "§eOne or more (?:item|material)s? didn't fit in your inventory and were added to your (?:item|material) stash! §6Click here §eto pick them up!" + ) + // private val config get() = SkyHanniMod.feature.chat private var lastMaterialCount = 0 private var lastDifferingMaterialsCount = 0 + private var lastType = "" private var lastSentMaterialCount = 0 private var lastSentDifferingMaterialsCount = 0 + private var lastSentType = "" @SubscribeEvent fun onChat(event: LorenzChatEvent) { - if (!config.compactStashWarnings) return - val message = event.message + if (!isEnabled()) return + + genericAddedToStashPattern.matchMatcher(event.message) { + event.blockedReason = "stash_compact" + } + materialCountPattern.matchMatcher(event.message) { groupOrNull("count")?.replace(",", "")?.toIntOrNull()?.let { count -> lastMaterialCount = count @@ -66,22 +85,27 @@ object StashCompact { groupOrNull("count")?.replace(",", "")?.toIntOrNull()?.let { count -> lastDifferingMaterialsCount = count } + groupOrNull("type")?.let { type -> + lastType = type + } event.blockedReason = "stash_compact" } - if(pickupStashPattern.matches(message)) { + if(pickupStashPattern.matches(event.message)) { event.blockedReason = "stash_compact" if (lastMaterialCount != lastSentMaterialCount || lastDifferingMaterialsCount != lastSentDifferingMaterialsCount) { sendCompactedStashMessage() lastSentMaterialCount = lastMaterialCount lastSentDifferingMaterialsCount = lastDifferingMaterialsCount + lastSentType = lastType } } } private fun sendCompactedStashMessage() { + if (config.compactStashWarnings == ChatConfig.StashCompactType.HIDE) return ChatUtils.clickableChat( - "§7You have §3${lastMaterialCount} §7${StringUtils.pluralize(lastMaterialCount, "material")} in stash, " + + "§7You have §3${lastMaterialCount} §7${StringUtils.pluralize(lastMaterialCount, lastType)} in stash, " + "§8totalling $lastDifferingMaterialsCount ${StringUtils.pluralize(lastDifferingMaterialsCount, "type")}. " + "§3Click to pickup§7.", onClick = { @@ -89,4 +113,6 @@ object StashCompact { } ) } + + private fun isEnabled() = config.compactStashWarnings != ChatConfig.StashCompactType.NONE } From 1e8bdfd99989950447399f6a403b829aea3be51b Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:23:38 -0400 Subject: [PATCH 04/12] Cleanup --- .../skyhanni/config/features/chat/ChatConfig.java | 10 +++++----- .../hannibal2/skyhanni/features/chat/StashCompact.kt | 12 +++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java index 2af6f230e941..c36ad484916d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java @@ -145,19 +145,19 @@ public String toString() { public boolean petRarityDropMessage = true; @Expose - @ConfigOption(name = "Compact Stash Warnings", desc = "Compact the Stash warnings into a single line of text.") + @ConfigOption(name = "Stash Warnings", desc = "Compact or hide warnings relating to items/materials in your stash.") @ConfigEditorDropdown - public StashCompactType compactStashWarnings = StashCompactType.COMPACT; + public StashHandlerType stashWarnings = StashHandlerType.COMPACT; - public enum StashCompactType { + public enum StashHandlerType { NONE("None (Show all)"), - COMPACT("Compact"), + COMPACT("Compact Messages"), HIDE("Hide Completely"), ; private final String name; - StashCompactType(String name) { + StashHandlerType(String name) { this.name = name; } 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 30080e81aa10..50746aa1d362 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -49,9 +49,10 @@ object StashCompact { * REGEX-TEST: §eOne or more items didn't fit in your inventory and were added to your item stash! §6Click here to pick them up! * REGEX-TEST: §eOne or more materials didn't fit in your inventory and were added to your material stash! §6Click here to pick them up! */ + @Suppress("MaxLineLength") private val genericAddedToStashPattern by patternGroup.pattern( "generic", - "§eOne or more (?:item|material)s? didn't fit in your inventory and were added to your (?:item|material) stash! §6Click here §eto pick them up!" + "§eOne or more (?:item|material)s? didn't fit in your inventory and were added to your (?:item|material) stash! §6Click here §eto pick them up!", ) // @@ -91,7 +92,7 @@ object StashCompact { event.blockedReason = "stash_compact" } - if(pickupStashPattern.matches(event.message)) { + if (pickupStashPattern.matches(event.message)) { event.blockedReason = "stash_compact" if (lastMaterialCount != lastSentMaterialCount || lastDifferingMaterialsCount != lastSentDifferingMaterialsCount) { sendCompactedStashMessage() @@ -103,16 +104,17 @@ object StashCompact { } private fun sendCompactedStashMessage() { - if (config.compactStashWarnings == ChatConfig.StashCompactType.HIDE) return + if (config.stashWarnings == ChatConfig.StashHandlerType.HIDE) return ChatUtils.clickableChat( "§7You have §3${lastMaterialCount} §7${StringUtils.pluralize(lastMaterialCount, lastType)} in stash, " + "§8totalling $lastDifferingMaterialsCount ${StringUtils.pluralize(lastDifferingMaterialsCount, "type")}. " + "§3Click to pickup§7.", onClick = { HypixelCommands.pickupStash() - } + }, + prefix = false, ) } - private fun isEnabled() = config.compactStashWarnings != ChatConfig.StashCompactType.NONE + private fun isEnabled() = config.stashWarnings != ChatConfig.StashHandlerType.NONE } From 7f2f3a5a198843489d440bb09036ead930eaba56 Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:45:34 -0400 Subject: [PATCH 05/12] Update pattern to match literal parens --- .../at/hannibal2/skyhanni/features/chat/StashCompact.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 50746aa1d362..400b72b638ca 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -31,10 +31,11 @@ object StashCompact { /** * REGEX-TEST: §f §8(This totals 1 type of material stashed!) * REGEX-TEST: §f §8(This totals 2 types of items stashed!) + * REGEX-TEST: §f §8(This totals 1 type of material stashed!) */ private val differingMaterialsCountPattern by patternGroup.pattern( "differing.materials.count", - "§f *§8(This totals (?[\\d,]+) type of (§.)+(?item|material)s? stashed!).*", + "§f *§8\\(This totals (?[\\d,]+) types? of (?item|material)s? stashed!\\).*", ) /** @@ -94,7 +95,10 @@ object StashCompact { if (pickupStashPattern.matches(event.message)) { event.blockedReason = "stash_compact" - if (lastMaterialCount != lastSentMaterialCount || lastDifferingMaterialsCount != lastSentDifferingMaterialsCount) { + if (lastMaterialCount != lastSentMaterialCount || + lastDifferingMaterialsCount != lastSentDifferingMaterialsCount || + lastType != lastSentType + ) { sendCompactedStashMessage() lastSentMaterialCount = lastMaterialCount lastSentDifferingMaterialsCount = lastDifferingMaterialsCount From ee7d33188eae6e37f2cfbfdc90b500ada9975e8c Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:49:53 -0400 Subject: [PATCH 06/12] Better regex tests --- .../java/at/hannibal2/skyhanni/features/chat/StashCompact.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 400b72b638ca..23a798fe22f8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -31,7 +31,8 @@ object StashCompact { /** * REGEX-TEST: §f §8(This totals 1 type of material stashed!) * REGEX-TEST: §f §8(This totals 2 types of items stashed!) - * REGEX-TEST: §f §8(This totals 1 type of material stashed!) + * REGEX-TEST: §f §8(This totals 3 types of materials stashed!) + * REGEX-TEST: §f §8(This totals 4 types of items stashed!) */ private val differingMaterialsCountPattern by patternGroup.pattern( "differing.materials.count", From d5e1cc40baa4a125adeb7128e79537f3313e80cc Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Sun, 6 Oct 2024 12:23:33 -0400 Subject: [PATCH 07/12] Slight formatting change --- .../java/at/hannibal2/skyhanni/features/chat/StashCompact.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 23a798fe22f8..8d6545a3463e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -112,7 +112,7 @@ object StashCompact { if (config.stashWarnings == ChatConfig.StashHandlerType.HIDE) return ChatUtils.clickableChat( "§7You have §3${lastMaterialCount} §7${StringUtils.pluralize(lastMaterialCount, lastType)} in stash, " + - "§8totalling $lastDifferingMaterialsCount ${StringUtils.pluralize(lastDifferingMaterialsCount, "type")}. " + + "§8totalling $lastDifferingMaterialsCount ${StringUtils.pluralize(lastDifferingMaterialsCount, "type")}§7. " + "§3Click to pickup§7.", onClick = { HypixelCommands.pickupStash() From 033ddd0a80e996966b0b24e99b94a2ccbc55ace5 Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:25:46 -0400 Subject: [PATCH 08/12] Fixes, improvements --- .../config/features/chat/ChatConfig.java | 24 ------------ .../features/chat/FilterTypesConfig.java | 5 +++ .../config/features/chat/StashConfig.java | 37 +++++++++++++++++++ .../skyhanni/features/chat/StashCompact.kt | 12 +++--- .../skyhanni/utils/HypixelCommands.kt | 4 ++ 5 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java index c36ad484916d..53f7aac94df8 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java @@ -6,7 +6,6 @@ import io.github.notenoughupdates.moulconfig.annotations.Category; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList; -import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; import org.lwjgl.input.Keyboard; @@ -143,27 +142,4 @@ public String toString() { @ConfigEditorBoolean @FeatureToggle public boolean petRarityDropMessage = true; - - @Expose - @ConfigOption(name = "Stash Warnings", desc = "Compact or hide warnings relating to items/materials in your stash.") - @ConfigEditorDropdown - public StashHandlerType stashWarnings = StashHandlerType.COMPACT; - - public enum StashHandlerType { - NONE("None (Show all)"), - COMPACT("Compact Messages"), - HIDE("Hide Completely"), - ; - - private final String name; - - StashHandlerType(String name) { - this.name = name; - } - - @Override - public String toString() { - return name; - } - } } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/FilterTypesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/FilterTypesConfig.java index c50a04bae2b6..ae41eae19e94 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/FilterTypesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/FilterTypesConfig.java @@ -13,6 +13,11 @@ public class FilterTypesConfig { @Accordion public PowderMiningFilterConfig powderMiningFilter = new PowderMiningFilterConfig(); + @Expose + @ConfigOption(name = "Stash Messages", desc = "") + @Accordion + public StashConfig stashMessages = new StashConfig(); + @Expose @ConfigOption(name = "Hypixel Lobbies", desc = "Hide announcements in Hypixel lobbies " + "(player joins, loot boxes, prototype lobby messages, radiating generosity, Hypixel tournaments)") 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 new file mode 100644 index 000000000000..06832e9cb49e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java @@ -0,0 +1,37 @@ +package at.hannibal2.skyhanni.config.features.chat; + +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class StashConfig { + + @Expose + @ConfigOption(name = "Stash Warnings", desc = "Compact or hide warnings relating to items/materials in your stash.") + @ConfigEditorDropdown + public StashHandlerType stashWarnings = StashHandlerType.COMPACT; + + public enum StashHandlerType { + NONE("None (Use Hypixel messages)"), + COMPACT("Compact Messages"), + HIDE("Hide Completely"), + ; + + private final String name; + + StashHandlerType(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + } + + @Expose + @ConfigOption(name = "Use /ViewStash", desc = "Use /viewstash [type] instead of /pickupstash.") + @ConfigEditorBoolean + public boolean useViewStash = false; +} 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 8d6545a3463e..82b9bd6ce45b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -1,11 +1,12 @@ package at.hannibal2.skyhanni.features.chat import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.config.features.chat.ChatConfig +import at.hannibal2.skyhanni.config.features.chat.StashConfig import at.hannibal2.skyhanni.events.LorenzChatEvent 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.RegexUtils.groupOrNull import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches @@ -59,7 +60,7 @@ object StashCompact { // - private val config get() = SkyHanniMod.feature.chat + private val config get() = SkyHanniMod.feature.chat.filterType.stashMessages private var lastMaterialCount = 0 private var lastDifferingMaterialsCount = 0 @@ -109,17 +110,18 @@ object StashCompact { } private fun sendCompactedStashMessage() { - if (config.stashWarnings == ChatConfig.StashHandlerType.HIDE) return + if (config.stashWarnings == StashConfig.StashHandlerType.HIDE) return ChatUtils.clickableChat( "§7You have §3${lastMaterialCount} §7${StringUtils.pluralize(lastMaterialCount, lastType)} in stash, " + "§8totalling $lastDifferingMaterialsCount ${StringUtils.pluralize(lastDifferingMaterialsCount, "type")}§7. " + "§3Click to pickup§7.", onClick = { - HypixelCommands.pickupStash() + if (config.useViewStash) HypixelCommands.viewStash(lastType) + else HypixelCommands.pickupStash() }, prefix = false, ) } - private fun isEnabled() = config.stashWarnings != ChatConfig.StashHandlerType.NONE + private fun isEnabled() = LorenzUtils.inSkyBlock && config.stashWarnings != StashConfig.StashHandlerType.NONE } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt index cfbc5fba0fce..b163a8d393ec 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt @@ -162,6 +162,10 @@ object HypixelCommands { send("pickupstash") } + fun viewStash(type: String) { + send("viewstash $type") + } + private fun send(command: String) { @Suppress("DEPRECATION") // TODO rename function From 07ebba1e008398b9cdd62025e09b6ac887fe1032 Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Fri, 11 Oct 2024 10:50:15 -0400 Subject: [PATCH 09/12] More options, better configs --- .../config/features/chat/StashConfig.java | 34 ++++++++----------- .../skyhanni/features/chat/StashCompact.kt | 23 +++++-------- 2 files changed, 22 insertions(+), 35 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 06832e9cb49e..92fdd8c4405d 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 @@ -1,34 +1,28 @@ package at.hannibal2.skyhanni.config.features.chat; +import at.hannibal2.skyhanni.config.FeatureToggle; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; -import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; public class StashConfig { @Expose - @ConfigOption(name = "Stash Warnings", desc = "Compact or hide warnings relating to items/materials in your stash.") - @ConfigEditorDropdown - public StashHandlerType stashWarnings = StashHandlerType.COMPACT; - - public enum StashHandlerType { - NONE("None (Use Hypixel messages)"), - COMPACT("Compact Messages"), - HIDE("Hide Completely"), - ; - - private final String name; + @ConfigOption(name = "Stash Warnings", desc = "Compact warnings relating to items/materials in your stash.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = true; - StashHandlerType(String name) { - this.name = name; - } + @Expose + @ConfigOption(name = "Hide Duplicate Warnings", desc = "Hide duplicate warnings for previously reported stash counts.") + @ConfigEditorBoolean + public boolean hideDuplicateCounts = true; - @Override - public String toString() { - return name; - } - } + @Expose + @ConfigOption(name = "Hide Low Warnings", desc = "Hide warnings with a total count below this number.") + @ConfigEditorSlider(minValue = 0, maxValue = 1000000, minStep = 100) + public int hideLowWarningsThreshold = 0; @Expose @ConfigOption(name = "Use /ViewStash", desc = "Use /viewstash [type] instead of /pickupstash.") 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 82b9bd6ce45b..506341e1576c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -1,7 +1,6 @@ package at.hannibal2.skyhanni.features.chat import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.config.features.chat.StashConfig import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils @@ -57,7 +56,6 @@ object StashCompact { "generic", "§eOne or more (?:item|material)s? didn't fit in your inventory and were added to your (?:item|material) stash! §6Click here §eto pick them up!", ) - // private val config get() = SkyHanniMod.feature.chat.filterType.stashMessages @@ -67,7 +65,6 @@ object StashCompact { private var lastType = "" private var lastSentMaterialCount = 0 - private var lastSentDifferingMaterialsCount = 0 private var lastSentType = "" @SubscribeEvent @@ -97,31 +94,27 @@ object StashCompact { if (pickupStashPattern.matches(event.message)) { event.blockedReason = "stash_compact" - if (lastMaterialCount != lastSentMaterialCount || - lastDifferingMaterialsCount != lastSentDifferingMaterialsCount || - lastType != lastSentType - ) { - sendCompactedStashMessage() - lastSentMaterialCount = lastMaterialCount - lastSentDifferingMaterialsCount = lastDifferingMaterialsCount - lastSentType = lastType - } + if (lastMaterialCount <= config.hideLowWarningsThreshold) return + if (config.hideDuplicateCounts && lastMaterialCount == lastSentMaterialCount && lastType == lastSentType) return + + sendCompactedStashMessage() } } private fun sendCompactedStashMessage() { - if (config.stashWarnings == StashConfig.StashHandlerType.HIDE) return ChatUtils.clickableChat( "§7You have §3${lastMaterialCount} §7${StringUtils.pluralize(lastMaterialCount, lastType)} in stash, " + "§8totalling $lastDifferingMaterialsCount ${StringUtils.pluralize(lastDifferingMaterialsCount, "type")}§7. " + - "§3Click to pickup§7.", + "§3Click to ${if(config.useViewStash) "view stash" else "pickup stash"}p§7.", onClick = { if (config.useViewStash) HypixelCommands.viewStash(lastType) else HypixelCommands.pickupStash() }, prefix = false, ) + lastSentMaterialCount = lastMaterialCount + lastSentType = lastType } - private fun isEnabled() = LorenzUtils.inSkyBlock && config.stashWarnings != StashConfig.StashHandlerType.NONE + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled } From d44964a459b7cbcc4dd16e1ec549d8d37fe22c31 Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Fri, 11 Oct 2024 11:00:06 -0400 Subject: [PATCH 10/12] p? --- .../java/at/hannibal2/skyhanni/features/chat/StashCompact.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 506341e1576c..428902c24612 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -105,7 +105,7 @@ object StashCompact { ChatUtils.clickableChat( "§7You have §3${lastMaterialCount} §7${StringUtils.pluralize(lastMaterialCount, lastType)} in stash, " + "§8totalling $lastDifferingMaterialsCount ${StringUtils.pluralize(lastDifferingMaterialsCount, "type")}§7. " + - "§3Click to ${if(config.useViewStash) "view stash" else "pickup stash"}p§7.", + "§3Click to ${if(config.useViewStash) "view stash" else "pickup stash"}§7.", onClick = { if (config.useViewStash) HypixelCommands.viewStash(lastType) else HypixelCommands.pickupStash() From 34df2863e570342c37440e08296309d933855c58 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 13 Oct 2024 16:16:26 +0200 Subject: [PATCH 11/12] code cleanup --- .../at/hannibal2/skyhanni/features/chat/StashCompact.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 428902c24612..8617dc193215 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -25,7 +25,7 @@ object StashCompact { */ private val materialCountPattern by patternGroup.pattern( "material.count", - "§f *§7You have §3(?[\\d,]+) (§.)+(?item|material)s? stashed away!.*", + "§f *§7You have §3(?[\\d,]+) (?:§.)+(?item|material)s? stashed away!.*", ) /** @@ -102,10 +102,11 @@ object StashCompact { } private fun sendCompactedStashMessage() { + val name = StringUtils.pluralize(lastMaterialCount, lastType) + val total = StringUtils.pluralize(lastDifferingMaterialsCount, "type") ChatUtils.clickableChat( - "§7You have §3${lastMaterialCount} §7${StringUtils.pluralize(lastMaterialCount, lastType)} in stash, " + - "§8totalling $lastDifferingMaterialsCount ${StringUtils.pluralize(lastDifferingMaterialsCount, "type")}§7. " + - "§3Click to ${if(config.useViewStash) "view stash" else "pickup stash"}§7.", + "§7You have §3${lastMaterialCount} §7$name in stash, §8totalling $lastDifferingMaterialsCount $total§7. " + + "§3Click to ${if (config.useViewStash) "view" else "pickup"} stash§7.", onClick = { if (config.useViewStash) HypixelCommands.viewStash(lastType) else HypixelCommands.pickupStash() From 1dca79a8fd0428f7bd5491d1b6e7537e7ad01f31 Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:03:25 -0400 Subject: [PATCH 12/12] Formatting --- .../skyhanni/features/chat/StashCompact.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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 8617dc193215..29a2689287bb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt @@ -6,6 +6,7 @@ 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.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches @@ -16,7 +17,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @SkyHanniModule object StashCompact { - // + // private val patternGroup = RepoPattern.group("stash.compact") /** @@ -56,7 +57,7 @@ object StashCompact { "generic", "§eOne or more (?:item|material)s? didn't fit in your inventory and were added to your (?:item|material) stash! §6Click here §eto pick them up!", ) - // + // private val config get() = SkyHanniMod.feature.chat.filterType.stashMessages @@ -76,14 +77,14 @@ object StashCompact { } materialCountPattern.matchMatcher(event.message) { - groupOrNull("count")?.replace(",", "")?.toIntOrNull()?.let { count -> + groupOrNull("count")?.formatIntOrNull()?.let { count -> lastMaterialCount = count } event.blockedReason = "stash_compact" } differingMaterialsCountPattern.matchMatcher(event.message) { - groupOrNull("count")?.replace(",", "")?.toIntOrNull()?.let { count -> + groupOrNull("count")?.formatIntOrNull()?.let { count -> lastDifferingMaterialsCount = count } groupOrNull("type")?.let { type -> @@ -102,16 +103,16 @@ object StashCompact { } private fun sendCompactedStashMessage() { - val name = StringUtils.pluralize(lastMaterialCount, lastType) - val total = StringUtils.pluralize(lastDifferingMaterialsCount, "type") + val typeNameFormat = StringUtils.pluralize(lastMaterialCount, lastType) + val typeFormat = StringUtils.pluralize(lastDifferingMaterialsCount, "type") ChatUtils.clickableChat( - "§7You have §3${lastMaterialCount} §7$name in stash, §8totalling $lastDifferingMaterialsCount $total§7. " + - "§3Click to ${if (config.useViewStash) "view" else "pickup"} stash§7.", + "§eYou have §6${lastMaterialCount} §e$typeNameFormat in stash§6, " + + "§etotalling §6$lastDifferingMaterialsCount $typeFormat§6. " + + "§eClick to ${if (config.useViewStash) "§6view" else "§6pickup"} §estash§6.", onClick = { if (config.useViewStash) HypixelCommands.viewStash(lastType) else HypixelCommands.pickupStash() }, - prefix = false, ) lastSentMaterialCount = lastMaterialCount lastSentType = lastType