Skip to content

Commit

Permalink
Feature: Chocolate Factory Booster Cookie Blocker (#2713)
Browse files Browse the repository at this point in the history
Co-authored-by: Cal <cwolfson58@gmail.com>
  • Loading branch information
DavidArthurCole and CalMWolfs authored Oct 13, 2024
1 parent 29a07ad commit 3293490
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
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()
}
}

0 comments on commit 3293490

Please sign in to comment.