diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java index 66d1ee2..1fe2ba8 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java @@ -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 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;