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: Block opening chocolate factory without Mythic Rabbit equipped #2124

Merged
merged 5 commits into from
Jun 20, 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 @@ -146,7 +146,7 @@ public class HoppityEggsConfig {
@Expose
@ConfigOption(
name = "Rabbit Pet Warning",
desc = "Warn when using the Egglocator without having a §d§lMythic Rabbit Pet §7selected. " +
desc = "Warn when using the Egglocator without a §d§lMythic Rabbit Pet §7equipped. " +
"§eOnly enable this setting when you own a mythic Rabbit pet."
)
@ConfigEditorBoolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,9 @@ public class ChocolateFactoryConfig {
@Accordion
public ChocolateFactoryCustomReminderConfig customReminder = new ChocolateFactoryCustomReminderConfig();

@Expose
@ConfigOption(name = "Mythic Rabbit", desc = "Blocks running /cf without a §d§lMythic Rabbit Pet §7equipped.")
@ConfigEditorBoolean
@FeatureToggle
public boolean mythicRabbitRequirement = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ object MythicRabbitPetWarning {

if (lastCheck.passedSince() < 30.seconds) return

if (!PetAPI.isCurrentPet(mythicRabbit)) {
if (!correctPet()) {
lastCheck = SimpleTimeMark.now()
warn()
}
}

fun correctPet() = PetAPI.isCurrentPet(mythicRabbit)

private fun warn() {
ChatUtils.chat("Use a mythic Rabbit pet for more chocolate!")
ChatUtils.chat("Use a §dMythic Rabbit Pet §efor more chocolate!")
LorenzUtils.sendTitle("§cNo Rabbit Pet!", 3.seconds)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package at.hannibal2.skyhanni.features.inventory.chocolatefactory

import at.hannibal2.skyhanni.SkyHanniMod
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.LorenzUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

@SkyHanniModule
object ChocolateFactoryBlockOpen {
private val config get() = SkyHanniMod.feature.inventory.chocolateFactory

/**
* REGEX-TEST: /cf
* REGEX-TEST: /cf test
* REGEX-TEST: /chocolatefactory
* REGEX-TEST: /chocolatefactory123456789
*/
private val commandPattern by RepoPattern.pattern(
"inventory.chocolatefactory.opencommand",
"\\/(?:cf|chocolatefactory)(?: .*)?",
)

private var commandSentTimer = SimpleTimeMark.farPast()

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

commandSentTimer = SimpleTimeMark.now()
event.cancel()
martimavocado marked this conversation as resolved.
Show resolved Hide resolved
ChatUtils.chatAndOpenConfig(
"Blocked opening the Chocolate Factory without a §dMythic Rabbit Pet §eequipped. Click here to disable!",
config::mythicRabbitRequirement,
)
}

private fun isEnabled() = LorenzUtils.inSkyBlock && config.mythicRabbitRequirement
}
Loading