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 all 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,12 +1,17 @@
package at.hannibal2.skyhanni.features.inventory.chocolatefactory

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.EntityMovementData
import at.hannibal2.skyhanni.data.IslandGraphs
import at.hannibal2.skyhanni.data.IslandType
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
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
Expand All @@ -16,6 +21,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 +32,46 @@ 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 = "warp to hub",
action = {
HypixelCommands.warp("hub")
EntityMovementData.onNextTeleport(IslandType.HUB) {
IslandGraphs.pathFind(LorenzVec(-32.5, 71.0, -76.5), "§aBazaar", condition = { true })
}
},
)
}
}
}

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