mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2025-02-11 03:29:53 +00:00
Concurrency adjustments for arrows and fishing styles
This commit is contained in:
parent
91697ee112
commit
e8c9278e76
2 changed files with 28 additions and 17 deletions
|
@ -1,5 +1,6 @@
|
||||||
package dev.esophose.playerparticles.styles;
|
package dev.esophose.playerparticles.styles;
|
||||||
|
|
||||||
|
import dev.esophose.playerparticles.PlayerParticles;
|
||||||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||||
import dev.esophose.playerparticles.particles.PParticle;
|
import dev.esophose.playerparticles.particles.PParticle;
|
||||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||||
|
@ -7,6 +8,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
|
@ -26,7 +28,16 @@ public class ParticleStyleArrows extends DefaultParticleStyle implements Listene
|
||||||
public ParticleStyleArrows() {
|
public ParticleStyleArrows() {
|
||||||
super("arrows", false, false, 0);
|
super("arrows", false, false, 0);
|
||||||
|
|
||||||
this.projectiles = Collections.synchronizedList(new ArrayList<>());
|
this.projectiles = new ArrayList<>();
|
||||||
|
|
||||||
|
// Removes all arrows that are considered dead
|
||||||
|
Bukkit.getScheduler().runTaskTimer(PlayerParticles.getInstance(), () -> {
|
||||||
|
for (int i = this.projectiles.size() - 1; i >= 0; i--) {
|
||||||
|
Projectile projectile = this.projectiles.get(i);
|
||||||
|
if ((this.arrowTrackingTime != -1 && projectile.getTicksLived() >= this.arrowTrackingTime) || !projectile.isValid() || projectile.getShooter() == null)
|
||||||
|
this.projectiles.remove(i);
|
||||||
|
}
|
||||||
|
}, 0L, 5L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,16 +63,9 @@ public class ParticleStyleArrows extends DefaultParticleStyle implements Listene
|
||||||
return particles;
|
return particles;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes all arrows that are considered dead
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTimers() {
|
public void updateTimers() {
|
||||||
for (int i = this.projectiles.size() - 1; i >= 0; i--) {
|
|
||||||
Projectile projectile = this.projectiles.get(i);
|
|
||||||
if ((this.arrowTrackingTime != -1 && projectile.getTicksLived() >= this.arrowTrackingTime) || projectile.isDead() || !projectile.isValid() || projectile.getShooter() == null)
|
|
||||||
this.projectiles.remove(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
package dev.esophose.playerparticles.styles;
|
package dev.esophose.playerparticles.styles;
|
||||||
|
|
||||||
|
import dev.esophose.playerparticles.PlayerParticles;
|
||||||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||||
import dev.esophose.playerparticles.particles.PParticle;
|
import dev.esophose.playerparticles.particles.PParticle;
|
||||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.FishHook;
|
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
@ -26,12 +31,15 @@ public class ParticleStyleFishing extends DefaultParticleStyle implements Listen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Projectile> projectiles;
|
private Set<Projectile> projectiles;
|
||||||
|
|
||||||
public ParticleStyleFishing() {
|
public ParticleStyleFishing() {
|
||||||
super("fishing", false, false, 0);
|
super("fishing", false, false, 0);
|
||||||
|
|
||||||
this.projectiles = Collections.synchronizedList(new ArrayList<>());
|
this.projectiles = new HashSet<>();
|
||||||
|
|
||||||
|
// Removes all fish hooks that are considered dead
|
||||||
|
Bukkit.getScheduler().runTaskTimer(PlayerParticles.getInstance(), () -> this.projectiles.removeIf(x -> !x.isValid()), 0L, 5L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -45,12 +53,9 @@ public class ParticleStyleFishing extends DefaultParticleStyle implements Listen
|
||||||
return particles;
|
return particles;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes all fish hooks that are considered dead
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTimers() {
|
public void updateTimers() {
|
||||||
this.projectiles.removeIf(x -> !x.isValid());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,7 +80,9 @@ public class ParticleStyleFishing extends DefaultParticleStyle implements Listen
|
||||||
case "CAUGHT_FISH":
|
case "CAUGHT_FISH":
|
||||||
case "CAUGHT_ENTITY":
|
case "CAUGHT_ENTITY":
|
||||||
case "REEL_IN":
|
case "REEL_IN":
|
||||||
this.projectiles.remove(event.getHook());
|
try {
|
||||||
|
this.projectiles.remove((Projectile) PlayerFishEvent_getHook.invoke(event));
|
||||||
|
} catch (ReflectiveOperationException ignored) { }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue