diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-05-24 10:46:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-24 10:46:29 +0200 |
commit | 623a9d213df3b1983a6dae416209518dd6904e2b (patch) | |
tree | 222b098e4826dbc009df29896592e74690b61870 | |
parent | 17ac70d7cd8416324acfffcde656930b4e9ae612 (diff) | |
download | skyhanni-623a9d213df3b1983a6dae416209518dd6904e2b.tar.gz skyhanni-623a9d213df3b1983a6dae416209518dd6904e2b.tar.bz2 skyhanni-623a9d213df3b1983a6dae416209518dd6904e2b.zip |
Improvement: Compact Hoppity Chat (#1748)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
6 files changed, 151 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/HoppityEggsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/HoppityEggsConfig.java index 04c915ff0..2bfe65a49 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/HoppityEggsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/HoppityEggsConfig.java @@ -92,4 +92,10 @@ public class HoppityEggsConfig { @ConfigEditorBoolean @FeatureToggle public boolean timeInChat = true; + + @Expose + @ConfigOption(name = "Compact Chat", desc = "Compact chat events when finding a Hoppity Egg.") + @ConfigEditorBoolean + @FeatureToggle + public boolean compactChat = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggType.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggType.kt index fcc647809..d67e9550a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggType.kt @@ -35,6 +35,7 @@ enum class HoppityEggType( fun isClaimed() = claimed val formattedName get() = "${if (isClaimed()) "§7§m" else mealColour}$mealName:$mealColour" + val coloredName get() = "$mealColour$mealName" companion object { fun allFound() = entries.forEach { it.markClaimed() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsCompactChat.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsCompactChat.kt new file mode 100644 index 000000000..21a2e4f7a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsCompactChat.kt @@ -0,0 +1,101 @@ +package at.hannibal2.skyhanni.features.event.hoppity + +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager.getEggType +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.seconds + +object HoppityEggsCompactChat { + + private var hoppityEggChat = mutableListOf<String>() + private var duplicate = false + private var lastRarity = "" + private var lastName = "" + private var lastProfit = "" + private var newRabbit = false + private var lastChatMeal: HoppityEggType? = null + private var lastDuplicateAmount: Long? = null + + fun compactChat(event: LorenzChatEvent, lastDuplicateAmount: Long? = null) { + lastDuplicateAmount?.let { + this.lastDuplicateAmount = it + } + if (!HoppityEggsManager.config.compactChat) return + event.blockedReason = "compact_hoppity" + hoppityEggChat.add(event.message) + if (lastDuplicateAmount != null) { + this.duplicate = true + } + if (hoppityEggChat.size == 3) { + DelayedRun.runDelayed(200.milliseconds) { + sendCompact() + } + } + } + + private fun sendCompact() { + if (hoppityEggChat.isNotEmpty()) { + ChatUtils.hoverableChat(createCompactMessage(), hover = hoppityEggChat, prefix = false) + } + + this.duplicate = false + this.newRabbit = false + lastRarity = "" + lastName = "" + lastProfit = "" + lastChatMeal = null + lastDuplicateAmount = null + } + + private fun createCompactMessage(): String { + val mealName = lastChatMeal?.coloredName ?: "" + + return if (duplicate) { + val format = lastDuplicateAmount?.let { NumberUtil.format(it) } ?: "?" + "$mealName Egg! §7Duplicate $lastName §7(§6+$format Chocolate§7)" + } else if (newRabbit) { + "$mealName Egg! §d§lNEW $lastName §7(${lastProfit}§7)" + } else "?" + } + + fun handleChat(event: LorenzChatEvent) { + HoppityEggsManager.eggFoundPattern.matchMatcher(event.message) { + hoppityEggChat = mutableListOf() + lastChatMeal = getEggType(event) + compactChat(event) + } + + HoppityEggsManager.rabbitFoundPatttern.matchMatcher(event.message) { + lastName = group("name") + lastRarity = group("rarity") + compactChat(event) + } + HoppityEggsManager.newRabbitFound.matchMatcher(event.message) { + val chocolate = group("chocolate") + val perSecond = group("perSecond") + newRabbit = true + lastProfit = "§6+$chocolate §7and §6+${perSecond}x c/s!" + compactChat(event) + } + } + + fun clickableCompact(onClick: () -> Unit): Boolean = if (hoppityEggChat.size > 0) { + val hover = hoppityEggChat.joinToString("\n") + + " \n§eClick here to share the location of this chocolate egg with the server!" + hoppityEggChat.clear() + ChatUtils.clickableChat( + createCompactMessage(), + hover = hover, + onClick = onClick, + expireAt = 30.seconds.fromNow(), + oneTimeClick = true, + prefix = false + ) + true + } else false +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt index 8ee19dda8..e96b2a829 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt @@ -37,10 +37,27 @@ object HoppityEggsManager { * REGEX-TEST: §d§lHOPPITY'S HUNT §r§dYou found a §r§aChocolate Dinner Egg §r§dbehind Emissary Sisko§r§d! * REGEX-TEST: §d§lHOPPITY'S HUNT §r§dYou found a §r§9Chocolate Lunch Egg §r§dnear the Diamond Essence Shop§r§d! */ - private val eggFoundPattern by ChocolateFactoryAPI.patternGroup.pattern( + val eggFoundPattern by ChocolateFactoryAPI.patternGroup.pattern( "egg.found", "§d§lHOPPITY'S HUNT §r§dYou found a §r§.Chocolate (?<meal>\\w+) Egg §r§d(?<note>.*)§r§d!" ) + + /** + * REGEX-TEST: §D§LHOPPITY'S HUNT §7You found §fArnie §7(§F§LCOMMON§7)! + * REGEX-TEST: §D§LHOPPITY'S HUNT §7You found §aPenelope §7(§A§LUNCOMMON§7)! + */ + val rabbitFoundPatttern by ChocolateFactoryAPI.patternGroup.pattern( + "rabbit.found", + "§D§LHOPPITY'S HUNT §7You found (?<name>.*) §7\\((?<rarity>.*)§7\\)!" + ) + + /** + * REGEX-TEST: §d§lNEW RABBIT! §6+2 Chocolate §7and §6+0.003x Chocolate §7per second! + */ + val newRabbitFound by ChocolateFactoryAPI.patternGroup.pattern( + "rabbit.found.new", + "§d§lNEW RABBIT! §6\\+(?<chocolate>.*) Chocolate §7and §6\\+(?<perSecond>.*)x Chocolate §7per second!" + ) private val noEggsLeftPattern by ChocolateFactoryAPI.patternGroup.pattern( "egg.noneleft", "§cThere are no hidden Chocolate Rabbit Eggs nearby! Try again later!" @@ -88,6 +105,8 @@ object HoppityEggsManager { if (!ChocolateFactoryAPI.isHoppityEvent()) return + HoppityEggsCompactChat.handleChat(event) + eggFoundPattern.matchMatcher(event.message) { HoppityEggLocator.eggFound() val meal = getEggType(event) @@ -142,12 +161,15 @@ object HoppityEggsManager { val currentLocation = LocationUtils.playerLocation() DelayedRun.runNextTick { - ChatUtils.clickableChat( - "Click here to share the location of this chocolate egg with the server!", - onClick = { HoppityEggsShared.shareNearbyEggLocation(currentLocation, meal, note) }, - expireAt = 30.seconds.fromNow(), - oneTimeClick = true - ) + val onClick = { HoppityEggsShared.shareNearbyEggLocation(currentLocation, meal, note) } + if (!HoppityEggsCompactChat.clickableCompact(onClick)) { + ChatUtils.clickableChat( + "Click here to share the location of this chocolate egg with the server!", + onClick = onClick, + expireAt = 30.seconds.fromNow(), + oneTimeClick = true + ) + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt index 445c72974..1a82440f6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryBarnManager.kt @@ -1,8 +1,10 @@ package at.hannibal2.skyhanni.features.inventory.chocolatefactory import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsCompactChat import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.formatLong @@ -54,10 +56,12 @@ object ChocolateFactoryBarnManager { val amount = group("amount").formatLong() if (config.showDuplicateTime) { val format = ChocolateFactoryAPI.timeUntilNeed(amount).format(maxUnits = 2) - event.chatComponent.appendText("\n§7(§a+§b$format §aof production§7)") - ChocolateAmount.averageChocPerSecond() + DelayedRun.runNextTick { + ChatUtils.chat("§7(§a+§b$format §aof production§7)") + } } ChocolateAmount.addToAll(amount) + HoppityEggsCompactChat.compactChat(event, lastDuplicateAmount = amount) } rabbitCrashedPattern.matchMatcher(event.message) { diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt index 6d67a9ad0..e5ed69064 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt @@ -47,20 +47,24 @@ object TestChatCommand { } else ChatComponentText(text.replace("&", "§")) if (!isHidden) ChatUtils.chat("Testing message: §7${component.formattedText}", prefixColor = "§a") - test(component) + test(component, isHidden) } - private fun test(componentText: IChatComponent) { + private fun test(componentText: IChatComponent, isHidden: Boolean) { val message = componentText.formattedText.stripHypixelMessage() val event = LorenzChatEvent(message, componentText) event.postAndCatch() if (event.blockedReason != "") { - ChatUtils.chat("§cChat blocked: ${event.blockedReason}") + if (!isHidden) { + ChatUtils.chat("§cChat blocked: ${event.blockedReason}") + } } else { val finalMessage = event.chatComponent if (finalMessage.formattedText.stripHypixelMessage() != message) { - ChatUtils.chat("§eChat modified!") + if (!isHidden) { + ChatUtils.chat("§eChat modified!") + } } ChatUtils.chat(finalMessage) } |