aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorDavid Cole <40234707+DavidArthurCole@users.noreply.github.com>2024-10-13 15:29:12 -0400
committerGitHub <noreply@github.com>2024-10-13 21:29:12 +0200
commit5fd54d529382fe44d129bd09c4c1f3e22125e9e1 (patch)
tree336245fc5836f4f7abf1b4f859db901ca13e2491 /src/main/java/at
parent3293490627911421dd8fa5afd124045f5319c922 (diff)
downloadskyhanni-5fd54d529382fe44d129bd09c4c1f3e22125e9e1.tar.gz
skyhanni-5fd54d529382fe44d129bd09c4c1f3e22125e9e1.tar.bz2
skyhanni-5fd54d529382fe44d129bd09c4c1f3e22125e9e1.zip
Feature: Stash Warning Compact (#2639)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/chat/FilterTypesConfig.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java31
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt122
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt8
4 files changed, 166 insertions, 0 deletions
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 c50a04bae..ae41eae19 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
@@ -14,6 +14,11 @@ public class FilterTypesConfig {
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)")
@ConfigEditorBoolean
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 000000000..92fdd8c44
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java
@@ -0,0 +1,31 @@
+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.ConfigEditorSlider;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
+
+public class StashConfig {
+
+ @Expose
+ @ConfigOption(name = "Stash Warnings", desc = "Compact warnings relating to items/materials in your stash.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean enabled = 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)
+ public int hideLowWarningsThreshold = 0;
+
+ @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
new file mode 100644
index 000000000..29a268928
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt
@@ -0,0 +1,122 @@
+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.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
+import at.hannibal2.skyhanni.utils.StringUtils
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+@SkyHanniModule
+object StashCompact {
+
+ // <editor-fold desc="Patterns">
+ private val patternGroup = RepoPattern.group("stash.compact")
+
+ /**
+ * 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(?<count>[\\d,]+) (?:§.)+(?<type>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!)
+ * 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",
+ "§f *§8\\(This totals (?<count>[\\d,]+) types? of (?<type>item|material)s? 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|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!
+ */
+ @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!",
+ )
+ // </editor-fold>
+
+ private val config get() = SkyHanniMod.feature.chat.filterType.stashMessages
+
+ private var lastMaterialCount = 0
+ private var lastDifferingMaterialsCount = 0
+ private var lastType = ""
+
+ private var lastSentMaterialCount = 0
+ private var lastSentType = ""
+
+ @SubscribeEvent
+ fun onChat(event: LorenzChatEvent) {
+ if (!isEnabled()) return
+
+ genericAddedToStashPattern.matchMatcher(event.message) {
+ event.blockedReason = "stash_compact"
+ }
+
+ materialCountPattern.matchMatcher(event.message) {
+ groupOrNull("count")?.formatIntOrNull()?.let { count ->
+ lastMaterialCount = count
+ }
+ event.blockedReason = "stash_compact"
+ }
+
+ differingMaterialsCountPattern.matchMatcher(event.message) {
+ groupOrNull("count")?.formatIntOrNull()?.let { count ->
+ lastDifferingMaterialsCount = count
+ }
+ groupOrNull("type")?.let { type ->
+ lastType = type
+ }
+ 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
+
+ sendCompactedStashMessage()
+ }
+ }
+
+ private fun sendCompactedStashMessage() {
+ val typeNameFormat = StringUtils.pluralize(lastMaterialCount, lastType)
+ val typeFormat = StringUtils.pluralize(lastDifferingMaterialsCount, "type")
+ ChatUtils.clickableChat(
+ "§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()
+ },
+ )
+ lastSentMaterialCount = lastMaterialCount
+ lastSentType = lastType
+ }
+
+ private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt
index c148e93e8..b163a8d39 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt
@@ -158,6 +158,14 @@ object HypixelCommands {
send("cb $uuid")
}
+ fun pickupStash() {
+ send("pickupstash")
+ }
+
+ fun viewStash(type: String) {
+ send("viewstash $type")
+ }
+
private fun send(command: String) {
@Suppress("DEPRECATION")
// TODO rename function