All checks were successful
EpicKnarvik97/KnarLib/pipeline/head This commit looks good
169 lines
5.4 KiB
Java
169 lines
5.4 KiB
Java
package net.knarcraft.knarlib.particle;
|
|
|
|
import org.bukkit.Particle;
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
/**
|
|
* A configuration describing a particle
|
|
*/
|
|
@SuppressWarnings("unused")
|
|
public final class ParticleConfig {
|
|
|
|
private final ParticleMode particleMode;
|
|
private final Particle particleType;
|
|
private final int particleAmount;
|
|
private final double particleDensity;
|
|
private final double heightOffset;
|
|
private final double offsetX;
|
|
private final double offsetY;
|
|
private final double offsetZ;
|
|
private final double extra;
|
|
|
|
/**
|
|
* Instantiates a new particle config
|
|
*
|
|
* @param particlesSection <p>The configuration section containing the particle's settings</p>
|
|
*/
|
|
public ParticleConfig(@NotNull ConfigurationSection particlesSection) {
|
|
@NotNull Particle particleType;
|
|
try {
|
|
particleType = Particle.valueOf(particlesSection.getString("type"));
|
|
} catch (IllegalArgumentException | NullPointerException exception) {
|
|
particleType = Particle.ASH;
|
|
}
|
|
this.particleType = particleType;
|
|
this.particleAmount = particlesSection.getInt("amount", 30);
|
|
this.offsetX = particlesSection.getDouble("offsetX", 0.5);
|
|
this.offsetY = particlesSection.getDouble("offsetY", 1);
|
|
this.offsetZ = particlesSection.getDouble("offsetZ", 0.5);
|
|
this.heightOffset = particlesSection.getDouble("heightOffset", 0.5);
|
|
this.extra = particlesSection.getDouble("extra", 0);
|
|
ParticleMode particleMode;
|
|
try {
|
|
particleMode = ParticleMode.valueOf(particlesSection.getString("mode"));
|
|
} catch (IllegalArgumentException | NullPointerException exception) {
|
|
particleMode = ParticleMode.SINGLE;
|
|
}
|
|
this.particleMode = particleMode;
|
|
|
|
// Make sure particle density is between 1 (inclusive) and 0 (exclusive)
|
|
double particleDensity = particlesSection.getDouble("particleDensity", 0.1);
|
|
if (particleDensity <= 0) {
|
|
particleDensity = 0.1;
|
|
} else if (particleDensity > 360) {
|
|
particleDensity = 360;
|
|
}
|
|
this.particleDensity = particleDensity;
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new particle config
|
|
*
|
|
* @param particleMode <p>The mode to use when spawning the particle</p>
|
|
* @param particleType <p>The type of particle to spawn</p>
|
|
* @param particleAmount <p>The amount of particles to spawn at once</p>
|
|
* @param particleDensity <p>The density of the particles, if spawning a shape</p>
|
|
* @param heightOffset <p>The offset above the block to spawn the particle</p>
|
|
* @param offsetX <p>The x-offset/spread of the spawned particles</p>
|
|
* @param offsetY <p>The y-offset/spread of the spawned particles</p>
|
|
* @param offsetZ <p>The z-offset/spread of the spawned particles</p>
|
|
* @param extra <p>Extra data for the particle. Usage depends on the particle type.</p>
|
|
*/
|
|
public ParticleConfig(@NotNull ParticleMode particleMode, @NotNull Particle particleType, int particleAmount,
|
|
double particleDensity, double heightOffset, double offsetX, double offsetY, double offsetZ,
|
|
double extra) {
|
|
this.particleMode = particleMode;
|
|
this.particleType = particleType;
|
|
this.particleAmount = particleAmount;
|
|
this.particleDensity = particleDensity;
|
|
this.heightOffset = heightOffset;
|
|
this.offsetX = offsetX;
|
|
this.offsetY = offsetY;
|
|
this.offsetZ = offsetZ;
|
|
this.extra = extra;
|
|
}
|
|
|
|
/**
|
|
* The mode to use when drawing/spawning the particle(s)
|
|
*
|
|
* @return <p>The particle mode</p>
|
|
*/
|
|
public @NotNull ParticleMode getParticleMode() {
|
|
return particleMode;
|
|
}
|
|
|
|
/**
|
|
* The type of particle to spawn
|
|
*
|
|
* @return <p>The particle type</p>
|
|
*/
|
|
public @NotNull Particle getParticleType() {
|
|
return particleType;
|
|
}
|
|
|
|
/**
|
|
* The amount of particles to spawn
|
|
*
|
|
* @return <p>The amount of particles</p>
|
|
*/
|
|
public int getParticleAmount() {
|
|
return particleAmount;
|
|
}
|
|
|
|
/**
|
|
* The density of particles to use in shapes closer to 0 causes larger density
|
|
*
|
|
* @return <p>The particle density</p>
|
|
*/
|
|
public double getParticleDensity() {
|
|
return particleDensity;
|
|
}
|
|
|
|
/**
|
|
* The number of blocks above the block the particle(s) should spawn
|
|
*
|
|
* @return <p>The y-offset</p>
|
|
*/
|
|
public double getHeightOffset() {
|
|
return heightOffset;
|
|
}
|
|
|
|
/**
|
|
* The offset/spread of particles in the x-direction
|
|
*
|
|
* @return <p>The x-offset</p>
|
|
*/
|
|
public double getOffsetX() {
|
|
return offsetX;
|
|
}
|
|
|
|
/**
|
|
* The offset/spread of particles in the y-direction
|
|
*
|
|
* @return <p>The y-offset</p>
|
|
*/
|
|
public double getOffsetY() {
|
|
return offsetY;
|
|
}
|
|
|
|
/**
|
|
* The offset/spread of particles in the z-direction
|
|
*
|
|
* @return <p>The z-offset</p>
|
|
*/
|
|
public double getOffsetZ() {
|
|
return offsetZ;
|
|
}
|
|
|
|
/**
|
|
* The extra value to set for the particle. Exactly what it does depends on the particle.
|
|
*
|
|
* @return <p>The particle's extra value</p>
|
|
*/
|
|
public double getExtra() {
|
|
return extra;
|
|
}
|
|
|
|
}
|