ServerEvents.commandRegistry(event => {
    const { commands: Commands } = event
    const KOFI_LINK = "https://ko-fi.com/xfeneq" 
    const COOLDOWN_KEY = "lastKofiTime"
    event.register(
        Commands.literal('kofi')
        .requires(src => src.hasPermission(0))
        .executes(ctx => {
            const player = ctx.source.player
            if (!player) return 0
            const now = Date.now()
            const cooldown = 1000
            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 kofiMessage = [
                "",
                { "text": "\u2560\u2550\u2550\u2550\u2550\u2550\u2563", "color": "gold" },
                { "text": "Ko-Fi", "bold": true, "color": "red" },
                { "text": "\u2560\u2550\u2550\u2550\u2550\u2550\u2563", "color": "gold" },
                { "text": "\n\n \u0020\u0020 " },
                { 
                    "text": "Click Here To Check", 
                    "bold": true, 
                    "underlined": true, 
                    "color": "green", 
                    "clickEvent": { "action": "open_url", "value": KOFI_LINK } 
                },
                { "text": "\n\n" },
                { "text": "\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563", "color": "gold" }
            ];
            const rawCommand = `/tellraw @a ${JSON.stringify(kofiMessage)}`
            server.runCommandSilent(rawCommand)
            return 1
        })
    )
})