import { BlockPermutation, world } from "@minecraft/server";
import { SettingsHandler } from "./settings";
let effectsSpongeMap = new Map();
export function effectsSpongePulse(block) {
    // Check if effects sponge is enabled
    if (!SettingsHandler.isSpongeEnabled("effectsSponge")) {
        block.setPermutation(BlockPermutation.resolve("minecraft:air"));
        // Notify nearby players
        const nearbyPlayers = world.getDimension(block.dimension.id).getPlayers({ location: block.location, maxDistance: 10 });
        for (const player of nearbyPlayers) {
            player.sendMessage("§cEffects Sponge is disabled in settings!");
        }
        return;
    }
    const blockId = `${block.location.x}_${block.location.y}_${block.location.z}`;
    if (!effectsSpongeMap.has(blockId)) {
        effectsSpongeMap.set(blockId, Date.now() + (15 * 1000));
    }
    else {
        const time = effectsSpongeMap.get(blockId);
        if (time != undefined && time < Date.now()) {
            effectsSpongeMap.delete(blockId);
            block.setPermutation(BlockPermutation.resolve("minecraft:air"));
        }
    }
    // Get players within 10 blocks
    const players = world.getDimension(block.dimension.id).getEntities({ maxDistance: 10, type: "minecraft:player", location: block.location });
    if (players.length == 0)
        return;
    for (const player of players) {
        // Remove all effects from the player
        for (const effect of player.getEffects()) {
            player.removeEffect(effect.typeId);
        }
        // Spawn feeding particle on block every time effects are cleared
    }
    world.getDimension(block.dimension.id).spawnParticle("wildphire_spg:effects_sponge_particle", { x: block.location.x + 0.5, y: block.location.y + 0.25, z: block.location.z + 0.5 });
}
