2022-01-11 22:02:04 +00:00
|
|
|
package com.alttd.objects;
|
|
|
|
|
|
2022-01-13 22:43:07 +00:00
|
|
|
import com.alttd.storage.PlayerSettings;
|
|
|
|
|
import org.bukkit.Bukkit;
|
2022-01-11 22:02:04 +00:00
|
|
|
import org.bukkit.Location;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
2022-02-17 01:02:48 +00:00
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
2022-01-13 22:43:07 +00:00
|
|
|
import java.util.stream.Collectors;
|
2022-01-11 22:02:04 +00:00
|
|
|
|
|
|
|
|
public class Frame {
|
2022-01-14 04:44:58 +00:00
|
|
|
List<AParticle> AParticles;
|
2022-01-11 22:02:04 +00:00
|
|
|
|
2022-01-14 04:44:58 +00:00
|
|
|
public Frame(List<AParticle> AParticles) {
|
|
|
|
|
this.AParticles = AParticles;
|
2022-01-11 22:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Spawns all particles in a frame (CALL ASYNC)
|
|
|
|
|
*
|
|
|
|
|
* @param location Location to spawn particles at
|
|
|
|
|
*/
|
|
|
|
|
public void spawn(Location location) {
|
2022-01-14 04:44:58 +00:00
|
|
|
Location tmpLocation = location.clone();
|
|
|
|
|
AParticles.forEach(AParticle -> {
|
2022-02-17 01:02:48 +00:00
|
|
|
ThreadLocalRandom current = ThreadLocalRandom.current();
|
2022-01-14 04:44:58 +00:00
|
|
|
AParticle.particleBuilder()
|
2022-02-23 01:44:42 +00:00
|
|
|
.location(tmpLocation.set(location.getX() + AParticle.x() + AParticle.offset_range() == 0 ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range()),
|
|
|
|
|
location.getY() + AParticle.y() + AParticle.offset_range() == 0 ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range()),
|
|
|
|
|
location.getZ() + AParticle.z() + AParticle.offset_range() == 0 ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range())))
|
2022-01-14 04:44:58 +00:00
|
|
|
.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();
|
|
|
|
|
});
|
2022-01-11 22:02:04 +00:00
|
|
|
}
|
|
|
|
|
}
|