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

        if (cd >= 2) {
            player.runCommand("function lunarfang/lunarcodex");
        }
        else if (cd < 1) {
            player.runCommand("function lunarfang/ccfr");
        }
    }
});