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.io.File;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class SongPlayer extends SessionAdapter {
|
public class SongPlayer extends SessionAdapter {
|
||||||
private final ChipmunkBot client;
|
private final ChipmunkBot client;
|
||||||
|
@ -27,6 +28,7 @@ public class SongPlayer extends SessionAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter @Setter private Song currentSong;
|
@Getter @Setter private Song currentSong;
|
||||||
|
@Getter @Setter private LinkedList<Song> songQueue = new LinkedList<>();
|
||||||
@Getter @Setter private Timer playTimer;
|
@Getter @Setter private Timer playTimer;
|
||||||
@Getter @Setter private SongLoaderThread loaderThread;
|
@Getter @Setter private SongLoaderThread loaderThread;
|
||||||
private int ticksUntilPausedActionbar = 20;
|
private int ticksUntilPausedActionbar = 20;
|
||||||
|
@ -66,14 +68,19 @@ public class SongPlayer extends SessionAdapter {
|
||||||
if (loaderThread.exception != null) {
|
if (loaderThread.exception != null) {
|
||||||
client.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED));
|
client.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED));
|
||||||
} else {
|
} else {
|
||||||
currentSong = loaderThread.song;
|
songQueue.add(loaderThread.song);
|
||||||
client.chat().tellraw(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN));
|
client.chat().tellraw(Component.translatable("Added %s to the song queue", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN));
|
||||||
currentSong.play();
|
|
||||||
}
|
}
|
||||||
loaderThread = null;
|
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;
|
if (currentSong.paused && ticksUntilPausedActionbar-- < 0) return;
|
||||||
else ticksUntilPausedActionbar = 20;
|
else ticksUntilPausedActionbar = 20;
|
||||||
|
|
Loading…
Reference in a new issue