package com.robothand.highqualitybot.music;

import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;

import java.util.LinkedList;
import java.util.Queue;

/**
 * Created by ethan on 6/19/17.
 */
public class TrackScheduler extends AudioEventAdapter {
    public enum Repeat {
        OFF, SINGLE, ALL
    }

    Repeat repeating;
    final Queue<AudioTrack> queue;
    final AudioPlayer player;

    public TrackScheduler(AudioPlayer player) {
        this.player = player;
        queue = new LinkedList<>();
    }

    // TODO implement scheduler methods
    public void add(AudioTrack track) {

    }

    public void nextTrack() {

    }

    @Override
    public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason reason) {

    }

    public Repeat getRepeat() {
        return repeating;
    }

    public void setRepeat(Repeat repeating) {
        this.repeating = repeating;
    }
}

@@ -507,16 +507,24 @@
  %7D%0A%0A    
+private 
 Repeat r
@@ -533,24 +533,32 @@
 eating;%0A    
+private 
 final Queue%3C
@@ -580,16 +580,24 @@
 ue;%0A    
+private 
 final Au
@@ -613,16 +613,50 @@
  player;
+%0A    private AudioTrack prevTrack;
 %0A%0A    pu
@@ -854,46 +854,705 @@
 ) %7B%0A
-%0A    %7D%0A%0A    public void nextTrack() %7B%0A
+        if (!player.startTrack(track, true)) %7B%0A            queue.offer(track);%0A        %7D%0A    %7D%0A%0A    public void nextTrack() %7B%0A        nextTrack(false);%0A    %7D%0A%0A    public void nextTrack(boolean forceNext) %7B%0A        if (repeating == Repeat.OFF %7C%7C forceNext) %7B%0A            player.startTrack(queue.poll(), false);%0A        %7D else if (repeating == Repeat.SINGLE) %7B%0A            player.startTrack(prevTrack.makeClone(), false);%0A        %7D else if (repeating == Repeat.ALL) %7B%0A            if (prevTrack == null) %7B%0A                prevTrack = player.getPlayingTrack();%0A            %7D%0A%0A            player.startTrack(queue.poll(), false);%0A            queue.add(prevTrack);%0A            prevTrack = null;%0A        %7D
 %0A   
@@ -1664,16 +1664,63 @@
 ason) %7B%0A
+        prevTrack = track;%0A        nextTrack();
 %0A    %7D%0A%0A

implement TrackScheduler