3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-19 14:30:16 +01:00

Fix isWorkingPipe and cursed ProtocolVersion comparator

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-02-14 22:45:34 +01:00
Ursprung 293427c172
Commit 35578372a1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
2 geänderte Dateien mit 11 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -84,7 +84,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
public static final ProtocolVersion v1_20_2 = register(764, "1.20.2"); public static final ProtocolVersion v1_20_2 = register(764, "1.20.2");
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3/1.20.4", new SubVersionRange("1.20", 3, 4)); public static final ProtocolVersion v1_20_3 = register(765, "1.20.3/1.20.4", new SubVersionRange("1.20", 3, 4));
public static final ProtocolVersion v1_20_5 = register(766, 177, "1.20.5"); public static final ProtocolVersion v1_20_5 = register(766, 177, "1.20.5");
public static final ProtocolVersion unknown = register(-1, "UNKNOWN"); public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null);
public static ProtocolVersion register(int version, String name) { public static ProtocolVersion register(int version, String name) {
return register(version, -1, name); return register(version, -1, name);
@ -108,10 +108,8 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
* @param protocolVersion protocol version to register * @param protocolVersion protocol version to register
*/ */
public static void register(ProtocolVersion protocolVersion) { public static void register(ProtocolVersion protocolVersion) {
if (protocolVersion != unknown) {
VERSION_LIST.add(protocolVersion); VERSION_LIST.add(protocolVersion);
VERSION_LIST.sort(ProtocolVersion::compareTo); VERSION_LIST.sort(ProtocolVersion::compareTo);
}
final Int2ObjectMap<ProtocolVersion> versions = VERSIONS.computeIfAbsent(protocolVersion.versionType, $ -> new Int2ObjectOpenHashMap<>()); final Int2ObjectMap<ProtocolVersion> versions = VERSIONS.computeIfAbsent(protocolVersion.versionType, $ -> new Int2ObjectOpenHashMap<>());
versions.put(protocolVersion.version, protocolVersion); versions.put(protocolVersion.version, protocolVersion);
@ -463,11 +461,14 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
@Override @Override
public int compareTo(final ProtocolVersion other) { public int compareTo(final ProtocolVersion other) {
if (customComparator() != null) { // Cursed custom comparators
if (this.versionType == VersionType.SPECIAL && customComparator() != null) {
return customComparator().compare(this, other); return customComparator().compare(this, other);
} else if (other.customComparator() != null) { } else if (other.versionType == VersionType.SPECIAL && other.customComparator() != null) {
return other.customComparator().compare(other, this); return other.customComparator().compare(this, other);
} else if (this.versionType != other.versionType) { }
if (this.versionType != other.versionType) {
// Compare by version type first since version ids have reset multiple times // Compare by version type first since version ids have reset multiple times
return this.versionType.ordinal() < other.versionType.ordinal() ? -1 : 1; return this.versionType.ordinal() < other.versionType.ordinal() ? -1 : 1;
} else if (this.version != other.version) { } else if (this.version != other.version) {

Datei anzeigen

@ -386,7 +386,7 @@ public class ProtocolManagerImpl implements ProtocolManager {
public boolean isWorkingPipe() { public boolean isWorkingPipe() {
for (Object2ObjectMap<ProtocolVersion, Protocol> map : registryMap.values()) { for (Object2ObjectMap<ProtocolVersion, Protocol> map : registryMap.values()) {
for (ProtocolVersion protocolVersion : serverProtocolVersion.supportedProtocolVersions()) { for (ProtocolVersion protocolVersion : serverProtocolVersion.supportedProtocolVersions()) {
if (map.containsKey(protocolVersion.getVersion())) { if (map.containsKey(protocolVersion)) {
return true; return true;
} }
} }