function checkItemCancellable(player, event, itemId)
{
    if(!global.tfc_classes_util.checkIncludes(global.tfc_classes_involved.items, itemId))
    {
        return;
    }

    const playerClass = global.tfc_classes_util.getClassOfPlayer(player);
    if(!playerClass)
    {
        player.displayClientMessage(Component.red("You cannot use this item because you do not have a class selected."), true);
        event.cancel();
        return;
    }

    if(!global.tfc_classes_util.checkIncludes(playerClass.allowed_items, itemId))
    {
        player.displayClientMessage(Component.red("You cannot use this item because you are a " + playerClass.id), true);
        event.cancel();
    }
}

ItemEvents.rightClicked((event) =>
{
    const player = event.player;
    if(!player || !event.item)
    {
        return;
    }

    const itemId = event.item.id;
    checkItemCancellable(player, event, itemId);
});

BlockEvents.rightClicked((event) =>
{
    const player = event.player;
    if(!player || !event.item)
    {
        return;
    }

    const itemId = event.item.id;
    checkItemCancellable(player, event, itemId);
});

BlockEvents.broken((event) =>
{
    const player = event.player;
    if(!player || !event.block)
    {
        return;
    }

    const itemId = player.mainHandItem.id;
    checkItemCancellable(player, event, itemId);
});

const $TriState = Java.loadClass("net.neoforged.neoforge.common.util.TriState");

CuriosJSEvents.canEquip((event) =>
{
    const player = event.entity;
    if(!player || !event.stack)
    {
        return;
    }

    const itemId = event.stack.id;
    if(!global.tfc_classes_util.checkIncludes(global.tfc_classes_involved.items, itemId))
    {
        return;
    }

    const playerClass = global.tfc_classes_util.getClassOfPlayer(player);
    if(!playerClass)
    {
        player.displayClientMessage(Component.red("You cannot equip this item because you do not have a class selected."), true);
        event.setResult($TriState.FALSE);
        return;
    }

    if(!global.tfc_classes_util.checkIncludes(playerClass.allowed_items, itemId))
    {
        player.displayClientMessage(Component.red("You cannot equip this item because you are a " + playerClass.id), true);
        event.setResult($TriState.FALSE);
    }
});