mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2025-01-05 22:28:22 +00:00
Fix spectral/tipped arrows not working in 1.14+
This commit is contained in:
parent
7def546cc2
commit
21ba139207
1 changed files with 27 additions and 32 deletions
|
@ -1,38 +1,39 @@
|
||||||
package com.esophose.playerparticles.styles;
|
package com.esophose.playerparticles.styles;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Arrow;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
|
||||||
|
|
||||||
import com.esophose.playerparticles.particles.ParticlePair;
|
import com.esophose.playerparticles.particles.ParticlePair;
|
||||||
import com.esophose.playerparticles.styles.api.PParticle;
|
import com.esophose.playerparticles.styles.api.PParticle;
|
||||||
import com.esophose.playerparticles.styles.api.ParticleStyle;
|
import com.esophose.playerparticles.styles.api.ParticleStyle;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ParticleStyleArrows implements ParticleStyle, Listener {
|
public class ParticleStyleArrows implements ParticleStyle, Listener {
|
||||||
|
|
||||||
private static final String[] arrowEntityNames = new String[] { "ARROW", "SPECTRAL_ARROW", "TIPPED_ARROW" };
|
private static final String[] arrowEntityNames = new String[] { "ARROW", "SPECTRAL_ARROW", "TIPPED_ARROW" };
|
||||||
private static final int MAX_ARROWS_PER_PLAYER = 10;
|
private static final int MAX_ARROWS_PER_PLAYER = 10;
|
||||||
private List<Arrow> arrows = new ArrayList<Arrow>();
|
private List<Projectile> arrows = new ArrayList<>();
|
||||||
|
|
||||||
public List<PParticle> getParticles(ParticlePair particle, Location location) {
|
public List<PParticle> getParticles(ParticlePair particle, Location location) {
|
||||||
List<PParticle> particles = new ArrayList<PParticle>();
|
List<PParticle> particles = new ArrayList<>();
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = arrows.size() - 1; i >= 0; i--) { // Loop backwards so the last-fired arrows are the ones that have particles if they go over the max
|
for (int i = this.arrows.size() - 1; i >= 0; i--) { // Loop backwards so the last-fired arrows are the ones that have particles if they go over the max
|
||||||
Arrow arrow = arrows.get(i);
|
Projectile arrow = this.arrows.get(i);
|
||||||
if (((Player) arrow.getShooter()).getUniqueId() == particle.getOwnerUniqueId()) {
|
if (((Player) arrow.getShooter()).getUniqueId().equals(particle.getOwnerUniqueId())) {
|
||||||
particles.add(new PParticle(arrow.getLocation(), 0.05F, 0.05F, 0.05F, 0.0F));
|
particles.add(new PParticle(arrow.getLocation(), 0.05F, 0.05F, 0.05F, 0.0F));
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count >= MAX_ARROWS_PER_PLAYER) break;
|
if (count >= MAX_ARROWS_PER_PLAYER)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return particles;
|
return particles;
|
||||||
|
@ -42,9 +43,10 @@ public class ParticleStyleArrows implements ParticleStyle, Listener {
|
||||||
* Removes all arrows that are considered dead
|
* Removes all arrows that are considered dead
|
||||||
*/
|
*/
|
||||||
public void updateTimers() {
|
public void updateTimers() {
|
||||||
for (int i = arrows.size() - 1; i >= 0; i--) {
|
for (int i = this.arrows.size() - 1; i >= 0; i--) {
|
||||||
Arrow arrow = arrows.get(i);
|
Projectile arrow = this.arrows.get(i);
|
||||||
if (arrow.getTicksLived() >= 1200 || arrow.isDead() || !arrow.isValid()) arrows.remove(i);
|
if (arrow.getTicksLived() >= 1200 || arrow.isDead() || !arrow.isValid())
|
||||||
|
this.arrows.remove(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,19 +74,12 @@ public class ParticleStyleArrows implements ParticleStyle, Listener {
|
||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onArrowFired(EntityShootBowEvent e) {
|
public void onArrowFired(EntityShootBowEvent e) {
|
||||||
if (e.getEntityType() == EntityType.PLAYER) {
|
if (e.getEntityType() != EntityType.PLAYER)
|
||||||
String entityName = e.getProjectile().getType().toString();
|
return;
|
||||||
boolean match = false;
|
|
||||||
for (String name : arrowEntityNames) {
|
|
||||||
if (entityName.equalsIgnoreCase(name)) {
|
|
||||||
match = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match)
|
String entityName = e.getProjectile().getType().toString();
|
||||||
arrows.add((Arrow) e.getProjectile());
|
if (Arrays.stream(arrowEntityNames).anyMatch(entityName::equalsIgnoreCase))
|
||||||
}
|
this.arrows.add((Projectile) e.getProjectile());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue