/*
 * Copyright  2014 - 2017 | Wurst-Imperium | All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package net.wurstclient.features.commands;

import java.util.Iterator;

import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.util.StringUtils;
import net.wurstclient.altmanager.Alt;
import net.wurstclient.altmanager.screens.GuiAltList;
import net.wurstclient.compatibility.WMinecraft;
import net.wurstclient.files.ConfigFiles;
import net.wurstclient.utils.ChatUtils;

@Cmd.Info(
	description = "Adds a player or all players on a server to your alt list.",
	name = "addalt",
	syntax = {"<player>", "all"},
	help = "Commands/addalt")
public final class AddAltCmd extends Cmd
{
	@Override
	public void execute(String[] args) throws CmdError
	{
		if(args.length != 1)
			syntaxError();
		if(args[0].equals("all"))
		{
			int alts = 0;
			Iterator itr = mc.getNetHandler().getPlayerInfoMap().iterator();
			while(itr.hasNext())
			{
				NetworkPlayerInfo info = (NetworkPlayerInfo)itr.next();
				String crackedName =
					StringUtils.stripControlCodes(info.getPlayerNameForReal());
				if(crackedName.equals(WMinecraft.getPlayer().getName())
					|| crackedName.equals("Alexander01998") || GuiAltList.alts
						.contains(new Alt(crackedName, null, null)))
					continue;
				GuiAltList.alts.add(new Alt(crackedName, null, null));
				alts++;
			}
			if(alts == 1)
				ChatUtils.message("Added 1 alt to the alt list.");
			else
				ChatUtils.message("Added " + alts + " alts to the alt list.");
			GuiAltList.sortAlts();
			ConfigFiles.ALTS.save();
		}else if(!args[0].equals("Alexander01998"))
		{
			GuiAltList.alts.add(new Alt(args[0], null, null));
			GuiAltList.sortAlts();
			ConfigFiles.ALTS.save();
			ChatUtils.message("Added \"" + args[0] + "\" to the alt list.");
		}
	}
}

@@ -319,36 +319,8 @@
 s;%0A%0A
-import java.util.Iterator;%0A%0A
 impo
@@ -948,16 +948,19 @@
 rror();%0A
+%09%09%0A
 %09%09if(arg
@@ -1007,161 +1007,93 @@
 %0A%09%09%09
-Iterator itr = mc.getNetHandler().getPlayerInfoMap().iterator();%0A%09%09%09while(itr.hasNext())%0A%09%09%09%7B%0A%09%09%09%09NetworkPlayerInfo info = (NetworkPlayerInfo)itr.next();
+for(NetworkPlayerInfo info : WMinecraft.getConnection()%0A%09%09%09%09.getPlayerInfoMap())%0A%09%09%09%7B
 %0A%09%09%09
@@ -1100,24 +1100,17 @@
 %09String 
-crackedN
+n
 ame =%0A%09%09
@@ -1180,19 +1180,17 @@
 %09%09%09%09
-if(crackedN
+%0A%09%09%09%09if(n
 ame.
@@ -1238,24 +1238,17 @@
 %09%09%09%09%09%7C%7C 
-crackedN
+n
 ame.equa
@@ -1267,17 +1267,22 @@
 r01998%22)
- 
+%0A%09%09%09%09%09
 %7C%7C GuiAl
@@ -1295,15 +1295,8 @@
 alts
-%0A%09%09%09%09%09%09
 .con
@@ -1305,32 +1305,25 @@
 ins(new Alt(
-crackedN
+n
 ame, null, n
@@ -1344,16 +1344,21 @@
 ntinue;%0A
+%09%09%09%09%0A
 %09%09%09%09GuiA
@@ -1385,16 +1385,9 @@
 Alt(
-crackedN
+n
 ame,
@@ -1418,16 +1418,20 @@
 +;%0A%09%09%09%7D%0A
+%09%09%09%0A
 %09%09%09if(al
@@ -1473,32 +1473,16 @@
 ed 1 alt
- to the alt list
 .%22);%0A%09%09%09
@@ -1532,36 +1532,24 @@
 + %22 alts
- to the alt list
 .%22);
+%0A%09%09%09
 %0A%09%09%09GuiA
@@ -1595,16 +1595,20 @@
 save();%0A
+%09%09%09%0A
 %09%09%7Delse 
@@ -1703,16 +1703,20 @@
 null));%0A
+%09%09%09%0A
 %09%09%09GuiAl
@@ -1757,24 +1757,28 @@
 LTS.save();%0A
+%09%09%09%0A
 %09%09%09ChatUtils
@@ -1797,42 +1797,12 @@
 ded 
-%5C%22%22 + args%5B0%5D + %22%5C%22 to the alt lis
+1 al
 t.%22)

Update AddAltCmd