import { world } from "@minecraft/server";
import { getChunkId } from "../utils";
import { SettingsHandler } from "./settings";
export function nightVisionPulse(block) {
    // Check if night vision sponge is enabled
    if (!SettingsHandler.isSpongeEnabled("nightVisionSponge")) {
        world.getDimension(block.dimension.id).runCommand(`setblock ${block.location.x} ${block.location.y} ${block.location.z} air destroy`);
        // Notify nearby players
        const nearbyPlayers = world.getDimension(block.dimension.id).getPlayers({ location: block.location, maxDistance: 10 });
        for (const player of nearbyPlayers) {
            player.sendMessage("§cNight Vision Sponge is disabled in settings!");
        }
        return;
    }
    const chunkId = getChunkId(block.location);
    const players = world.getAllPlayers().filter((p) => {
        const location = getChunkId(p.location);
        if (location === chunkId) {
            return p;
        }
    });
    const pos = block.location;
    world.getDimension(block.dimension.id).spawnParticle("wildphire_spg:night_vision_sponge_particle", { x: pos.x + 0.5, y: pos.y, z: pos.z + 0.5 });
    world.getDimension(block.dimension.id).playSound("beacon.ambient", pos);
    for (const player of players) {
        player.addEffect("minecraft:night_vision", 320);
    }
}
