fixed playnow bug with shuffling, by rewriting the instructions to mimic the track scheduler's behaviour.

This commit is contained in:
Andrew Lalis 2017-09-02 01:04:58 +02:00 committed by Andrew Lalis
parent f0122a5098
commit a1057279e9
1 changed files with 17 additions and 2 deletions

View File

@ -1,6 +1,8 @@
package handiebot.command.commands.music; package handiebot.command.commands.music;
import com.google.api.services.youtube.model.Video; 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.HandieBot;
import handiebot.command.CommandContext; import handiebot.command.CommandContext;
import handiebot.command.ReactionHandler; import handiebot.command.ReactionHandler;
@ -11,6 +13,7 @@ import handiebot.lavaplayer.playlist.UnloadedTrack;
import handiebot.utils.MessageUtils; import handiebot.utils.MessageUtils;
import handiebot.utils.YoutubeSearch; import handiebot.utils.YoutubeSearch;
import sx.blah.discord.handle.obj.IMessage; import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IVoiceChannel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -73,7 +76,19 @@ public class PlayNowCommand extends ContextCommand {
*/ */
private void playTrackNow(UnloadedTrack track, CommandContext context){ private void playTrackNow(UnloadedTrack track, CommandContext context){
TrackScheduler scheduler = HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler; TrackScheduler scheduler = HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler;
scheduler.getActivePlaylist().getTracks().add(0, track); AudioPlayer player = HandieBot.musicPlayer.getMusicManager(context.getGuild()).player;
scheduler.nextTrack(); 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);
} }
} }