3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-25 15:50:10 +01:00

Make versions ordered by the index inserted. (Seems to work best over alphabetical)

Dieser Commit ist enthalten in:
Myles 2016-06-19 23:32:41 +01:00
Ursprung 6740c5c6dc
Commit 1217a9b7e2
2 geänderte Dateien mit 38 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -1,13 +1,16 @@
package us.myles.ViaVersion.api.protocol;
import lombok.Data;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;
import java.util.*;
@Data
@AllArgsConstructor
@Getter
public class ProtocolVersion {
private static final Map<Integer, ProtocolVersion> versions = new HashMap<>();
private static final List<ProtocolVersion> versionList = new ArrayList<>();
public static final ProtocolVersion v1_4_6;
public static final ProtocolVersion v1_5_1;
@ -52,6 +55,7 @@ public class ProtocolVersion {
public static void register(@NonNull ProtocolVersion protocol) {
versions.put(protocol.getId(), protocol);
versionList.add(protocol);
}
public static boolean isRegistered(int id) {
@ -66,7 +70,25 @@ public class ProtocolVersion {
}
}
public static int getIndex(ProtocolVersion version) {
return versionList.indexOf(version);
}
public static List<ProtocolVersion> getProtocols() {
return Collections.unmodifiableList(new ArrayList<>(versions.values()));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ProtocolVersion that = (ProtocolVersion) o;
return id == that.id;
}
@Override
public int hashCode() {
return id;
}
}

Datei anzeigen

@ -27,19 +27,25 @@ public class ListSubCmd extends ViaSubCommand {
@Override
public boolean execute(CommandSender sender, String[] args) {
Map<Integer, Set<String>> playerVersions = new HashMap<>();
Map<ProtocolVersion, Set<String>> playerVersions = new TreeMap<>(new Comparator<ProtocolVersion>() {
@Override
public int compare(ProtocolVersion o1, ProtocolVersion o2) {
return ProtocolVersion.getIndex(o2) - ProtocolVersion.getIndex(o1);
}
});
for (Player p : Bukkit.getOnlinePlayers()) {
int playerVersion = ViaVersion.getInstance().getPlayerVersion(p);
if (!playerVersions.containsKey(playerVersion))
playerVersions.put(playerVersion, new HashSet<String>());
playerVersions.get(playerVersion).add(p.getName());
ProtocolVersion key = ProtocolVersion.getProtocol(playerVersion);
if (!playerVersions.containsKey(key))
playerVersions.put(key, new HashSet<String>());
playerVersions.get(key).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());
for (Map.Entry<ProtocolVersion, Set<String>> entry : playerVersions.entrySet())
sendMessage(sender, "&8[&6%s&8]: &b%s", entry.getKey().getName(), entry.getValue());
sorted.clear();
playerVersions.clear();
return true;
}
}