Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Fix isWorkingPipe and cursed ProtocolVersion comparator
Dieser Commit ist enthalten in:
Ursprung
293427c172
Commit
35578372a1
@ -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) {
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren