Particles/src/main/java/com/alttd/objects/Frame.java

45 lines
1.8 KiB
Java
Raw Normal View History

package com.alttd.objects;
import com.alttd.storage.PlayerSettings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.util.List;
2022-02-17 01:02:48 +00:00
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
public class Frame {
List<AParticle> AParticles;
public Frame(List<AParticle> AParticles) {
this.AParticles = AParticles;
}
/**
* Spawns all particles in a frame (CALL ASYNC)
*
* @param location Location to spawn particles at
*/
public void spawn(Location location) {
Location tmpLocation = location.clone();
AParticles.forEach(AParticle -> {
2022-02-17 01:02:48 +00:00
ThreadLocalRandom current = ThreadLocalRandom.current();
AParticle.particleBuilder()
2022-02-17 01:02:48 +00:00
.location(tmpLocation.set(location.getX() + AParticle.x() + current.nextDouble(-AParticle.offset_range(), AParticle.offset_range()),
location.getY() + AParticle.y() + current.nextDouble(-AParticle.offset_range(), AParticle.offset_range()),
location.getZ() + AParticle.z() + current.nextDouble(-AParticle.offset_range(), AParticle.offset_range())))
.receivers(Bukkit.getOnlinePlayers().stream()
.filter(player -> {
PlayerSettings playerSettings = PlayerSettings.getPlayer(player.getUniqueId());
if (playerSettings == null)
return false;
if (!playerSettings.isSeeingParticles())
return false;
return player.getLocation().distance(location) < 100;
}).collect(Collectors.toList())
)
.spawn();
});
}
}