Use existing ProtocolVersion#getProtocol when possible (#3720)

This commit is contained in:
EnZaXD 2024-02-27 14:02:16 +01:00 committed by GitHub
parent 26a8e5fef1
commit 3c0930c62f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 5 deletions

View File

@ -139,7 +139,7 @@ public interface ProtocolManager {
@Deprecated @Deprecated
default @Nullable List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion) { default @Nullable List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion) {
return getProtocolPath(ProtocolVersion.getProtocol(VersionType.RELEASE, clientVersion), ProtocolVersion.getProtocol(VersionType.RELEASE, serverVersion)); return getProtocolPath(ProtocolVersion.getProtocol(clientVersion), ProtocolVersion.getProtocol(serverVersion));
} }
/** /**

View File

@ -162,7 +162,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
private BlockedProtocolVersions loadBlockedProtocolVersions() { private BlockedProtocolVersions loadBlockedProtocolVersions() {
List<Integer> blockProtocols = getListSafe("block-protocols", Integer.class, "Invalid blocked version protocol found in config: '%s'"); List<Integer> blockProtocols = getListSafe("block-protocols", Integer.class, "Invalid blocked version protocol found in config: '%s'");
List<String> blockVersions = getListSafe("block-versions", String.class, "Invalid blocked version found in config: '%s'"); List<String> blockVersions = getListSafe("block-versions", String.class, "Invalid blocked version found in config: '%s'");
ObjectSet<ProtocolVersion> blockedProtocols = blockProtocols.stream().map(integer -> ProtocolVersion.getProtocol(VersionType.RELEASE, integer)).collect(ObjectOpenHashSet::of, ObjectSet::add, ObjectSet::addAll); ObjectSet<ProtocolVersion> blockedProtocols = blockProtocols.stream().map(ProtocolVersion::getProtocol).collect(ObjectOpenHashSet::of, ObjectSet::add, ObjectSet::addAll);
ProtocolVersion lowerBound = ProtocolVersion.unknown; ProtocolVersion lowerBound = ProtocolVersion.unknown;
ProtocolVersion upperBound = ProtocolVersion.unknown; ProtocolVersion upperBound = ProtocolVersion.unknown;
for (String s : blockVersions) { for (String s : blockVersions) {

View File

@ -45,20 +45,20 @@ public abstract class AbstractProtocolDetectorService implements ProtocolDetecto
lock.readLock().unlock(); lock.readLock().unlock();
} }
if (detectedProtocol != -1) { if (detectedProtocol != -1) {
return ProtocolVersion.getProtocol(VersionType.RELEASE, detectedProtocol); return ProtocolVersion.getProtocol(detectedProtocol);
} }
// Step 2. Check config (CME moment?) // Step 2. Check config (CME moment?)
final Map<String, Integer> servers = configuredServers(); final Map<String, Integer> servers = configuredServers();
final Integer protocol = servers.get(serverName); final Integer protocol = servers.get(serverName);
if (protocol != null) { if (protocol != null) {
return ProtocolVersion.getProtocol(VersionType.RELEASE, protocol); return ProtocolVersion.getProtocol(protocol);
} }
// Step 3. Use Default (CME moment intensifies?) // Step 3. Use Default (CME moment intensifies?)
final Integer defaultProtocol = servers.get("default"); final Integer defaultProtocol = servers.get("default");
if (defaultProtocol != null) { if (defaultProtocol != null) {
return ProtocolVersion.getProtocol(VersionType.RELEASE, defaultProtocol); return ProtocolVersion.getProtocol(defaultProtocol);
} }
// Step 4: Use the proxy's lowest supported... *cries* // Step 4: Use the proxy's lowest supported... *cries*