PlayerParticles/Plugin/src/main/java/dev/esophose/playerparticles/styles/ParticleStyleOrbit.java

60 lines
2 KiB
Java
Raw Normal View History

package dev.esophose.playerparticles.styles;
2016-09-10 21:13:13 -07:00
2019-12-12 19:32:53 -07:00
import dev.esophose.playerparticles.particles.PParticle;
2020-01-05 17:26:45 -07:00
import dev.esophose.playerparticles.particles.ParticlePair;
2020-05-11 13:04:11 -06:00
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
import dev.esophose.playerparticles.util.MathL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
2016-09-10 21:13:13 -07:00
import org.bukkit.Location;
public class ParticleStyleOrbit extends DefaultParticleStyle {
2016-09-10 21:13:13 -07:00
private int step = 0;
2020-01-16 19:09:11 -07:00
private int orbs;
private int numSteps;
2020-02-06 04:37:50 -07:00
private double radius;
2020-01-16 19:09:11 -07:00
public ParticleStyleOrbit() {
super("orbit", true, true, 0);
}
@Override
public List<PParticle> getParticles(ParticlePair particle, Location location) {
2019-12-12 19:32:53 -07:00
List<PParticle> particles = new ArrayList<>();
2020-01-16 19:09:11 -07:00
for (int i = 0; i < this.orbs; i++) {
2020-02-06 04:37:50 -07:00
double dx = -(MathL.cos((this.step / (double) this.numSteps) * (Math.PI * 2) + (((Math.PI * 2) / this.orbs) * i))) * this.radius;
double dz = -(MathL.sin((this.step / (double) this.numSteps) * (Math.PI * 2) + (((Math.PI * 2) / this.orbs) * i))) * this.radius;
2018-10-13 16:38:01 -06:00
particles.add(new PParticle(location.clone().add(dx, 0, dz)));
}
return particles;
}
@Override
public void updateTimers() {
2020-01-16 19:09:11 -07:00
this.step = (this.step + 1) % this.numSteps;
}
@Override
protected List<String> getGuiIconMaterialNames() {
return Arrays.asList("ENCHANTING_TABLE", "ENCHANTMENT_TABLE");
}
@Override
protected void setDefaultSettings(CommentedFileConfiguration config) {
2020-01-16 19:09:11 -07:00
this.setIfNotExists("orbs", 3, "The number of orbs that orbit the player");
this.setIfNotExists("steps", 120, "The number of spawning steps around the player");
2020-02-06 04:37:50 -07:00
this.setIfNotExists("radius", 1.0, "The radius for spawning the orbs");
}
@Override
protected void loadSettings(CommentedFileConfiguration config) {
2020-01-16 19:09:11 -07:00
this.orbs = config.getInt("orbs");
this.numSteps = config.getInt("steps");
2020-02-06 04:37:50 -07:00
this.radius = config.getDouble("radius");
2018-12-01 19:34:01 -07:00
}
2016-09-10 21:13:13 -07:00
}