I have tried doing the following:
import { world } from "@minecraft/server";
world.afterEvents.itemStartUse.subscribe((e) => {
let { itemStack, source } = e;
if (itemStack.typeId != 'minecraft:crossbow') return;
source.setDynamicProperty('adv:charging', true);
source.sendMessage('charging');
})
world.afterEvents.itemStopUse.subscribe((e) => {
let { itemStack, source } = e;
if (itemStack.typeId != 'minecraft:crossbow') return;
source.setDynamicProperty('adv:charging', false);
source.sendMessage('charged');
})
world.afterEvents.itemUse.subscribe((e) => {
let { itemStack, source } = e;
if (itemStack.typeId != 'minecraft:crossbow') return;
if (source.getDynamicProperty('adv:charging')) return;
source.sendMessage(`used charged item!`);
})
..However, it seems like itemUse is being triggered before the itemStartUse event and is not enough time for the property adv:charging to be checked. Is there a way to delay the itemUse event to check if the player is charging for a crossbow, and if not, then run the code.