mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-11-21 11:45:16 +01:00
Added support for snapshot client versions (Still requires VV dev access)
This commit is contained in:
parent
f155799a36
commit
a4099d760f
@ -22,6 +22,7 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
|||||||
import com.viaversion.viaversion.api.protocol.version.VersionType;
|
import com.viaversion.viaversion.api.protocol.version.VersionType;
|
||||||
import com.viaversion.viaversion.protocol.RedirectProtocolVersion;
|
import com.viaversion.viaversion.protocol.RedirectProtocolVersion;
|
||||||
import com.viaversion.viaversion.protocol.version.BaseVersionProvider;
|
import com.viaversion.viaversion.protocol.version.BaseVersionProvider;
|
||||||
|
import net.raphimc.netminecraft.constants.MCVersion;
|
||||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||||
|
|
||||||
public class ViaProxyVersionProvider extends BaseVersionProvider {
|
public class ViaProxyVersionProvider extends BaseVersionProvider {
|
||||||
@ -42,7 +43,15 @@ public class ViaProxyVersionProvider extends BaseVersionProvider {
|
|||||||
if (connection.isClientSide()) {
|
if (connection.isClientSide()) {
|
||||||
return ProxyConnection.fromUserConnection(connection).getServerVersion();
|
return ProxyConnection.fromUserConnection(connection).getServerVersion();
|
||||||
} else if (clientProtocol.getVersionType() == VersionType.RELEASE) {
|
} else if (clientProtocol.getVersionType() == VersionType.RELEASE) {
|
||||||
|
if (MCVersion.ALL_VERSIONS.containsKey(clientProtocol.getVersion())) {
|
||||||
return clientProtocol;
|
return clientProtocol;
|
||||||
|
} else { // Version not supported by NetMinecraft
|
||||||
|
return MCVersion.ALL_VERSIONS.keySet().stream().min((o1, o2) -> {
|
||||||
|
final int diff1 = Math.abs(o1 - clientProtocol.getVersion());
|
||||||
|
final int diff2 = Math.abs(o2 - clientProtocol.getVersion());
|
||||||
|
return Integer.compare(diff1, diff2);
|
||||||
|
}).map(ProtocolVersion::getProtocol).orElse(ProtocolVersion.unknown);
|
||||||
|
}
|
||||||
} else if (clientProtocol instanceof RedirectProtocolVersion redirectProtocolVersion) {
|
} else if (clientProtocol instanceof RedirectProtocolVersion redirectProtocolVersion) {
|
||||||
return redirectProtocolVersion.getOrigin();
|
return redirectProtocolVersion.getOrigin();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user