package protocolsupport.commands;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;

import protocolsupport.api.ProtocolSupportAPI;
import protocolsupport.api.ProtocolVersion;

public class CommandHandler implements CommandExecutor {

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
		if (!sender.hasPermission("protocolsupport.admin")) {
			sender.sendMessage(ChatColor.RED + "No permission");
			return true;
		}
		if ((args.length == 1) && args[0].equalsIgnoreCase("list")) {
			sender.sendMessage(ChatColor.GOLD+"[1.8]: "+getPlayersStringForProtocol(ProtocolVersion.MINECRAFT_1_8));
			sender.sendMessage(ChatColor.GOLD+"[1.7.10]: "+getPlayersStringForProtocol(ProtocolVersion.MINECRAFT_1_7_10));
			sender.sendMessage(ChatColor.GOLD+"[1.7.5]: "+getPlayersStringForProtocol(ProtocolVersion.MINECRAFT_1_7_5));
			sender.sendMessage(ChatColor.GOLD+"[1.6.4]: "+getPlayersStringForProtocol(ProtocolVersion.MINECRAFT_1_6_4));
			sender.sendMessage(ChatColor.GOLD+"[1.6.2]: "+getPlayersStringForProtocol(ProtocolVersion.MINECRAFT_1_6_2));
			sender.sendMessage(ChatColor.GOLD+"[1.5.2]: "+getPlayersStringForProtocol(ProtocolVersion.MINECRAFT_1_5_2));
			return true;
		}
		if ((args.length == 2) && args[0].equalsIgnoreCase("entity")) {
			sender.sendMessage(ChatColor.GOLD+"Entity: "+CraftPlayer.class.cast((sender)).getHandle().world.a(Integer.parseInt(args[1])).toString());
			return true;
		}
		return false;
	}

	private String getPlayersStringForProtocol(ProtocolVersion version) {
		StringBuilder sb = new StringBuilder();
		for (Player player : Bukkit.getOnlinePlayers()) {
			if (ProtocolSupportAPI.getProtocolVersion(player) == version) {
				sb.append(player.getName());
				sb.append(", ");
			}
		}
		return sb.toString();
	}

}

@@ -206,66 +206,8 @@
 er;%0A
-import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;%0A
 impo
@@ -235,16 +235,16 @@
 Player;%0A
+
 %0Aimport 
@@ -728,24 +728,40 @@
 D+%22%5B1.8%5D: %22+
+ChatColor.GREEN+
 getPlayersSt
@@ -855,24 +855,40 @@
 %5B1.7.10%5D: %22+
+ChatColor.GREEN+
 getPlayersSt
@@ -984,24 +984,40 @@
 %22%5B1.7.5%5D: %22+
+ChatColor.GREEN+
 getPlayersSt
@@ -1112,24 +1112,40 @@
 %22%5B1.6.4%5D: %22+
+ChatColor.GREEN+
 getPlayersSt
@@ -1240,24 +1240,40 @@
 %22%5B1.6.2%5D: %22+
+ChatColor.GREEN+
 getPlayersSt
@@ -1372,16 +1372,32 @@
 5.2%5D: %22+
+ChatColor.GREEN+
 getPlaye
@@ -1475,235 +1475,8 @@
 %09%09%7D%0A
-%09%09if ((args.length == 2) && args%5B0%5D.equalsIgnoreCase(%22entity%22)) %7B%0A%09%09%09sender.sendMessage(ChatColor.GOLD+%22Entity: %22+CraftPlayer.class.cast((sender)).getHandle().world.a(Integer.parseInt(args%5B1%5D)).toString());%0A%09%09%09return true;%0A%09%09%7D%0A
 %09%09re
@@ -1777,16 +1777,16 @@
 (%22, %22);%0A
-
 %09%09%09%7D%0A%09%09%7D
@@ -1782,24 +1782,97 @@
 );%0A%09%09%09%7D%0A%09%09%7D%0A
+%09%09if (sb.length() %3E 2) %7B%0A%09%09%09sb.delete(sb.length() - 2, sb.length());%0A%09%09%7D%0A
 %09%09return sb.

Change list command format