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:chaoswhirl") {
        const player = event.source;
        let cd = getScore('chaoswcd', player);

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