From a1057279e9ccc9c2513b669e9f46db26ea6d84cf Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 2 Sep 2017 01:04:58 +0200 Subject: [PATCH] fixed playnow bug with shuffling, by rewriting the instructions to mimic the track scheduler's behaviour. --- .../commands/music/PlayNowCommand.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/handiebot/command/commands/music/PlayNowCommand.java b/src/main/java/handiebot/command/commands/music/PlayNowCommand.java index a0bf26d..a284f1c 100644 --- a/src/main/java/handiebot/command/commands/music/PlayNowCommand.java +++ b/src/main/java/handiebot/command/commands/music/PlayNowCommand.java @@ -1,6 +1,8 @@ package handiebot.command.commands.music; import com.google.api.services.youtube.model.Video; +import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; +import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import handiebot.HandieBot; import handiebot.command.CommandContext; import handiebot.command.ReactionHandler; @@ -11,6 +13,7 @@ import handiebot.lavaplayer.playlist.UnloadedTrack; import handiebot.utils.MessageUtils; import handiebot.utils.YoutubeSearch; import sx.blah.discord.handle.obj.IMessage; +import sx.blah.discord.handle.obj.IVoiceChannel; import java.util.ArrayList; import java.util.List; @@ -73,7 +76,19 @@ public class PlayNowCommand extends ContextCommand { */ private void playTrackNow(UnloadedTrack track, CommandContext context){ TrackScheduler scheduler = HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler; - scheduler.getActivePlaylist().getTracks().add(0, track); - scheduler.nextTrack(); + AudioPlayer player = HandieBot.musicPlayer.getMusicManager(context.getGuild()).player; + AudioTrack currentTrack = player.getPlayingTrack(); + if (currentTrack != null){ + player.stopTrack(); + if (scheduler.isRepeating()){ + scheduler.getActivePlaylist().addTrack(new UnloadedTrack(currentTrack)); + } + } + AudioTrack aTrack = track.loadAudioTrack(); + IVoiceChannel voiceChannel = HandieBot.musicPlayer.getVoiceChannel(context.getGuild()); + if (!voiceChannel.isConnected()){ + voiceChannel.join(); + } + player.startTrack(aTrack, false); } }