|
19 | 19 | import com.xxmicloxx.NoteBlockAPI.NoteBlockAPI; |
20 | 20 | import com.xxmicloxx.NoteBlockAPI.event.SongDestroyingEvent; |
21 | 21 | import com.xxmicloxx.NoteBlockAPI.event.SongEndEvent; |
| 22 | +import com.xxmicloxx.NoteBlockAPI.event.SongLoopEvent; |
22 | 23 | import com.xxmicloxx.NoteBlockAPI.event.SongStoppedEvent; |
23 | 24 | import com.xxmicloxx.NoteBlockAPI.model.CustomInstrument; |
24 | 25 | import com.xxmicloxx.NoteBlockAPI.model.Fade; |
@@ -52,6 +53,7 @@ public abstract class SongPlayer { |
52 | 53 | protected int fadeDuration = 60; |
53 | 54 | protected int fadeDone = 0; |
54 | 55 | protected Fade fadeType = Fade.FADE_LINEAR; |
| 56 | + protected boolean loop = false; |
55 | 57 |
|
56 | 58 | private final Lock lock = new ReentrantLock(); |
57 | 59 |
|
@@ -254,9 +256,15 @@ private void start() { |
254 | 256 | calculateFade(); |
255 | 257 | tick++; |
256 | 258 | if (tick > song.getLength()) { |
257 | | - playing = false; |
258 | 259 | tick = -1; |
259 | | - SongEndEvent event = new SongEndEvent(SongPlayer.this); |
| 260 | + if (loop){ |
| 261 | + fadeDone = 0; |
| 262 | + SongLoopEvent event = new SongLoopEvent(this); |
| 263 | + plugin.doSync(() -> Bukkit.getPluginManager().callEvent(event)); |
| 264 | + continue; |
| 265 | + } |
| 266 | + playing = false; |
| 267 | + SongEndEvent event = new SongEndEvent(this); |
260 | 268 | plugin.doSync(() -> Bukkit.getPluginManager().callEvent(event)); |
261 | 269 | if (autoDestroy) { |
262 | 270 | destroy(); |
@@ -503,6 +511,22 @@ public void setCategory(SoundCategory soundCategory) { |
503 | 511 | this.soundCategory = soundCategory; |
504 | 512 | CallUpdate("soundCategory", soundCategory.name()); |
505 | 513 | } |
| 514 | + |
| 515 | + /** |
| 516 | + * Sets whether the SongPlayer will loop |
| 517 | + * @param playing |
| 518 | + */ |
| 519 | + public void setLoop(boolean loop){ |
| 520 | + this.loop = loop; |
| 521 | + } |
| 522 | + |
| 523 | + /** |
| 524 | + * Gets whether the SongPlayer will loop |
| 525 | + * @return is loop |
| 526 | + */ |
| 527 | + public boolean isLoop(){ |
| 528 | + return loop; |
| 529 | + } |
506 | 530 |
|
507 | 531 | void CallUpdate(String key, Object value){ |
508 | 532 | try { |
|
0 commit comments