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,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;
}
127 changes: 127 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,127 @@
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
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
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 lastSentDifferingMaterialsCount = 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")?.replace(",", "")?.toIntOrNull()?.let { count ->
DavidArthurCole marked this conversation as resolved.
Show resolved Hide resolved
lastMaterialCount = count
}
event.blockedReason = "stash_compact"
}

differingMaterialsCountPattern.matchMatcher(event.message) {
groupOrNull("count")?.replace(",", "")?.toIntOrNull()?.let { count ->
DavidArthurCole marked this conversation as resolved.
Show resolved Hide resolved
lastDifferingMaterialsCount = count
}
groupOrNull("type")?.let { type ->
lastType = type
}
event.blockedReason = "stash_compact"
}

if (pickupStashPattern.matches(event.message)) {
event.blockedReason = "stash_compact"
if (lastMaterialCount != lastSentMaterialCount ||
lastDifferingMaterialsCount != lastSentDifferingMaterialsCount ||
lastType != lastSentType
) {
sendCompactedStashMessage()
lastSentMaterialCount = lastMaterialCount
lastSentDifferingMaterialsCount = lastDifferingMaterialsCount
lastSentType = lastType
}
}
}

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.",
onClick = {
if (config.useViewStash) HypixelCommands.viewStash(lastType)
else HypixelCommands.pickupStash()
},
prefix = false,
DavidArthurCole marked this conversation as resolved.
Show resolved Hide resolved
)
}

private fun isEnabled() = LorenzUtils.inSkyBlock && config.stashWarnings != StashConfig.StashHandlerType.NONE
}
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