From 7aea6aa7b3774a3797f68a503eb42e99e88c2e56 Mon Sep 17 00:00:00 2001 From: Clicks <58398364+CuzImClicks@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:14:08 +0200 Subject: Feature: Transfer Cooldown Prevention (#1751) Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: Cal Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../config/features/commands/CommandsConfig.java | 12 +++++ .../skyhanni/features/commands/TransferCooldown.kt | 61 ++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/commands/TransferCooldown.kt (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/commands/CommandsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/commands/CommandsConfig.java index 1747baee6..854ed39cc 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/commands/CommandsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/commands/CommandsConfig.java @@ -47,4 +47,16 @@ public class CommandsConfig { @ConfigEditorBoolean @FeatureToggle public boolean viewRecipeLowerCase = true; + + @Expose + @ConfigOption(name = "Fix Transfer Cooldown", desc = "Waits for the transfer cooldown to complete if you try to warp.") + @ConfigEditorBoolean + @FeatureToggle + public boolean transferCooldown = false; + + @Expose + @ConfigOption(name = "Transfer Cooldown Ended Message", desc = "Sends a message in chat when the transfer cooldown ends.") + @ConfigEditorBoolean + @FeatureToggle + public boolean transferCooldownMessage = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/TransferCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/TransferCooldown.kt new file mode 100644 index 000000000..2a9c70cd9 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/TransferCooldown.kt @@ -0,0 +1,61 @@ +package at.hannibal2.skyhanni.features.commands + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.MessageSendToServerEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.HypixelCommands +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +@SkyHanniModule +object TransferCooldown { + + private val config get() = SkyHanniMod.feature.misc.commands + private var lastRunCompleted: SimpleTimeMark = SimpleTimeMark.farPast() + private var action: (() -> Unit)? = null + + @SubscribeEvent + fun onWorldLoad(event: LorenzWorldChangeEvent) { + if (!config.transferCooldown || lastRunCompleted.isInFuture()) return + lastRunCompleted = DelayedRun.runDelayed(3.seconds) { + if (config.transferCooldownMessage && LorenzUtils.inSkyBlock) { + ChatUtils.chat("§aPlayer Transfer Cooldown has ended.") + } + action?.invoke() + action = null + } + } + + @SubscribeEvent + fun onCommand(event: MessageSendToServerEvent) { + if (!LorenzUtils.inSkyBlock || !config.transferCooldown || lastRunCompleted.isInPast()) return + when (event.splitMessage[0]) { + "/is" -> { + event.cancel() + action = { HypixelCommands.island() } + } + + "/warp" -> { + event.cancel() + action = { + HypixelCommands.warp(event.splitMessage.subList(1, event.splitMessage.size).joinToString(" ")) + } + } + + "/warpforge" -> { + event.cancel() + action = { HypixelCommands.warp("forge") } + } + + "/hub" -> { + event.cancel() + action = { HypixelCommands.warp("hub") } + } + } + } +} -- cgit