import { EquipmentSlot, world, system, EntityComponentTypes } from "@minecraft/server";

// Función para aplicar efectos a los jugadores que tienen un ítem específico en el pecho
function applyEffectsToPlayers() {
    const players = world.getPlayers();

    for (const player of players) {
        try {
            // Accede al componente "equippable"
            const equipmentCompPlayer = player.getComponent(EntityComponentTypes.Equippable);
            const chestItem = equipmentCompPlayer.getEquipmentSlot(EquipmentSlot.Chest);
            const legsItem = equipmentCompPlayer.getEquipmentSlot(EquipmentSlot.Legs);
            if (chestItem && chestItem.typeId === "aft_pb:face") {
                // Aplica los efectos si el ítem equipado es el deseado
                player.runCommand(`effect @s regeneration 3 1 false`);
                player.runCommand(`effect @s strength 3 1 false`);
            }
        } catch (error) {
        }
        try {
            const equipmentCompPlayer = player.getComponent(EntityComponentTypes.Equippable);
            const legsItem = equipmentCompPlayer.getEquipmentSlot(EquipmentSlot.Legs);
            if (legsItem && legsItem.typeId === "aft_pb:pet_block_rope") {
                // Aplica los efectos si el ítem equipado es el deseado
                player.runCommand(`effect @s jump_boost 3 1 false`);
            }
        } catch (error) {
        }
    }
}

// Ejecuta el chequeo cada 10 ticks (medio segundo)
system.runInterval(applyEffectsToPlayers, 10);
