package net.knarcraft.knarlib.particle; import org.bukkit.Particle; import org.jetbrains.annotations.NotNull; /** * A builder for creating particle configurations * *
The default behavior will spawn a single particle with no offset or extra data, and density 1.
*/ @SuppressWarnings("unused") public class ParticleConfigBuilder { private final Particle particleType; private ParticleMode particleMode = ParticleMode.SINGLE; private int particleAmount = 1; private double particleDensity = 1; private double heightOffset = 0; private double offsetX = 0; private double offsetY = 0; private double offsetZ = 0; private double extra = 0; /** * Instantiates a new particle config builder * * @param particleTypeThe type of particle to spawn
*/ public ParticleConfigBuilder(@NotNull Particle particleType) { this.particleType = particleType; } /** * Sets the mode to use when spawning the particles * * @param particleModeThe mode to use
* @returnThis particle configuration builder
*/ public @NotNull ParticleConfigBuilder setMode(@NotNull ParticleMode particleMode) { this.particleMode = particleMode; return this; } /** * Sets the amount of particles to spawn * * @param particleAmountThe number/amount of particles to spawn
* @returnThis particle configuration builder
*/ public @NotNull ParticleConfigBuilder setAmount(int particleAmount) { this.particleAmount = particleAmount; return this; } /** * Sets the density of the particles to spawn * * @param particleDensityThe new density
* @returnThis particle configuration builder
*/ public @NotNull ParticleConfigBuilder setDensity(double particleDensity) { this.particleDensity = particleDensity; return this; } /** * Sets the x,y,z offsets of the spawned particles * *These values control the spread of the spawned particles
* * @param offsetXThe offset in the x-direction
* @param offsetYThe offset in the y-direction
* @param offsetZThe offset in the z-direction
* @returnThis particle configuration builder
*/ public @NotNull ParticleConfigBuilder setOffsets(double offsetX, double offsetY, double offsetZ) { this.offsetX = offsetX; this.offsetY = offsetY; this.offsetZ = offsetZ; return this; } /** * Sets the x offset of the spawned particles * * @param offsetXThe offset in the x-direction
* @returnThis particle configuration builder
*/ public @NotNull ParticleConfigBuilder setXOffset(double offsetX) { this.offsetX = offsetX; return this; } /** * Sets the y offset of the spawned particles * * @param offsetYThe offset in the y-direction
* @returnThis particle configuration builder
*/ public @NotNull ParticleConfigBuilder setYOffset(double offsetY) { this.offsetY = offsetY; return this; } /** * Sets the z offset of the spawned particles * * @param offsetZThe offset in the z-direction
* @returnThis particle configuration builder
*/ public @NotNull ParticleConfigBuilder setZOffset(double offsetZ) { this.offsetZ = offsetZ; return this; } /** * Sets the extra data for the spawned particles * * @param extraThe extra data to set
* @returnThis particle configuration builder
*/ public @NotNull ParticleConfigBuilder setExtra(double extra) { this.extra = extra; return this; } /** * Sets the height offset for the spawned particles * * @param heightOffsetThe height offset to use
* @returnThis particle configuration builder
*/ public @NotNull ParticleConfigBuilder setHeightOffset(double heightOffset) { this.heightOffset = heightOffset; return this; } /** * Builds the particle configuration * * @returnThe built particle configuration
*/ public @NotNull ParticleConfig build() { return new ParticleConfig(particleMode, particleType, particleAmount, particleDensity, heightOffset, offsetX, offsetY, offsetZ, extra); } }