package com.robothand.highqualitybot.command;

import com.robothand.highqualitybot.Bot;
import com.robothand.highqualitybot.music.GuildMusicPlayer;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

/**
 * Created by ethan on 6/19/17.
 */
public class PlayCommand extends Command {

    @Override
    public String[] getNames() {
        return new String[] {"play"};
    }

    @Override
    public String getDescription() {
        return "With no arguments, resumes playback if the player is paused. Providing a valid audio source (YouTube" +
                "link, SoundCloud, etc.) as an argument will add it to the queue.\n" +
                "Usage: " + Bot.PREFIX + "play [link]";
    }

    @Override
    public String getShortDesc() {
        return "Resume the player, or provide a link to add a song to the queue!";
    }

    @Override
    public void onCommand(MessageReceivedEvent event, String[] args) {
        GuildMusicPlayer musicPlayer;
        Guild guild = event.getGuild();
        MessageChannel channel = event.getChannel();

        // Get player for this guild
        musicPlayer = GuildMusicPlayer.getPlayer(guild);

        // join sender's channel if player is not already in one
        if (!musicPlayer.isInChannel()) {
            musicPlayer.joinChannel(event.getMember().getVoiceState().getChannel());
        }

        if (args.length > 1) {
            String search = "";
            for (int i = 1; i < args.length; i++) {
                search = search.concat(args[i]);
            }

            musicPlayer.playTrack(search, channel);
        } else {
            if (musicPlayer.isPaused()) {
                musicPlayer.setPaused(false);
                channel.sendMessage("Player resumed.").queue();
            } else {
                channel.sendMessage("The player is already running!").queue();
            }
        }
    }
}
@@ -238,16 +238,67 @@
 hannel;%0A
+import net.dv8tion.jda.core.entities.VoiceChannel;%0A
 import n
@@ -1318,21 +1318,17 @@
  // 
-join sender's
+Auto-join
  cha
@@ -1422,78 +1422,462 @@
     
-musicPlayer.joinChannel(event.getMember().getVoiceState().getChannel()
+VoiceChannel voice = event.getMember().getVoiceState().getChannel();%0A            if (event.getMember().getVoiceState().inVoiceChannel()) %7B%0A                // first try sender's channel%0A                voice = event.getMember().getVoiceState().getChannel();%0A            %7D else %7B%0A                // otherwise we should just join the first ava%0A                voice = guild.getVoiceChannels().get(0);%0A            %7D%0A%0A            musicPlayer.joinChannel(voice
 );%0A 

Resolve #2 (#6)