Skip to content

Commit 8522faf

Browse files
committed
Merge branch 'master' of https://github.com/CrAfTsArMy/CodeLib
2 parents 44d26f9 + 077ea95 commit 8522faf

2 files changed

Lines changed: 24 additions & 19 deletions

File tree

src/main/java/de/codeblocksmc/codelib/locations/LocationWrapperReduced.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public boolean equals(Object obj) {
121121
*
122122
* @return a hash code based on the fields of the object.
123123
*/
124+
124125
@Override
125126
public int hashCode() {
126127
return Objects.hash(x, y, z, yaw, pitch);

src/main/java/de/codeblocksmc/codelib/util/ParticleUtil.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
package de.codeblocksmc.codelib.util;
22

3+
import com.google.common.util.concurrent.AtomicDouble;
4+
import org.bukkit.Bukkit;
35
import org.bukkit.Location;
46
import org.bukkit.Particle;
57
import org.bukkit.World;
68
import org.bukkit.plugin.Plugin;
79
import org.bukkit.scheduler.BukkitRunnable;
10+
import org.bukkit.scheduler.BukkitTask;
811
import org.bukkit.util.Vector;
912

13+
/*
14+
* @author Try
15+
* @version 1.1
16+
*/
17+
1018
public class ParticleUtil {
1119
public static void spawnParticleCircle(Location center, double radius, Particle particle, int points) {
1220
World world = center.getWorld();
@@ -25,29 +33,25 @@ public static void spawnRotatingCircle(Location center, double radius, Particle
2533
World world = center.getWorld();
2634
if (world == null) return;
2735

28-
new BukkitRunnable() {
29-
int ticks = 0;
30-
double angleOffset = 0;
3136

32-
@Override
33-
public void run() {
34-
if (ticks >= durationTicks) {
35-
cancel();
36-
return;
37-
}
3837

39-
for (int i = 0; i < points; i++) {
40-
double angle = 2 * Math.PI * i / points + angleOffset;
41-
double x = Math.cos(angle) * radius;
42-
double z = Math.sin(angle) * radius;
43-
Location loc = center.clone().add(new Vector(x, 0, z));
44-
world.spawnParticle(particle, loc, 1, 0, 0, 0, 0);
45-
}
4638

47-
angleOffset += angularVelocity;
48-
ticks += 2;
39+
final AtomicDouble angleOffset = new AtomicDouble(0);
40+
41+
BukkitTask particleTask = Bukkit.getScheduler().runTaskTimer(plugin,()->{
42+
43+
for (int i = 0; i < points; i++) {
44+
double angle = 2 * Math.PI * i / points + angleOffset.get();
45+
double x = Math.cos(angle) * radius;
46+
double z = Math.sin(angle) * radius;
47+
Location loc = center.clone().add(new Vector(x, 0, z));
48+
world.spawnParticle(particle, loc, 1, 0, 0, 0, 0);
4949
}
50-
}.runTaskTimer(plugin, 0, 2L);
50+
angleOffset.addAndGet(angularVelocity);
51+
52+
}, 0, 2L);
53+
54+
Bukkit.getScheduler().runTaskLater(plugin, particleTask::cancel, durationTicks);
5155
}
5256

5357

0 commit comments

Comments
 (0)