ServerEvents.commandRegistry(event => {
    const { commands: Commands } = event
    const COOLDOWN_KEY = "lastGhastTime"
    const COOLDOWN = 3000
    event.register(
        Commands.literal('ghast')
        .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
            const pName = player.username
            server.runCommandSilent(`execute as ${pName} run execute if entity @e[type=minecraft:ghast] run tellraw @s {"text":"All ghosts were successfully killed.","color":"green"}`)
            server.runCommandSilent(`execute as ${pName} run execute unless entity @e[type=minecraft:ghast] run tellraw @s {"text":"No ghosts were found.","color":"red"}`)
            server.runCommandSilent('kill @e[type=minecraft:ghast]')
            server.runCommandSilent('kill @e[type=minecraft:vex]')
            server.runCommandSilent('kill @e[type=halloween_luckyblock:ghost]')
            return 1
        })
    )
})