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: Chocolate Factory Booster Cookie Blocker #2713

Merged
merged 4 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -232,6 +232,12 @@ public class ChocolateFactoryConfig {
@FeatureToggle
public boolean mythicRabbitRequirement = false;

@Expose
@ConfigOption(name = "Booster Cookie", desc = "Blocks running /cf without a §6§lBooster Cookie §7active.")
@ConfigEditorBoolean
@FeatureToggle
public boolean boosterCookieRequirement = false;

@Expose
@ConfigOption(name = "Stray Tracker", desc = "Track stray rabbits found in the Chocolate Factory menu.")
@ConfigEditorBoolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.inventory.chocolatefactory

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.MessageSendToServerEvent
import at.hannibal2.skyhanni.features.event.hoppity.MythicRabbitPetWarning
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
Expand All @@ -16,6 +17,7 @@ import kotlin.time.Duration.Companion.seconds
@SkyHanniModule
object ChocolateFactoryBlockOpen {
private val config get() = SkyHanniMod.feature.inventory.chocolateFactory
private val profileStorage get() = ProfileStorageData.profileSpecific?.bits

/**
* REGEX-TEST: /cf
Expand All @@ -26,27 +28,41 @@ object ChocolateFactoryBlockOpen {
*/
private val commandPattern by RepoPattern.pattern(
"inventory.chocolatefactory.opencommand",
"\\/(?:cf|(?:chocolate)?factory)(?: .*)?",
"/(?:cf|(?:chocolate)?factory)(?: .*)?",
)

private var commandSentTimer = SimpleTimeMark.farPast()

@SubscribeEvent
fun onCommandSend(event: MessageSendToServerEvent) {
if (!isEnabled()) return
if (!LorenzUtils.inSkyBlock) return
if (!commandPattern.matches(event.message)) return
if (commandSentTimer.passedSince() < 5.seconds) return
if (MythicRabbitPetWarning.correctPet()) return

commandSentTimer = SimpleTimeMark.now()
event.cancel()
ChatUtils.clickToActionOrDisable(
"§cBlocked opening the Chocolate Factory without a §dMythic Rabbit Pet §cequipped!",
config::mythicRabbitRequirement,
actionName = "open pets menu",
action = { HypixelCommands.pet() },
)
if (config.mythicRabbitRequirement && !MythicRabbitPetWarning.correctPet()) {
event.cancelOpen()
ChatUtils.clickToActionOrDisable(
"§cBlocked opening the Chocolate Factory without a §dMythic Rabbit Pet §cequipped!",
config::mythicRabbitRequirement,
actionName = "open pets menu",
action = { HypixelCommands.pet() },
)
} else if (config.boosterCookieRequirement) {
profileStorage?.boosterCookieExpiryTime?.let {
if (it.timeUntil() > 0.seconds) return
event.cancelOpen()
ChatUtils.clickToActionOrDisable(
"§cBlocked opening the Chocolate Factory without a §dBooster Cookie §cactive!",
config::boosterCookieRequirement,
actionName = "open bazaar",
action = { HypixelCommands.bazaar("Booster Cookie") },
DavidArthurCole marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
}

private fun isEnabled() = LorenzUtils.inSkyBlock && config.mythicRabbitRequirement
private fun MessageSendToServerEvent.cancelOpen() {
commandSentTimer = SimpleTimeMark.now()
this.cancel()
}
}
Loading