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: Hoppity Purse Blocker #2664

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
DavidArthurCole marked this conversation as resolved.
Show resolved Hide resolved
if (!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",
DavidArthurCole marked this conversation as resolved.
Show resolved Hide resolved
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")
}

private fun send(command: String) {
@Suppress("DEPRECATION")
// TODO rename function
Expand Down
Loading