3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +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; package us.myles.ViaVersion.api.protocol;
import lombok.Data; import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import java.util.*; import java.util.*;
@Data @AllArgsConstructor
@Getter
public class ProtocolVersion { public class ProtocolVersion {
private static final Map<Integer, ProtocolVersion> versions = new HashMap<>(); 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_4_6;
public static final ProtocolVersion v1_5_1; public static final ProtocolVersion v1_5_1;
@ -52,6 +55,7 @@ public class ProtocolVersion {
public static void register(@NonNull ProtocolVersion protocol) { public static void register(@NonNull ProtocolVersion protocol) {
versions.put(protocol.getId(), protocol); versions.put(protocol.getId(), protocol);
versionList.add(protocol);
} }
public static boolean isRegistered(int id) { 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() { public static List<ProtocolVersion> getProtocols() {
return Collections.unmodifiableList(new ArrayList<>(versions.values())); 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 @Override
public boolean execute(CommandSender sender, String[] args) { 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()) { for (Player p : Bukkit.getOnlinePlayers()) {
int playerVersion = ViaVersion.getInstance().getPlayerVersion(p); int playerVersion = ViaVersion.getInstance().getPlayerVersion(p);
if (!playerVersions.containsKey(playerVersion)) ProtocolVersion key = ProtocolVersion.getProtocol(playerVersion);
playerVersions.put(playerVersion, new HashSet<String>()); if (!playerVersions.containsKey(key))
playerVersions.get(playerVersion).add(p.getName()); 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()) for (Map.Entry<ProtocolVersion, Set<String>> entry : playerVersions.entrySet())
sendMessage(sender, "&8[&6%s&8]: &b%s", ProtocolVersion.getProtocol(entry.getKey()).getName(), entry.getValue()); sendMessage(sender, "&8[&6%s&8]: &b%s", entry.getKey().getName(), entry.getValue());
sorted.clear(); playerVersions.clear();
return true; return true;
} }
} }