const GLOBAL_COOLDOWN = 3000; 
const MOB_COMMANDS = [
    {
        command: "dragon",
        entities: ["minecraft:ender_dragon"],
        successMsg: "All Dragons were successfully killed.",
        failMsg: "No Dragons were found."
    },
    {
        command: "wither",
        entities: ["minecraft:wither"],
        successMsg: "All Withers were successfully killed.",
        failMsg: "No Withers were found."
    },
    {
        command: "ghast",
        entities: ["minecraft:ghast", "minecraft:vex", "halloween_luckyblock:ghost"],
        successMsg: "All Ghosts were successfully killed.",
        failMsg: "No Ghosts were found."
    },
    {
        command: "warden",
        entities: ["minecraft:warden"],
        successMsg: "All Wardens were successfully killed.",
        failMsg: "No Wardens were found."
    }
];
ServerEvents.commandRegistry(event => {
    const { commands: Commands } = event;
    MOB_COMMANDS.forEach(config => {
        event.register(
            Commands.literal(config.command)
            .requires(src => src.hasPermission(0))
            .executes(ctx => {
                const player = ctx.source.player;
                if (!player) return 0;
                const now = Date.now();
                const cooldownKey = `lastKillTime_${config.command}`;
                const lastUsed = player.persistentData[cooldownKey] || 0;
                if (now - lastUsed < GLOBAL_COOLDOWN) {
                    const remaining = ((GLOBAL_COOLDOWN - (now - lastUsed)) / 1000).toFixed(1);
                    player.tell(`§cYou must wait §e${remaining}s §cbefore using this command again!`);
                    return 0;
                }
                const server = player.server;
                let totalKilled = 0;
                for (let entityType of config.entities) {
                    totalKilled += server.runCommandSilent(`kill @e[type=${entityType}]`);
                }
                player.persistentData[cooldownKey] = now;
                if (totalKilled > 0) {
                    player.tell(Text.green(config.successMsg));
                } else {
                    player.tell(Text.red(config.failMsg));
                }
                return 1;
            })
        );
    });
});