From 4c46dc62afb5293271a28e94ea5e0626fa3f319f Mon Sep 17 00:00:00 2001 From: hmzel Date: Fri, 19 Jul 2024 21:17:33 -0500 Subject: [PATCH] made it so you can change whether ParticleShapes run async or not (cherry picked from commit befb07e056b46da0a8054a9cf9bba7e0665f83e3) --- .../shapers/parents/ParticleShaper.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/hm/zelha/particlesfx/shapers/parents/ParticleShaper.java b/src/main/java/hm/zelha/particlesfx/shapers/parents/ParticleShaper.java index 2f338e80..e57ef0d6 100644 --- a/src/main/java/hm/zelha/particlesfx/shapers/parents/ParticleShaper.java +++ b/src/main/java/hm/zelha/particlesfx/shapers/parents/ParticleShaper.java @@ -29,6 +29,7 @@ public abstract class ParticleShaper extends RotationHandler implements Shape { protected final Vector vectorHelper = new Vector(); protected BukkitTask animator = null; protected Particle particle; + protected boolean async = true; protected int particleFrequency; protected int particlesPerDisplay = 0; protected int currentCount = 0; @@ -45,12 +46,18 @@ public Shape start() { Validate.isTrue(ParticleSFX.getPlugin() != null, "Plugin is null! please put ParticleSFX.setPlugin(this) in your onEnable() method!"); - animator = new BukkitRunnable() { + BukkitRunnable runnable = new BukkitRunnable() { @Override public void run() { display(); } - }.runTaskTimerAsynchronously(ParticleSFX.getPlugin(), 1, delay); + }; + + if (async) { + animator = runnable.runTaskTimerAsynchronously(ParticleSFX.getPlugin(), 1, delay); + } else { + animator = runnable.runTaskTimer(ParticleSFX.getPlugin(), 1, delay); + } return this; } @@ -59,6 +66,7 @@ public Shape stop() { if (animator == null) return this; animator.cancel(); + animator = null; return this; @@ -188,6 +196,14 @@ public Shape setParticlesPerDisplay(int particlesPerDisplay) { return this; } + public Shape setAsync(boolean async) { + stop(); + + this.async = async; + + return start(); + } + public Shape setDelay(int delay) { stop(); @@ -253,6 +269,10 @@ public int getPlayerAmount() { return players.size(); } + public boolean isAsync() { + return async; + } + public boolean isRunning() { return animator != null; }