mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2025-02-11 03:29:53 +00:00
Added the option to spawn particles from far away
This commit is contained in:
parent
cad1ecb7a7
commit
621862a5be
10 changed files with 66 additions and 44 deletions
|
@ -171,10 +171,10 @@ public class ParticleManager extends Manager implements Listener, Runnable {
|
|||
|
||||
if (Setting.TOGGLE_ON_MOVE.getBoolean() && particle.getStyle().canToggleWithMovement() && pplayer.isMoving()) {
|
||||
for (PParticle pparticle : DefaultStyles.FEET.getParticles(particle, location))
|
||||
ParticleEffect.display(particle, pparticle, false, pplayer.getPlayer());
|
||||
ParticleEffect.display(particle, pparticle, particle.getStyle().hasLongRangeVisibility(), pplayer.getPlayer());
|
||||
} else {
|
||||
for (PParticle pparticle : particle.getStyle().getParticles(particle, location))
|
||||
ParticleEffect.display(particle, pparticle, false, pplayer.getPlayer());
|
||||
ParticleEffect.display(particle, pparticle, particle.getStyle().hasLongRangeVisibility(), pplayer.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -186,14 +186,15 @@ public class ParticleManager extends Manager implements Listener, Runnable {
|
|||
* @param world The world the particles are spawning in
|
||||
* @param particle The ParticlePair to use for getting particle settings
|
||||
* @param particles The particles to display
|
||||
* @param isLongRange If the particle can be viewed from long range
|
||||
*/
|
||||
public void displayParticles(Player player, World world, ParticlePair particle, List<PParticle> particles) {
|
||||
public void displayParticles(Player player, World world, ParticlePair particle, List<PParticle> particles, boolean isLongRange) {
|
||||
PermissionManager permissionManager = this.playerParticles.getManager(PermissionManager.class);
|
||||
if ((player != null && player.getGameMode() == GameMode.SPECTATOR) || !permissionManager.isWorldEnabled(world.getName()))
|
||||
return;
|
||||
|
||||
for (PParticle pparticle : particles)
|
||||
ParticleEffect.display(particle, pparticle, false, Bukkit.getPlayer(particle.getOwnerUniqueId()));
|
||||
ParticleEffect.display(particle, pparticle, isLongRange, Bukkit.getPlayer(particle.getOwnerUniqueId()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -273,19 +273,19 @@ public enum ParticleEffect {
|
|||
*
|
||||
* @param particle The ParticlePair, given the effect/style/data
|
||||
* @param pparticle The particle spawn information
|
||||
* @param isFixedEffect If the particle is spawned from a fixed effect
|
||||
* @param isLongRange If the particle can be viewed from long range
|
||||
* @param owner The player that owns the particles
|
||||
*/
|
||||
public static void display(ParticlePair particle, PParticle pparticle, boolean isFixedEffect, Player owner) {
|
||||
public static void display(ParticlePair particle, PParticle pparticle, boolean isLongRange, Player owner) {
|
||||
ParticleEffect effect = particle.getEffect();
|
||||
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), isFixedEffect, owner);
|
||||
effect.display(particle.getSpawnMaterial(), 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), isFixedEffect, owner);
|
||||
effect.display(particle.getSpawnColor(), pparticle.getLocation(true), isLongRange, owner);
|
||||
} else {
|
||||
effect.display(pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), count, pparticle.getLocation(false), isFixedEffect, owner);
|
||||
effect.display(pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), count, pparticle.getLocation(false), isLongRange, owner);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,18 +298,16 @@ public enum ParticleEffect {
|
|||
* @param speed Display speed of the particles
|
||||
* @param amount Amount of particles
|
||||
* @param center Center location of the effect
|
||||
* @param isFixedEffect If the particle is spawned from a fixed effect
|
||||
* @param isLongRange If the particle can be viewed from long range
|
||||
* @param owner The player that owns the particles
|
||||
* @throws ParticleDataException If the particle effect requires additional data
|
||||
*/
|
||||
public void display(double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, boolean isFixedEffect, Player owner) throws ParticleDataException {
|
||||
if (this.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
||||
public void display(double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, boolean isLongRange, Player owner) throws ParticleDataException {
|
||||
if (this.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA))
|
||||
throw new ParticleDataException("This particle effect requires additional data");
|
||||
}
|
||||
|
||||
for (Player player : this.getPlayersInRange(center, isFixedEffect, owner)) {
|
||||
for (Player player : this.getPlayersInRange(center, isLongRange, owner))
|
||||
player.spawnParticle(this.internalEnum, center.getX(), center.getY(), center.getZ(), amount, offsetX, offsetY, offsetZ, speed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -317,23 +315,21 @@ public enum ParticleEffect {
|
|||
*
|
||||
* @param color Color of the particle
|
||||
* @param center Center location of the effect
|
||||
* @param isFixedEffect If the particle is spawned from a fixed effect
|
||||
* @param isLongRange If the particle can be viewed from long range
|
||||
* @param owner The player that owns the particles
|
||||
* @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect
|
||||
*/
|
||||
public void display(ParticleColor color, Location center, boolean isFixedEffect, Player owner) throws ParticleColorException {
|
||||
if (!this.hasProperty(ParticleProperty.COLORABLE)) {
|
||||
public void display(ParticleColor color, Location center, boolean isLongRange, Player owner) throws ParticleColorException {
|
||||
if (!this.hasProperty(ParticleProperty.COLORABLE))
|
||||
throw new ParticleColorException("This particle effect is not colorable");
|
||||
}
|
||||
|
||||
if (this == DUST && NMSUtil.getVersionNumber() >= 13) { // DUST uses a special data object for spawning in 1.13
|
||||
if (this == DUST && NMSUtil.getVersionNumber() >= 13) { // DUST uses a special data object for spawning in 1.13+
|
||||
OrdinaryColor dustColor = (OrdinaryColor) color;
|
||||
DustOptions dustOptions = new DustOptions(Color.fromRGB(dustColor.getRed(), dustColor.getGreen(), dustColor.getBlue()), Setting.DUST_SIZE.getFloat());
|
||||
for (Player player : this.getPlayersInRange(center, isFixedEffect, owner)) {
|
||||
for (Player player : this.getPlayersInRange(center, isLongRange, owner))
|
||||
player.spawnParticle(this.internalEnum, center.getX(), center.getY(), center.getZ(), 1, 0, 0, 0, 0, dustOptions);
|
||||
}
|
||||
} else {
|
||||
for (Player player : this.getPlayersInRange(center, isFixedEffect, owner)) {
|
||||
for (Player player : this.getPlayersInRange(center, isLongRange, owner)) {
|
||||
// Minecraft clients require that you pass a non-zero value if the Red value should be zero
|
||||
player.spawnParticle(this.internalEnum, center.getX(), center.getY(), center.getZ(), 0, this == ParticleEffect.DUST && color.getValueX() == 0 ? Float.MIN_VALUE : color.getValueX(), color.getValueY(), color.getValueZ(), 1);
|
||||
}
|
||||
|
@ -352,11 +348,11 @@ public enum ParticleEffect {
|
|||
* @param speed Display speed of the particles
|
||||
* @param amount Amount of particles
|
||||
* @param center Center location of the effect
|
||||
* @param isFixedEffect If the particle is spawned from a fixed effect
|
||||
* @param isLongRange If the particle can be viewed from long range
|
||||
* @param owner The player that owns the particles
|
||||
* @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
|
||||
*/
|
||||
public void display(Material spawnMaterial, double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, boolean isFixedEffect, Player owner) throws ParticleDataException {
|
||||
public void display(Material spawnMaterial, double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, boolean isLongRange, Player owner) throws ParticleDataException {
|
||||
if (!this.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
||||
throw new ParticleDataException("This particle effect does not require additional data");
|
||||
}
|
||||
|
@ -370,7 +366,7 @@ public enum ParticleEffect {
|
|||
extraData = new MaterialData(spawnMaterial); // Deprecated, only used in versions < 1.13
|
||||
}
|
||||
|
||||
for (Player player : this.getPlayersInRange(center, isFixedEffect, owner))
|
||||
for (Player player : this.getPlayersInRange(center, isLongRange, owner))
|
||||
player.spawnParticle(this.internalEnum, center.getX(), center.getY(), center.getZ(), amount, offsetX, offsetY, offsetZ, speed, extraData);
|
||||
}
|
||||
|
||||
|
@ -378,22 +374,22 @@ public enum ParticleEffect {
|
|||
* Gets a List of Players within the particle display range
|
||||
*
|
||||
* @param center The center of the radius to check around
|
||||
* @param isFixedEffect If the particle is spawned from a fixed effect
|
||||
* @param isLongRange If the particle can be viewed from long range
|
||||
* @param owner The player that owns the particles
|
||||
* @return A List of Players within the particle display range
|
||||
*/
|
||||
private List<Player> getPlayersInRange(Location center, boolean isFixedEffect, Player owner) {
|
||||
private List<Player> getPlayersInRange(Location center, boolean isLongRange, Player owner) {
|
||||
List<Player> players = new ArrayList<>();
|
||||
int range = !isFixedEffect ? Setting.PARTICLE_RENDER_RANGE_PLAYER.getInt() : Setting.PARTICLE_RENDER_RANGE_FIXED_EFFECT.getInt();
|
||||
int range = !isLongRange ? Setting.PARTICLE_RENDER_RANGE_PLAYER.getInt() : Setting.PARTICLE_RENDER_RANGE_FIXED_EFFECT.getInt();
|
||||
range *= range;
|
||||
|
||||
for (PPlayer pplayer : PlayerParticles.getInstance().getManager(ParticleManager.class).getPPlayers()) {
|
||||
Player p = pplayer.getPlayer();
|
||||
if (!isFixedEffect && !this.canSee(p, owner))
|
||||
if (!this.canSee(p, owner))
|
||||
continue;
|
||||
|
||||
if (p != null && pplayer.canSeeParticles() && p.getWorld().equals(center.getWorld()) && center.distanceSquared(p.getLocation()) <= range * range) {
|
||||
if (p != null && pplayer.canSeeParticles() && p.getWorld().equals(center.getWorld()) && center.distanceSquared(p.getLocation()) <= range)
|
||||
players.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
return players;
|
||||
|
|
|
@ -26,7 +26,9 @@ public interface ParticleStyle {
|
|||
/**
|
||||
* @return true if the style is enabled, false otherwise
|
||||
*/
|
||||
boolean isEnabled();
|
||||
default boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The style's internal name that will always remain constant
|
||||
|
@ -36,7 +38,9 @@ public interface ParticleStyle {
|
|||
/**
|
||||
* @return The name that the style will display to the users as
|
||||
*/
|
||||
String getName();
|
||||
default String getName() {
|
||||
return this.getInternalName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the style can be used in a FixedParticleEffect
|
||||
|
@ -50,15 +54,26 @@ public interface ParticleStyle {
|
|||
*
|
||||
* @return True if it can be, otherwise False
|
||||
*/
|
||||
boolean canToggleWithMovement();
|
||||
default boolean canToggleWithMovement() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Y-axis offset to be applied when using '/pp fixed create looking'
|
||||
*
|
||||
* @return How far to move the style up or down to get it centered on the block properly
|
||||
*/
|
||||
double getFixedEffectOffset();
|
||||
|
||||
default double getFixedEffectOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the particle should be seen from the fixed effect distance instead of the player distance, or false otherwise
|
||||
*/
|
||||
default boolean hasLongRangeVisibility() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ParticleStyle with the name given, returns null if not found
|
||||
*
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package dev.esophose.playerparticles.styles;
|
||||
|
||||
import dev.esophose.playerparticles.PlayerParticles;
|
||||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.manager.ParticleManager;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import java.util.ArrayList;
|
||||
|
@ -20,9 +22,12 @@ public class ParticleStyleArrows extends DefaultParticleStyle implements Listene
|
|||
private int maxArrowsPerPlayer;
|
||||
private boolean onlySpawnIfFlying;
|
||||
private List<String> arrowEntityNames;
|
||||
private ParticleManager particleManager;
|
||||
|
||||
public ParticleStyleArrows() {
|
||||
super("arrows", false, false, 0);
|
||||
|
||||
this.particleManager = PlayerParticles.getInstance().getManager(ParticleManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,6 +64,11 @@ public class ParticleStyleArrows extends DefaultParticleStyle implements Listene
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasLongRangeVisibility() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event used to get all projectiles fired by players
|
||||
* Adds all projectiles fired from players to the array
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ParticleStyleBlockBreak extends DefaultParticleStyle implements Lis
|
|||
if (pplayer != null) {
|
||||
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKBREAK)) {
|
||||
Location loc = event.getBlock().getLocation().clone();
|
||||
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc));
|
||||
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ParticleStyleBlockPlace extends DefaultParticleStyle implements Lis
|
|||
if (pplayer != null) {
|
||||
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKPLACE)) {
|
||||
Location loc = event.getBlock().getLocation().clone();
|
||||
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc));
|
||||
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ public class ParticleStyleCelebration extends DefaultParticleStyle {
|
|||
trail.setEffect(ParticleStyleCelebration.this.fuseEffect);
|
||||
trail.setStyle(DefaultStyles.CELEBRATION);
|
||||
|
||||
particleManager.displayParticles(player, this.location.getWorld(), trail, Collections.singletonList(new PParticle(this.location)));
|
||||
particleManager.displayParticles(player, this.location.getWorld(), trail, Collections.singletonList(new PParticle(this.location)), true);
|
||||
|
||||
this.location.add(0, ParticleStyleCelebration.this.fuseSpacing, 0);
|
||||
} else {
|
||||
|
@ -140,7 +140,7 @@ public class ParticleStyleCelebration extends DefaultParticleStyle {
|
|||
|
||||
particles.add(new PParticle(this.location.clone().add(dx, dy, dz)));
|
||||
}
|
||||
particleManager.displayParticles(player, this.location.getWorld(), particle, particles);
|
||||
particleManager.displayParticles(player, this.location.getWorld(), particle, particles, true);
|
||||
|
||||
this.cancel();
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class ParticleStyleHurt extends DefaultParticleStyle implements Listener
|
|||
if (pplayer != null) {
|
||||
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.HURT)) {
|
||||
Location loc = player.getLocation().clone().add(0, 1, 0);
|
||||
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.HURT.getParticles(particle, loc));
|
||||
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.HURT.getParticles(particle, loc), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class ParticleStyleMove extends DefaultParticleStyle implements Listener
|
|||
Location loc = event.getPlayer().getLocation().clone();
|
||||
loc.setY(loc.getY() + 0.05);
|
||||
Player player = event.getPlayer();
|
||||
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.MOVE.getParticles(particle, loc));
|
||||
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.MOVE.getParticles(particle, loc), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class ParticleStyleSwords extends DefaultParticleStyle implements Listene
|
|||
if (pplayer != null && SWORD_NAMES.contains(player.getInventory().getItemInMainHand().getType().name())) {
|
||||
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.SWORDS)) {
|
||||
Location loc = entity.getLocation().clone().add(0, 1, 0);
|
||||
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.SWORDS.getParticles(particle, loc));
|
||||
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.SWORDS.getParticles(particle, loc), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue