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