package net.omniscimus.fireworks.commands;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Map;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;

import net.omniscimus.fireworks.ShowHandler;
import net.omniscimus.fireworks.commands.exceptions.WrongArgumentsNumberException;

/**
 * This command loads a saved show from savedshows.yml into the server and
 * starts it.
 *
 * @author Omniscimus
 */
public class LoadCommand extends FireworksCommand {

    private final ShowHandler showHandler;

    public LoadCommand(ShowHandler showHandler) {
        this.showHandler = showHandler;
    }

    @Override
    public void run(CommandSender sender, String[] args)
            throws WrongArgumentsNumberException, UnsupportedEncodingException {

        if (args.length == 0) {
            StringBuilder responseBuilder = new StringBuilder(ChatColor.GOLD + "Saved shows: \n");
            Map<String, ArrayList<Location>> savedShows = showHandler.getSavedShows();
            if (savedShows.isEmpty()) {
                responseBuilder.append("None.");
            } else {
                showHandler.getSavedShows().keySet().stream().forEach((showName) -> {
                    responseBuilder.append(ChatColor.RED).append(showName).append(ChatColor.RED).append(", ");
                });
            }
            sender.sendMessage(responseBuilder.toString());
        } else if (args.length == 1) {
            ArrayList<Location> showWeShouldLoad
                    = showHandler.getSavedShows().get(args[0]);
            if (showWeShouldLoad == null) {
                sender.sendMessage(ChatColor.GOLD + "Couldn't find that show.");
            } else {
                for (Location loc : showWeShouldLoad) {
                    showHandler.startShow(loc);
                }
                sender.sendMessage(
                        ChatColor.GOLD + "Show loaded successfully.");
            }
        } else {
            throw new WrongArgumentsNumberException();
        }

    }

}

@@ -1174,32 +1174,44 @@
         
-showHandler.getS
+String%5B%5D savedShowsNames = s
 avedShow
@@ -1211,18 +1211,16 @@
 vedShows
-()
 .keySet(
@@ -1225,38 +1225,96 @@
 t().
-stream().forEach((s
+toArray(new String%5B0%5D);%0A                for (int i = 0; i %3C savedS
 how
+s
 Name
-) -%3E
+s.length; i++)
  %7B%0A 
@@ -1382,16 +1382,126 @@
 nd(s
+avedS
 how
+s
 Name
-)
+s%5Bi%5D);%0A                    if (i != savedShowsNames.length - 1) %7B%0A                        responseBuilder
 .app
@@ -1506,34 +1506,35 @@
 ppend(ChatColor.
-RE
+GOL
 D).append(%22, %22);
@@ -1554,11 +1554,31 @@
     
-%7D);
+    %7D%0A                %7D
 %0A   

Improve listing of saved shows in load cmd