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

// Armor effect on paladin armor
function main() {
	
	for (let player of world.getAllPlayers()) {
		const armorEquipped = player.getComponent(EntityEquippableComponent.componentId)

		const hasHelmet = armorEquipped.getEquipment(EquipmentSlot.Head)?.typeId == "oct_plev:paladin_helmet";
		const hasChestplate = armorEquipped.getEquipment(EquipmentSlot.Chest)?.typeId == "oct_plev:paladin_chestplate";
		const hasLeggings = armorEquipped.getEquipment(EquipmentSlot.Legs)?.typeId == "oct_plev:paladin_leggings";
		const hasBoots = armorEquipped.getEquipment(EquipmentSlot.Feet)?.typeId == "oct_plev:paladin_boots";

		// const hasFullArmor = hasHelmet && hasChestplate && hasLeggings && hasBoots
		// const hasAnyArmor = hasHelmet || hasChestplate || hasLeggings || hasBoots
		const hasThreeParts = ((hasHelmet && hasChestplate && hasLeggings) || (hasHelmet && hasChestplate && hasBoots) || (hasHelmet && hasLeggings && hasBoots) || (hasChestplate && hasLeggings && hasBoots))

		if(hasThreeParts) {
			player.runCommand("/playsound oct_plev.sound.paladin_armor_effect @a ~ ~ ~");
			player.runCommand("/summon oct_plev:regeneration_sphere ~ ~1.5 ~");
			player.runCommand("/particle oct_plev:regeneration_sphere ~ ~ ~");
		}
	}
}
system.runInterval(main, 600);
// system.runInterval(main, 10);