Skip to content

Commit

Permalink
Feature: Hoppity Purse Blocker (#2664)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidArthurCole authored Oct 16, 2024
1 parent a428543 commit a33034e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -59,13 +63,22 @@ 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
private var nextWarningTime: Instant? = null
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) {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 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,10 @@ object HypixelCommands {
send("cb $uuid")
}

fun bank() {
send("bank")
}

fun pickupStash() {
send("pickupstash")
}
Expand Down

0 comments on commit a33034e

Please sign in to comment.