diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/commands/CommandsConfig.java | 12 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/commands/TransferCooldown.kt | 61 |
2 files changed, 73 insertions, 0 deletions
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") } + } + } + } +} |