Added the option for styles to override individual particle data

This commit is contained in:
Esophose 2021-05-13 01:08:36 -06:00
parent 942e83216c
commit 845455c231
No known key found for this signature in database
GPG key ID: DE0E013CAE5C630A
2 changed files with 52 additions and 10 deletions

View file

@ -11,6 +11,28 @@ public class PParticle {
private double speed;
private double xOff, yOff, zOff;
private boolean directional;
private Object overrideData;
/**
* The constructor with all the fancy parameters and override data for customization
*
* @param location The location to display the particle at
* @param xOff The offset for the x-axis
* @param yOff The offset for the y-axis
* @param zOff The offset for the z-axis
* @param speed The speed the particle will move at
* @param directional If the particle should use the x, y, and z offsets as directions instead
* @param overrideData If not null, will override the player's set data on spawn
*/
public PParticle(Location location, double xOff, double yOff, double zOff, double speed, boolean directional, Object overrideData) {
this.location = location;
this.xOff = xOff;
this.yOff = yOff;
this.zOff = zOff;
this.speed = speed;
this.directional = directional;
this.overrideData = overrideData;
}
/**
* The constructor with all the fancy parameters for customization
@ -23,12 +45,7 @@ public class PParticle {
* @param directional If the particle should use the x, y, and z offsets as directions instead
*/
public PParticle(Location location, double xOff, double yOff, double zOff, double speed, boolean directional) {
this.location = location;
this.xOff = xOff;
this.yOff = yOff;
this.zOff = zOff;
this.speed = speed;
this.directional = directional;
this(location, xOff, yOff, zOff, speed, directional, null);
}
/**
@ -41,7 +58,7 @@ public class PParticle {
* @param speed The speed the particle will move at
*/
public PParticle(Location location, double xOff, double yOff, double zOff, double speed) {
this(location, xOff, yOff, zOff, speed, false);
this(location, xOff, yOff, zOff, speed, false, null);
}
/**
@ -51,7 +68,7 @@ public class PParticle {
* @param location The location to display the particles at
*/
public PParticle(Location location) {
this(location, 0.0F, 0.0F, 0.0F, 0.0F, false);
this(location, 0.0F, 0.0F, 0.0F, 0.0F, false, null);
}
/**
@ -122,4 +139,13 @@ public class PParticle {
return this.zOff;
}
/**
* Gets the data to override for the particle
*
* @return The data to override for the particle, may be null
*/
public Object getOverrideData() {
return this.overrideData;
}
}

View file

@ -3,6 +3,8 @@ package dev.esophose.playerparticles.particles;
import com.google.common.collect.ObjectArrays;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
import dev.esophose.playerparticles.particles.data.NoteColor;
import dev.esophose.playerparticles.particles.data.OrdinaryColor;
import dev.esophose.playerparticles.particles.data.ParticleColor;
import dev.esophose.playerparticles.particles.spawning.ParticleSpawner;
import dev.esophose.playerparticles.particles.spawning.ParticleSpawner.ParticleColorException;
@ -326,9 +328,23 @@ public enum ParticleEffect {
int count = pparticle.isDirectional() ? 0 : 1;
if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
effect.display(particle.getSpawnMaterial(), pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(false), isLongRange, owner);
Material data;
if (pparticle.getOverrideData() instanceof Material) {
data = (Material) pparticle.getOverrideData();
} else {
data = particle.getSpawnMaterial();
}
effect.display(data, pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(false), isLongRange, owner);
} else if (effect.hasProperty(ParticleProperty.COLORABLE)) {
effect.display(particle.getSpawnColor(), pparticle.getLocation(true), isLongRange, owner);
ParticleColor data;
if (pparticle.getOverrideData() instanceof NoteColor && particle.getEffect() == ParticleEffect.NOTE) {
data = (NoteColor) pparticle.getOverrideData();
} else if (pparticle.getOverrideData() instanceof OrdinaryColor && particle.getEffect() != ParticleEffect.NOTE) {
data = (OrdinaryColor) pparticle.getOverrideData();
} else {
data = particle.getSpawnColor();
}
effect.display(data, pparticle.getLocation(true), isLongRange, owner);
} else {
effect.display(pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), count, pparticle.getLocation(false), isLongRange, owner);
}