import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { HeartAbilityManager } from "../systems/index";
export async function endermanAbility(player) {
    utils.mclog(`enderman`);
    utils.runCommand(`particle ldz:enderman_ability_warp ~ ~ ~`, player);
    mc.world.playSound('ability.endermen.teleport', player.location);
    await utils.waitForEvent(5, () => {
        var _a, _b, _c;
        const location = (_a = player.getSpawnPoint()) !== null && _a !== void 0 ? _a : mc.world.getDefaultSpawnLocation();
        player.teleport(location, { dimension: (_c = (_b = player.getSpawnPoint()) === null || _b === void 0 ? void 0 : _b.dimension) !== null && _c !== void 0 ? _c : utils.overworld });
        utils.runCommand(`particle ldz:enderman_ability_warp ~ ~ ~`, player);
        HeartAbilityManager.addInvulnerability(player, 'noFallDamage');
    });
    await utils.waitForEvent(5, () => { });
    await utils.waitForLoopEvent(0, () => {
        return player.hasTag('onGround');
    });
    utils.waitForEvent(5, () => {
        HeartAbilityManager.removeInvulnerability(player, 'noFallDamage');
    });
}
