package de.steamwar.lobby.particle.elements;

import de.steamwar.lobby.particle.ParticleElement;
import de.steamwar.lobby.particle.ParticleTickData;
import org.bukkit.Location;

import java.util.function.UnaryOperator;

public class LocationMutator extends DelegatingParticleElement {

    private UnaryOperator<Location> mutator;

    public LocationMutator(ParticleElement particleElement, UnaryOperator<Location> mutator) {
        super(particleElement);
        this.mutator = mutator;
    }

    public LocationMutator(ParticleElement particleElement, double vx, double vy, double vz) {
        this(particleElement, location -> location.add(vx, vy, vz));
    }

    @Override
    public String attribute() {
        return null;
    }

    @Override
    public void tick(ParticleTickData particleTickData) {
        ParticleTickData nParticleTickData = particleTickData.withLocation(mutator.apply(particleTickData.getLocation()));
        particleElement.tick(nParticleTickData);
    }
}
