Skip to content

Commit

Permalink
made it so you can change whether ParticleShapes run async or not
Browse files Browse the repository at this point in the history
(cherry picked from commit befb07e)
  • Loading branch information
hmzel committed Jul 21, 2024
1 parent db89897 commit 2731a7d
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -59,6 +66,7 @@ public Shape stop() {
if (animator == null) return this;

animator.cancel();

animator = null;

return this;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -253,6 +269,10 @@ public int getPlayerAmount() {
return players.size();
}

public boolean isAsync() {
return async;
}

public boolean isRunning() {
return animator != null;
}
Expand Down

0 comments on commit 2731a7d

Please sign in to comment.