Skip to content

Commit

Permalink
added support for addons
Browse files Browse the repository at this point in the history
  • Loading branch information
ILike2WatchMemes committed Jul 12, 2024
1 parent 375e59a commit 30defcb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public String toString() {
public boolean compactBestiaryMessage = true;

@Expose
@ConfigOption(name = "Compact Experiment Rewards", desc = "Compact the rewards gained from Experiments, only showing additional information when hovering.")
@ConfigOption(name = "Compact Experimentation Rewards", desc = "Compact the rewards gained from Add-ons and Experiments, only showing additional information when hovering.")
@ConfigEditorBoolean
@FeatureToggle
public boolean compactEnchantingExp = false;
public boolean compactRewards = false;

@Expose
@ConfigOption(name = "Arachne Hider", desc = "Hide chat messages about the Arachne Fight while outside of §eArachne's Sanctuary§7.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.milliseconds
Expand All @@ -19,10 +18,11 @@ import kotlin.time.Duration.Companion.seconds
@SkyHanniModule
object CompactExperimentRewards {

private val enabled get() = SkyHanniMod.feature.chat.compactEnchantingExp
private val enabled get() = SkyHanniMod.feature.chat.compactRewards

private var gainedRewards = mutableListOf<String>()
private var lastTimeTableOpened = SimpleTimeMark.farPast()
private var currentMessage = ""

/**
* REGEX-TEST: Superpairs (Metaphysical)
Expand All @@ -31,7 +31,17 @@ object CompactExperimentRewards {
private val patternGroup = RepoPattern.group("chat.experiments.compact")
val experimentInventoriesPattern by patternGroup.pattern(
"inventories",
"Superpairs (?:\\(.+\\)|Rewards)",
"(?:Superpairs|Chronomatron|Ultrasequencer) (?:\\(.+\\)|➜ Stakes|Rewards)|Experimentation Table",
)

/**
* REGEX-TEST: §eYou claimed the §r§dUltrasequencer §r§erewards!
* REGEX-TEST: §eYou claimed the §r§cUltrasequencer §r§erewards!
*/

val claimMessagePattern by patternGroup.pattern(
"message",
"(?<message>§eYou claimed the §r§.\\S+ §r§erewards!)",
)

/**
Expand All @@ -45,7 +55,7 @@ object CompactExperimentRewards {

private val experimentsDropPattern by patternGroup.pattern(
"drop",
"^.[^+]+\\+(?<reward>.*)\$",
"^(?:§8 \\+| §r§8\\+)(?<reward>.*)\$",
)

@SubscribeEvent
Expand All @@ -59,30 +69,30 @@ object CompactExperimentRewards {
fun onChat(event: LorenzChatEvent) {
if (!enabled || lastTimeTableOpened.passedSince() >= 3.seconds || event.blockedReason != "") return

if (event.message.removeColor() == "You claimed the Superpairs rewards!") {
event.blockedReason = "COMPACT_REWARDS"
return
}

event.message.let { message ->
claimMessagePattern.matchMatcher(message) {
currentMessage = group("message")
event.blockedReason = "COMPACT_REWARDS"
return
}
experimentsDropPattern.matchMatcher(message) {
val reward = group("reward")

gainedRewards.add(reward)
event.blockedReason = "COMPACT_REWARDS"

DelayedRun.runDelayed(100.milliseconds) {
if (gainedRewards.last() == reward) {
val chatMessage = "§eYou claimed the §dSuperpairs §erewards!"
if (gainedRewards.last() == reward && currentMessage != "") {

val expList = mutableListOf<String>().apply {
gainedRewards.forEach {
add("§8+$it")
}
}

ChatUtils.hoverableChat(chatMessage, expList, null, false)
ChatUtils.hoverableChat(currentMessage, expList, null, false)
gainedRewards.clear()
currentMessage = ""
}
}
}
Expand Down

0 comments on commit 30defcb

Please sign in to comment.