import { world, EquipmentSlot } from "@minecraft/server";
import * as utils from "../utils"

export async function onTick()
{
    try {
        for (const player of world.getPlayers()) {
            const equippable = player.getComponent('equippable');
            if(equippable){
                const head = equippable.getEquipment(EquipmentSlot.Head);
                const chest = equippable.getEquipment(EquipmentSlot.Chest);
                const legs = equippable.getEquipment(EquipmentSlot.Legs);
                const feet = equippable.getEquipment(EquipmentSlot.Feet);
                if(head && chest && legs && feet){
                    if(head.typeId == "pu_sg:fire_dragon_armor_helmet" && chest.typeId == "pu_sg:fire_dragon_armor_chestplate" && legs.typeId == "pu_sg:fire_dragon_armor_leggings" && feet.typeId == "pu_sg:fire_dragon_armor_boots"){
                        utils.runPlayerCommand(player, "effect @s fire_resistance 11 1 true");
                    }
                }
            }
        }
    } catch (e) {
    }
};


export async function onEntityHurt(event) {
    const source = event.damageSource.damagingEntity;
    const entity = event.hurtEntity;
    if (entity?.typeId === "minecraft:player") {
        const equippable = entity.getComponent('equippable');
        if(equippable){
            const head = equippable.getEquipment(EquipmentSlot.Head);
            const chest = equippable.getEquipment(EquipmentSlot.Chest);
            const legs = equippable.getEquipment(EquipmentSlot.Legs);
            const feet = equippable.getEquipment(EquipmentSlot.Feet);
            if(head && chest && legs && feet){
                if(head.typeId == "pu_sg:fire_dragon_armor_helmet" && chest.typeId == "pu_sg:fire_dragon_armor_chestplate" && legs.typeId == "pu_sg:fire_dragon_armor_leggings" && feet.typeId == "pu_sg:fire_dragon_armor_boots"){
                    if(source) {
                        source.setOnFire(5);
                    }
                }
            }
        }
    }
}