diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityCallWarningConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityCallWarningConfig.java index 6e4ccf027305..0406b268d8b8 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityCallWarningConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityCallWarningConfig.java @@ -7,6 +7,7 @@ import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorButton; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorColour; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorText; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; import io.github.notenoughupdates.moulconfig.observer.Property; @@ -44,4 +45,14 @@ public class HoppityCallWarningConfig { @ConfigOption(name = "Sounds", desc = "Click to open the list of available sounds.") @ConfigEditorButton(buttonText = "OPEN") public Runnable sounds = () -> OSUtils.openBrowser("https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/mapping-and-modding-tutorials/2213619-1-8-all-playsound-sound-arguments"); + + @Expose + @ConfigOption(name = "Ensure Coins Pre-Trade", desc = "Block opening Hoppity's abiphone trade menu if you do not have enough coins in your purse.") + @ConfigEditorBoolean + public boolean ensureCoins = true; + + @Expose + @ConfigOption(name = "Coin Threshold", desc = "The amount of coins you need to have in your purse to be able to open Hoppity's abiphone trade menu.") + @ConfigEditorSlider(minValue = 250000, maxValue = 5000000, minStep = 250000) + public int coinThreshold = 5000000; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCallWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCallWarning.kt index 57bc0975fac8..92daf50d4280 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCallWarning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCallWarning.kt @@ -1,18 +1,22 @@ package at.hannibal2.skyhanni.features.event.hoppity +import at.hannibal2.skyhanni.data.PurseAPI import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzKeyPressEvent +import at.hannibal2.skyhanni.events.MessageSendToServerEvent import at.hannibal2.skyhanni.events.SecondPassedEvent import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColorInt import at.hannibal2.skyhanni.utils.ConditionalUtils import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.StringUtils.isValidUuid import net.minecraft.client.Minecraft @@ -59,6 +63,14 @@ object HoppityCallWarning { "§e\\[NPC] §aHoppity§f: §b✆ §f§rWhat's up, .*§f\\?", ) + /** + * REGEX-TEST: /selectnpcoption hoppity r_2_1 + */ + private val pickupOutgoingCommandPattern by ChocolateFactoryAPI.patternGroup.pattern( + "hoppity.call.pickup.outgoing", + "/selectnpcoption hoppity r_2_1", + ) + private val config get() = HoppityEggsManager.config.hoppityCallWarning private var warningSound = SoundUtils.createSound("note.pling", 1f) private var activeWarning = false @@ -66,6 +78,7 @@ object HoppityCallWarning { private var finalWarningTime: Instant? = null private val callLength = 7.seconds private var acceptUUID: String? = null + private var commandSentTimer = SimpleTimeMark.farPast() @SubscribeEvent fun onKeyPress(event: LorenzKeyPressEvent) { @@ -128,6 +141,23 @@ object HoppityCallWarning { GlStateManager.color(1F, 1F, 1F, 1F) } + @SubscribeEvent + fun onCommandSend(event: MessageSendToServerEvent) { + if (!LorenzUtils.inSkyBlock || !config.ensureCoins) return + if (!pickupOutgoingCommandPattern.matches(event.message)) return + if (commandSentTimer.passedSince() < 5.seconds) return + if (PurseAPI.getPurse() >= config.coinThreshold) return + + commandSentTimer = SimpleTimeMark.now() + event.cancel() + ChatUtils.clickToActionOrDisable( + "§cBlocked picking up Hoppity without enough coins!", + config::ensureCoins, + actionName = "open bank menu", + action = { HypixelCommands.bank() }, + ) + } + private fun readPickupUuid(event: LorenzChatEvent) { val siblings = event.chatComponent.siblings.takeIf { it.size >= 3 } ?: return val clickEvent = siblings[2]?.chatStyle?.chatClickEvent ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt index b163a8d393ec..608ba9d8e2ff 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt @@ -158,6 +158,10 @@ object HypixelCommands { send("cb $uuid") } + fun bank() { + send("bank") + } + fun pickupStash() { send("pickupstash") }