Skip to content

Commit c373c7d

Browse files
committed
Added loop feature
Loop added to SongPlayer. Added SongLoopEvent. Bug fixes.
1 parent 5307d1f commit c373c7d

File tree

9 files changed

+76
-4
lines changed

9 files changed

+76
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# NoteBlockAPI
2-
[![](https://jitpack.io/v/koca2000/NoteBlockAPI.svg)](https://jitpack.io/#koca2000/NoteBlockAPI)
2+
[![](https://jitpack.io/v/koca2000/NoteBlockAPI.svg)](https://jitpack.io/#koca2000/NoteBlockAPI) [![Build Status](http://ci.haprosgames.com/buildStatus/icon?job=NoteBlockAPI)](http://ci.haprosgames.com/job/NoteBlockAPI)
33

4-
For information about this Spigot/Bukkit API, go to https://www.spigotmc.org/resources/noteblockapi.19287/
4+
For information about this Spigot/Bukkit API, go to https://www.spigotmc.org/resources/noteblockapi.19287/
5+
Dev builds are available at [Jenkins](http://ci.haprosgames.com/job/NoteBlockAPI/ "Jenkins")

src/main/java/com/xxmicloxx/NoteBlockAPI/NoteBlockSongPlayer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public NoteBlockSongPlayer(Song song, SoundCategory soundCategory) {
2727
super(song, soundCategory);
2828
makeNewClone(com.xxmicloxx.NoteBlockAPI.songplayer.NoteBlockSongPlayer.class);
2929
}
30+
31+
public NoteBlockSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer songPlayer) {
32+
super(songPlayer);
33+
}
3034

3135
@Override
3236
void update(String key, Object value) {

src/main/java/com/xxmicloxx/NoteBlockAPI/PositionSongPlayer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public PositionSongPlayer(Song song, SoundCategory soundCategory) {
2727
makeNewClone(com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer.class);
2828
}
2929

30+
public PositionSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer songPlayer) {
31+
super(songPlayer);
32+
}
33+
3034
@Override
3135
void update(String key, Object value) {
3236
super.update(key, value);

src/main/java/com/xxmicloxx/NoteBlockAPI/RadioSongPlayer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public RadioSongPlayer(Song song, SoundCategory soundCategory) {
2020
super(song, soundCategory);
2121
makeNewClone(com.xxmicloxx.NoteBlockAPI.songplayer.RadioSongPlayer.class);
2222
}
23+
24+
public RadioSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer songPlayer) {
25+
super(songPlayer);
26+
}
2327

2428
@Override
2529
public void playTick(Player player, int tick) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.xxmicloxx.NoteBlockAPI.event;
2+
3+
import org.bukkit.event.Event;
4+
import org.bukkit.event.HandlerList;
5+
6+
import com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer;
7+
8+
public class SongLoopEvent extends Event {
9+
10+
private static final HandlerList handlers = new HandlerList();
11+
private SongPlayer song;
12+
13+
public SongLoopEvent(SongPlayer song) {
14+
this.song = song;
15+
}
16+
17+
public static HandlerList getHandlerList() {
18+
return handlers;
19+
}
20+
21+
public SongPlayer getSongPlayer() {
22+
return song;
23+
}
24+
25+
public HandlerList getHandlers() {
26+
return handlers;
27+
}
28+
29+
}

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/NoteBlockSongPlayer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ public class NoteBlockSongPlayer extends RangeSongPlayer {
2727

2828
public NoteBlockSongPlayer(Song song) {
2929
super(song);
30+
makeNewClone(com.xxmicloxx.NoteBlockAPI.NoteBlockSongPlayer.class);
3031
}
3132

3233
public NoteBlockSongPlayer(Song song, SoundCategory soundCategory) {
3334
super(song, soundCategory);
35+
makeNewClone(com.xxmicloxx.NoteBlockAPI.NoteBlockSongPlayer.class);
3436
}
3537

3638

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/PositionSongPlayer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ public class PositionSongPlayer extends RangeSongPlayer {
2727

2828
public PositionSongPlayer(Song song) {
2929
super(song);
30+
makeNewClone(com.xxmicloxx.NoteBlockAPI.PositionSongPlayer.class);
3031
}
3132

3233
public PositionSongPlayer(Song song, SoundCategory soundCategory) {
3334
super(song, soundCategory);
35+
makeNewClone(com.xxmicloxx.NoteBlockAPI.PositionSongPlayer.class);
3436
}
3537

3638
private PositionSongPlayer(SongPlayer songPlayer) {

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/RadioSongPlayer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ public class RadioSongPlayer extends SongPlayer {
2020

2121
public RadioSongPlayer(Song song) {
2222
super(song);
23+
makeNewClone(com.xxmicloxx.NoteBlockAPI.RadioSongPlayer.class);
2324
}
2425

2526
public RadioSongPlayer(Song song, SoundCategory soundCategory) {
2627
super(song, soundCategory);
28+
makeNewClone(com.xxmicloxx.NoteBlockAPI.RadioSongPlayer.class);
2729
}
2830

2931

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/SongPlayer.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.xxmicloxx.NoteBlockAPI.NoteBlockAPI;
2020
import com.xxmicloxx.NoteBlockAPI.event.SongDestroyingEvent;
2121
import com.xxmicloxx.NoteBlockAPI.event.SongEndEvent;
22+
import com.xxmicloxx.NoteBlockAPI.event.SongLoopEvent;
2223
import com.xxmicloxx.NoteBlockAPI.event.SongStoppedEvent;
2324
import com.xxmicloxx.NoteBlockAPI.model.CustomInstrument;
2425
import com.xxmicloxx.NoteBlockAPI.model.Fade;
@@ -52,6 +53,7 @@ public abstract class SongPlayer {
5253
protected int fadeDuration = 60;
5354
protected int fadeDone = 0;
5455
protected Fade fadeType = Fade.FADE_LINEAR;
56+
protected boolean loop = false;
5557

5658
private final Lock lock = new ReentrantLock();
5759

@@ -254,9 +256,15 @@ private void start() {
254256
calculateFade();
255257
tick++;
256258
if (tick > song.getLength()) {
257-
playing = false;
258259
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);
260268
plugin.doSync(() -> Bukkit.getPluginManager().callEvent(event));
261269
if (autoDestroy) {
262270
destroy();
@@ -503,6 +511,22 @@ public void setCategory(SoundCategory soundCategory) {
503511
this.soundCategory = soundCategory;
504512
CallUpdate("soundCategory", soundCategory.name());
505513
}
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+
}
506530

507531
void CallUpdate(String key, Object value){
508532
try {

0 commit comments

Comments
 (0)