Add element for new particle system except WingParticle
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Ursprung
f22cd77464
Commit
9576843d83
@ -10,26 +10,26 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Particle {
|
||||
public class ParticleData {
|
||||
|
||||
private final Material material;
|
||||
private final String name;
|
||||
private final Set<String> attributes = new LinkedHashSet<>();
|
||||
private final ParticleRequirement requirement;
|
||||
|
||||
public Particle(Material material, String name) {
|
||||
public ParticleData(Material material, String name) {
|
||||
this.material = material;
|
||||
this.name = name;
|
||||
this.requirement = ParticleRequirement.NO_REQUIRMENT;
|
||||
}
|
||||
|
||||
public Particle(Material material, String name, ParticleRequirement requirement) {
|
||||
public ParticleData(Material material, String name, ParticleRequirement requirement) {
|
||||
this.material = material;
|
||||
this.name = name;
|
||||
this.requirement = requirement;
|
||||
}
|
||||
|
||||
public Particle add(String attribute) {
|
||||
public ParticleData add(String attribute) {
|
||||
attributes.add(attribute);
|
||||
return this;
|
||||
}
|
44
src/de/steamwar/lobby/otherparticle/ParticleElement.java
Normale Datei
44
src/de/steamwar/lobby/otherparticle/ParticleElement.java
Normale Datei
@ -0,0 +1,44 @@
|
||||
package de.steamwar.lobby.otherparticle;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface ParticleElement {
|
||||
Random RANDOM = new Random();
|
||||
|
||||
default Color randomColor() {
|
||||
return Color.fromRGB(RANDOM.nextInt(255), RANDOM.nextInt(255), RANDOM.nextInt(255));
|
||||
}
|
||||
|
||||
default float randomSize() {
|
||||
return RANDOM.nextFloat() / 2 + 1;
|
||||
}
|
||||
|
||||
default Particle.DustOptions randomParticleDust() {
|
||||
return new Particle.DustOptions(randomColor(), randomSize());
|
||||
}
|
||||
|
||||
default void display(Location location, Consumer<Player> consumer) {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
int viewDistance = player.getClientViewDistance() * 16;
|
||||
if (location.distanceSquared(player.getLocation()) <= viewDistance * viewDistance) {
|
||||
consumer.accept(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
default void aggregateAttributes(ParticleData particleData) {
|
||||
}
|
||||
|
||||
default ParticleTickType tickType() {
|
||||
return ParticleTickType.MOVE;
|
||||
}
|
||||
|
||||
void tick(ParticleTickData particleTickData);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package de.steamwar.lobby.otherparticle;
|
||||
|
||||
public interface ParticleEnum {
|
||||
Particle getParticle();
|
||||
ParticleData getParticle();
|
||||
}
|
||||
|
36
src/de/steamwar/lobby/otherparticle/ParticleTickData.java
Normale Datei
36
src/de/steamwar/lobby/otherparticle/ParticleTickData.java
Normale Datei
@ -0,0 +1,36 @@
|
||||
package de.steamwar.lobby.otherparticle;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class ParticleTickData {
|
||||
|
||||
private final World world;
|
||||
private final Player player;
|
||||
private Location location;
|
||||
private final double deg;
|
||||
|
||||
public ParticleTickData withLocation(Location location) {
|
||||
ParticleTickData particleTickData = copy();
|
||||
particleTickData.location = location;
|
||||
return particleTickData;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
if (location == null) {
|
||||
return player.getLocation();
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
public ParticleTickData copy() {
|
||||
return new ParticleTickData(world, player, location, deg);
|
||||
}
|
||||
}
|
9
src/de/steamwar/lobby/otherparticle/ParticleTickType.java
Normale Datei
9
src/de/steamwar/lobby/otherparticle/ParticleTickType.java
Normale Datei
@ -0,0 +1,9 @@
|
||||
package de.steamwar.lobby.otherparticle;
|
||||
|
||||
public enum ParticleTickType {
|
||||
|
||||
ALWAYS,
|
||||
MOVE,
|
||||
SNEAK,
|
||||
;
|
||||
}
|
27
src/de/steamwar/lobby/otherparticle/elements/Always.java
Normale Datei
27
src/de/steamwar/lobby/otherparticle/elements/Always.java
Normale Datei
@ -0,0 +1,27 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickData;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickType;
|
||||
|
||||
public class Always extends DelegatingParticleElement {
|
||||
|
||||
public Always(ParticleElement particleElement) {
|
||||
super(particleElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String attribute() {
|
||||
return "PARTICLE_ATTRIBUTE_TICK";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleTickType tickType() {
|
||||
return ParticleTickType.ALWAYS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
particleElement.tick(particleTickData);
|
||||
}
|
||||
}
|
28
src/de/steamwar/lobby/otherparticle/elements/Circle.java
Normale Datei
28
src/de/steamwar/lobby/otherparticle/elements/Circle.java
Normale Datei
@ -0,0 +1,28 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickData;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class Circle extends DelegatingParticleElement {
|
||||
|
||||
public Circle(ParticleElement particleElement) {
|
||||
super(particleElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String attribute() {
|
||||
return "PARTICLE_ATTRIBUTE_CIRCLE";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
Location location = particleTickData.getLocation();
|
||||
|
||||
Vector vector = new Vector(1, 0, 0);
|
||||
vector.rotateAroundY(particleTickData.getDeg());
|
||||
ParticleTickData nParticleTickData = particleTickData.withLocation(location.clone().add(vector));
|
||||
particleElement.tick(nParticleTickData);
|
||||
}
|
||||
}
|
31
src/de/steamwar/lobby/otherparticle/elements/Cloud.java
Normale Datei
31
src/de/steamwar/lobby/otherparticle/elements/Cloud.java
Normale Datei
@ -0,0 +1,31 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickData;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class Cloud extends DelegatingParticleElement {
|
||||
|
||||
public Cloud(ParticleElement particleElement) {
|
||||
super(particleElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String attribute() {
|
||||
return "PARTICLE_ATTRIBUTE_CLOUD";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
if (particleTickData.getWorld().getBlockAt(particleTickData.getPlayer().getLocation().subtract(0, 0.5, 0)).getType() == Material.AIR) {
|
||||
particleTickData.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 5, 2, false, false, false));
|
||||
} else {
|
||||
particleTickData.getPlayer().removePotionEffect(PotionEffectType.SLOW_FALLING);
|
||||
return;
|
||||
}
|
||||
ParticleTickData nParticleTickData = particleTickData.withLocation(particleTickData.getLocation().subtract(0, -0.2, 0));
|
||||
particleElement.tick(nParticleTickData);
|
||||
}
|
||||
}
|
48
src/de/steamwar/lobby/otherparticle/elements/Delayed.java
Normale Datei
48
src/de/steamwar/lobby/otherparticle/elements/Delayed.java
Normale Datei
@ -0,0 +1,48 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Delayed extends DelegatingParticleElement {
|
||||
|
||||
private DelayedData delayedData = new DelayedData();
|
||||
private int interval;
|
||||
|
||||
private static class DelayedData implements Listener {
|
||||
private Map<Player, Integer> data = new HashMap<>();
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
data.remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
public Delayed(ParticleElement particleElement, int interval) {
|
||||
super(particleElement);
|
||||
Bukkit.getPluginManager().registerEvents(delayedData, LobbySystem.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String attribute() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
int currentNumber = delayedData.data.getOrDefault(particleTickData.getPlayer(), 0) % interval;
|
||||
delayedData.data.put(particleTickData.getPlayer(), currentNumber + 1);
|
||||
if (currentNumber != 0) {
|
||||
return;
|
||||
}
|
||||
particleElement.tick(particleTickData);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.otherparticle.ParticleData;
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickType;
|
||||
|
||||
public abstract class DelegatingParticleElement implements ParticleElement {
|
||||
|
||||
protected final ParticleElement particleElement;
|
||||
|
||||
protected DelegatingParticleElement(ParticleElement particleElement) {
|
||||
this.particleElement = particleElement;
|
||||
}
|
||||
|
||||
public abstract String attribute();
|
||||
|
||||
@Override
|
||||
public void aggregateAttributes(ParticleData particleData) {
|
||||
String attribute = attribute();
|
||||
if (attribute != null) {
|
||||
particleData.add(attribute);
|
||||
}
|
||||
particleElement.aggregateAttributes(particleData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleTickType tickType() {
|
||||
return particleElement.tickType();
|
||||
}
|
||||
}
|
47
src/de/steamwar/lobby/otherparticle/elements/DoubleCircle.java
Normale Datei
47
src/de/steamwar/lobby/otherparticle/elements/DoubleCircle.java
Normale Datei
@ -0,0 +1,47 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickData;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class DoubleCircle extends Circle {
|
||||
|
||||
private ParticleElement second;
|
||||
|
||||
public DoubleCircle(ParticleElement first, ParticleElement second) {
|
||||
super(first);
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String attribute() {
|
||||
return "PARTICLE_ATTRIBUTE_BI_CIRCLE";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleTickType tickType() {
|
||||
if (particleElement.tickType() == second.tickType()) {
|
||||
return particleElement.tickType();
|
||||
}
|
||||
// TODO: This could be improved but I will not do it
|
||||
return ParticleTickType.MOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
Location location = particleTickData.getLocation();
|
||||
|
||||
Vector vector = new Vector(1, 0, 0);
|
||||
vector.rotateAroundY(particleTickData.getDeg());
|
||||
ParticleTickData nParticleTickData = particleTickData.withLocation(location.clone().add(vector));
|
||||
particleElement.tick(nParticleTickData);
|
||||
|
||||
vector.setX(-vector.getX());
|
||||
vector.setZ(-vector.getZ());
|
||||
|
||||
nParticleTickData = particleTickData.withLocation(location.clone().add(vector));
|
||||
second.tick(nParticleTickData);
|
||||
}
|
||||
}
|
44
src/de/steamwar/lobby/otherparticle/elements/DustParticle.java
Normale Datei
44
src/de/steamwar/lobby/otherparticle/elements/DustParticle.java
Normale Datei
@ -0,0 +1,44 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickData;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
public class DustParticle implements ParticleElement {
|
||||
|
||||
private Particle particle;
|
||||
private float vx = 0.01f;
|
||||
private float vy = 0.01f;
|
||||
private float vz = 0.01f;
|
||||
private double speed = 0.01;
|
||||
private int count = 5;
|
||||
|
||||
public DustParticle(Particle particle) {
|
||||
this.particle = particle;
|
||||
}
|
||||
|
||||
public DustParticle(Particle particle, float vx, float vy, float vz) {
|
||||
this.particle = particle;
|
||||
this.vx = vx;
|
||||
this.vy = vy;
|
||||
this.vz = vz;
|
||||
}
|
||||
|
||||
public DustParticle(Particle particle, float vx, float vy, float vz, float speed, int count) {
|
||||
this.particle = particle;
|
||||
this.vx = vx;
|
||||
this.vy = vy;
|
||||
this.vz = vz;
|
||||
this.speed = speed;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
Location location = particleTickData.getLocation().add(0.0, 0.2, 0.0);
|
||||
display(location, player -> {
|
||||
player.spawnParticle(particle, location, count, vx, vy, vz, speed, randomParticleDust());
|
||||
});
|
||||
}
|
||||
}
|
27
src/de/steamwar/lobby/otherparticle/elements/Group.java
Normale Datei
27
src/de/steamwar/lobby/otherparticle/elements/Group.java
Normale Datei
@ -0,0 +1,27 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickData;
|
||||
|
||||
public class Group extends DelegatingParticleElement {
|
||||
|
||||
private final ParticleElement[] rest;
|
||||
|
||||
public Group(ParticleElement particleElement, ParticleElement... rest) {
|
||||
super(particleElement);
|
||||
this.rest = rest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String attribute() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
particleElement.tick(particleTickData);
|
||||
for (ParticleElement particleElement : rest) {
|
||||
particleElement.tick(particleTickData);
|
||||
}
|
||||
}
|
||||
}
|
28
src/de/steamwar/lobby/otherparticle/elements/LocationMutator.java
Normale Datei
28
src/de/steamwar/lobby/otherparticle/elements/LocationMutator.java
Normale Datei
@ -0,0 +1,28 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String attribute() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
ParticleTickData nParticleTickData = particleTickData.withLocation(mutator.apply(particleTickData.getLocation()));
|
||||
particleElement.tick(nParticleTickData);
|
||||
}
|
||||
}
|
23
src/de/steamwar/lobby/otherparticle/elements/NonFloor.java
Normale Datei
23
src/de/steamwar/lobby/otherparticle/elements/NonFloor.java
Normale Datei
@ -0,0 +1,23 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickData;
|
||||
|
||||
public class NonFloor extends DelegatingParticleElement {
|
||||
|
||||
public NonFloor(ParticleElement particleElement) {
|
||||
super(particleElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String attribute() {
|
||||
return "PARTICLE_ATTRIBUTE_NON_FLOOR";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
if (particleTickData.getWorld().getBlockAt(particleTickData.getPlayer().getLocation().subtract(0, 0.5, 0)).getType().isAir()) {
|
||||
particleElement.tick(particleTickData);
|
||||
}
|
||||
}
|
||||
}
|
24
src/de/steamwar/lobby/otherparticle/elements/NonFlying.java
Normale Datei
24
src/de/steamwar/lobby/otherparticle/elements/NonFlying.java
Normale Datei
@ -0,0 +1,24 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickData;
|
||||
|
||||
public class NonFlying extends DelegatingParticleElement {
|
||||
|
||||
public NonFlying(ParticleElement particleElement) {
|
||||
super(particleElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String attribute() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
if (particleTickData.getPlayer().isGliding()) {
|
||||
return;
|
||||
}
|
||||
particleElement.tick(particleTickData);
|
||||
}
|
||||
}
|
66
src/de/steamwar/lobby/otherparticle/elements/SimpleParticle.java
Normale Datei
66
src/de/steamwar/lobby/otherparticle/elements/SimpleParticle.java
Normale Datei
@ -0,0 +1,66 @@
|
||||
package de.steamwar.lobby.otherparticle.elements;
|
||||
|
||||
import de.steamwar.lobby.otherparticle.ParticleElement;
|
||||
import de.steamwar.lobby.otherparticle.ParticleTickData;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
public class SimpleParticle implements ParticleElement {
|
||||
|
||||
private final Particle particle;
|
||||
private boolean customVelocity = false;
|
||||
private float vx;
|
||||
private float vy;
|
||||
private float vz;
|
||||
private double time = 0.01;
|
||||
private int count = 5;
|
||||
|
||||
public SimpleParticle(Particle particle) {
|
||||
this.particle = particle;
|
||||
}
|
||||
|
||||
public SimpleParticle(Particle particle, float vx, float vy, float vz) {
|
||||
this.particle = particle;
|
||||
this.customVelocity = true;
|
||||
this.vx = vx;
|
||||
this.vy = vy;
|
||||
this.vz = vz;
|
||||
}
|
||||
|
||||
public SimpleParticle(Particle particle, float vx, float vy, float vz, double time) {
|
||||
this.particle = particle;
|
||||
this.customVelocity = true;
|
||||
this.vx = vx;
|
||||
this.vy = vy;
|
||||
this.vz = vz;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public SimpleParticle(Particle particle, float vx, float vy, float vz, double time, int count) {
|
||||
this.particle = particle;
|
||||
this.customVelocity = true;
|
||||
this.vx = vx;
|
||||
this.vy = vy;
|
||||
this.vz = vz;
|
||||
this.time = time;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public SimpleParticle(Particle particle, double time, int count) {
|
||||
this.particle = particle;
|
||||
this.time = time;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
Location location = particleTickData.getLocation().add(0.0, 0.2, 0.0);
|
||||
display(location, player -> {
|
||||
if (customVelocity) {
|
||||
player.spawnParticle(particle, location, count, vx, vy, vz, time);
|
||||
} else {
|
||||
player.spawnParticle(particle, location, count);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren