11package de .codeblocksmc .codelib .util ;
22
3+ import com .google .common .util .concurrent .AtomicDouble ;
4+ import org .bukkit .Bukkit ;
35import org .bukkit .Location ;
46import org .bukkit .Particle ;
57import org .bukkit .World ;
68import org .bukkit .plugin .Plugin ;
79import org .bukkit .scheduler .BukkitRunnable ;
10+ import org .bukkit .scheduler .BukkitTask ;
811import org .bukkit .util .Vector ;
912
13+ /*
14+ * @author Try
15+ * @version 1.1
16+ */
17+
1018public 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