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

        if (cd >= 260) {
            player.runCommand("function lunarfang/lunarfield");
        }
        else if (cd < 1) {
            player.runCommand("function lunarfang/lffr");
        }
    }
});