Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Stash Warning Compact #2639

Merged
merged 14 commits into from
Oct 13, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
122 changes: 122 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/features/chat/StashCompact.kt
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading