package us.myles.ViaVersion.commands.defaultsubs;

import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.command.ViaSubCommand;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;

import java.util.*;

public class ListSubCmd extends ViaSubCommand {
    @Override
    public String name() {
        return "list";
    }

    @Override
    public String description() {
        return "Shows lists of the versions from logged in players";
    }

    @Override
    public String usage() {
        return "list";
    }

    @Override
    public boolean execute(CommandSender sender, String[] args) {
        Map<Integer, Set<String>> playerVersions = new HashMap<>();
        for (Player p : Bukkit.getOnlinePlayers()) {
            int playerVersion = ViaVersion.getInstance().getPlayerVersion(p);
            if (playerVersions.containsKey(playerVersion)) {
                playerVersions.get(playerVersion).add(p.getName());
                continue;
            }
            playerVersions.put(playerVersion, new HashSet<String>()).add(p.getName());

        }
        Map<Integer, Set<String>> sorted = new TreeMap<>(playerVersions);

        for (Map.Entry<Integer, Set<String>> entry : sorted.entrySet())
            sendMessage(sender, "&8[&6%s&8]: &b%s", ProtocolVersion.getProtocol(entry.getKey()).getName(), entry.getValue());

        sorted.clear();
        return true;
    }
}

@@ -930,16 +930,17 @@
     if (
+!
 playerVe
@@ -973,18 +973,16 @@
 ersion))
- %7B
 %0A       
@@ -1005,18 +1005,18 @@
 ersions.
-ge
+pu
 t(player
@@ -1026,67 +1026,33 @@
 sion
-).add(p.getName());%0A                continue;%0A            %7D
+, new HashSet%3CString%3E());
 %0A   
@@ -1067,34 +1067,34 @@
  playerVersions.
-pu
+ge
 t(playerVersion,
@@ -1092,39 +1092,16 @@
 rVersion
-, new HashSet%3CString%3E()
 ).add(p.
@@ -1108,25 +1108,24 @@
 getName());%0A
-%0A
         %7D%0A  

Fix viaversion list command