ServerEvents.commandRegistry(event => {
    const { commands: Commands } = event
    const COOLDOWN_KEY = "lastDayTime"
    const COOLDOWN = 3000
    event.register(
        Commands.literal('day')
        .requires(src => src.hasPermission(0))
        .executes(ctx => {
            const player = ctx.source.player
            if (!player) return 0
            const now = Date.now()
            const lastUsed = player.persistentData[COOLDOWN_KEY] || 0
            if (now - lastUsed < COOLDOWN) {
                const remaining = ((COOLDOWN - (now - lastUsed)) / 1000).toFixed(1)
                player.tell(`§cYou must wait §e${remaining}s §cbefore using this command again!`)
                return 0
            }
            player.persistentData[COOLDOWN_KEY] = now
            const server = ctx.source.server
            server.runCommandSilent('time set noon')
            return 1
        })
    )
})