Implement the song queue
This commit is contained in:
parent
8d4274883b
commit
0755e1b505
1 changed files with 11 additions and 4 deletions
|
@ -15,6 +15,7 @@ import lombok.Setter;
|
|||
import java.io.File;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class SongPlayer extends SessionAdapter {
|
||||
private final ChipmunkBot client;
|
||||
|
@ -27,6 +28,7 @@ public class SongPlayer extends SessionAdapter {
|
|||
}
|
||||
|
||||
@Getter @Setter private Song currentSong;
|
||||
@Getter @Setter private LinkedList<Song> songQueue = new LinkedList<>();
|
||||
@Getter @Setter private Timer playTimer;
|
||||
@Getter @Setter private SongLoaderThread loaderThread;
|
||||
private int ticksUntilPausedActionbar = 20;
|
||||
|
@ -66,14 +68,19 @@ public class SongPlayer extends SessionAdapter {
|
|||
if (loaderThread.exception != null) {
|
||||
client.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED));
|
||||
} else {
|
||||
currentSong = loaderThread.song;
|
||||
client.chat().tellraw(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN));
|
||||
currentSong.play();
|
||||
songQueue.add(loaderThread.song);
|
||||
client.chat().tellraw(Component.translatable("Added %s to the song queue", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN));
|
||||
}
|
||||
loaderThread = null;
|
||||
}
|
||||
|
||||
if (currentSong == null) return;
|
||||
if (currentSong == null) {
|
||||
if (songQueue.size() == 0) return;
|
||||
|
||||
currentSong = songQueue.poll();
|
||||
client.chat().tellraw(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN));
|
||||
currentSong.play();
|
||||
}
|
||||
|
||||
if (currentSong.paused && ticksUntilPausedActionbar-- < 0) return;
|
||||
else ticksUntilPausedActionbar = 20;
|
||||
|
|
Loading…
Reference in a new issue