From f8704eaab7e97739aa58f72f36fab19b186fb4f2 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Wed, 3 Apr 2024 23:43:52 +0200 Subject: [PATCH] Use version name for protocol auto detection --- .../util/ProtocolVersionDetector.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/protocoltranslator/util/ProtocolVersionDetector.java b/src/main/java/de/florianmichael/viafabricplus/protocoltranslator/util/ProtocolVersionDetector.java index 979c18d9..d8d5b9f5 100644 --- a/src/main/java/de/florianmichael/viafabricplus/protocoltranslator/util/ProtocolVersionDetector.java +++ b/src/main/java/de/florianmichael/viafabricplus/protocoltranslator/util/ProtocolVersionDetector.java @@ -21,6 +21,8 @@ package de.florianmichael.viafabricplus.protocoltranslator.util; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import net.lenni0451.mcping.MCPing; import net.lenni0451.mcping.responses.MCPingResponse; +import net.minecraft.util.Formatting; +import net.raphimc.vialoader.util.ProtocolVersionList; import java.net.InetSocketAddress; @@ -59,7 +61,15 @@ public class ProtocolVersionDetector { if (ProtocolVersion.isRegistered(response.version.protocol)) { // If the protocol is registered, we can use it return ProtocolVersion.getProtocol(response.version.protocol); } else { - throw new RuntimeException("Unsupported protocol version: " + response.version.protocol); + for (ProtocolVersion protocol : ProtocolVersionList.getProtocolsNewToOld()) { + for (String version : protocol.getIncludedVersions()) { + if (response.version.name.contains(version)) { + return protocol; + } + } + } + throw new RuntimeException("Unable to detect the server version\nServer sent an invalid protocol id: " + + response.version.protocol + " (" + response.version.name + Formatting.RESET + ")"); } } }