import * as utils from "../../utils/index";
import { WornHat } from "../worn_hat";
class PlungerHat extends WornHat {
    constructor() {
        super(...arguments);
        this.hatTypeId = "ldz_crcomp:hat_plunger";
        this.cachedPlayerList = [];
    }
    async onEquip() {
        const wearer = this.hatWearer.Entity;
        utils.waitForLoopEvent(20, () => {
            if (wearer.isValid()) {
                const query = { type: "minecraft:player", location: wearer.location, maxDistance: 16 };
                this.cachedPlayerList = [];
                utils.getEntitiesSafe(wearer.dimension, query).forEach(player => {
                    if (player.id === wearer.id)
                        return;
                    player.addEffect("health_boost", 1200, { amplifier: 4, showParticles: false });
                    this.cachedPlayerList.push(player);
                });
            }
            return false;
        }, this.cancelCategory);
    }
    async onUnequip() {
        utils.abortEvents(this.cancelCategory);
        this.cachedPlayerList.forEach(player => {
            player.removeEffect("health_boost");
        });
    }
}
WornHat.HatTable["ldz_crcomp:hat_plunger"] = PlungerHat;
