Skip to content

Commit

Permalink
Shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Dec 29, 2016
1 parent 68ae358 commit 72c279b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/main/java/net/dv8tion/discord/music/PlayerControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,17 @@ else if (".list".equals(command[0]))
}
}
}
else if (".shuffle".equals(command[0]))
{
if (scheduler.queue.isEmpty())
{
event.getChannel().sendMessage("The queue is currently empty!").queue();
return;
}

scheduler.shuffle();
event.getChannel().sendMessage("The queue has been shuffled!").queue();
}
}

private void loadAndPlay(GuildMusicManager mng, final MessageChannel channel, final String trackUrl, final boolean addPlaylist)
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/net/dv8tion/discord/music/TrackScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
* This class schedules tracks for the audio player. It contains the queue of tracks.
Expand All @@ -15,7 +17,7 @@ public class TrackScheduler extends AudioEventAdapter
{
private boolean repeating = false;
final AudioPlayer player;
final BlockingQueue<AudioTrack> queue;
final Queue<AudioTrack> queue;
AudioTrack lastTrack;

/**
Expand All @@ -24,7 +26,7 @@ public class TrackScheduler extends AudioEventAdapter
public TrackScheduler(AudioPlayer player)
{
this.player = player;
this.queue = new LinkedBlockingQueue<>();
this.queue = new LinkedList<>();
}

/**
Expand Down Expand Up @@ -78,4 +80,9 @@ public void setRepeating(boolean repeating)
{
this.repeating = repeating;
}

public void shuffle()
{
Collections.shuffle((List<?>) queue);
}
}

0 comments on commit 72c279b

Please sign in to comment.