import { world } from "@minecraft/server";

function getScore(objectiveName, player) {
    return world.scoreboard.getObjective(objectiveName)?.getScore(player.scoreboardIdentity);
}

world.afterEvents.itemUse.subscribe((event) => {
    if (event.itemStack.typeId == "zk:chaospurge") {
        const player = event.source;
        let cd = getScore('chaospcd', player);

        if (cd >= 400) {
            player.runCommand("function chaoscleaver/chaospurge");
        }
        else if (cd < 400) {
            player.runCommand("function chaoscleaver/ccfr");
        }
    }
});