Files
TCOWW/src/main/kotlin/fr/azur/tcoww/commands/TimeGest.kt
2025-06-28 14:53:52 +02:00

44 lines
1.5 KiB
Kotlin

package fr.azur.tcoww.commands
import com.mojang.brigadier.Command
import com.mojang.brigadier.builder.LiteralArgumentBuilder
import fr.azur.tcoww.game.TimeGestion
import io.papermc.paper.command.brigadier.CommandSourceStack
import io.papermc.paper.command.brigadier.Commands
import org.bukkit.Bukkit
import org.bukkit.plugin.Plugin
import org.bukkit.scheduler.BukkitTask
class TimeGest {
var timeGestion: TimeGestion? = null
var sheduler: BukkitTask? = null
var plugin: Plugin? = null
private fun kill() {
sheduler?.cancel()
sheduler = null
timeGestion = null
}
val root: LiteralArgumentBuilder<CommandSourceStack> = Commands.literal("timegest")
.requires { sender ->
sender.sender.isOp
}.then(
Commands.literal("start").executes { ctx ->
if (plugin == null) plugin = Bukkit.getPluginManager().getPlugin("tcoww")!!
val executor = ctx.source.executor
if (executor == null) throw Error("No executor !")
if (timeGestion != null || sheduler != null) kill()
timeGestion = TimeGestion(plugin!!, executor.world)
sheduler = Bukkit.getScheduler().runTaskTimer(plugin!!, Runnable {
timeGestion!!.tick()
}, 0L, 1L)
Command.SINGLE_SUCCESS
}
).then(
Commands.literal("kill").executes {
kill()
Command.SINGLE_SUCCESS
}
)
}