Ensure Bungee protocol order as well as ensuring it picks a protocol that viaversion knows.

This commit is contained in:
Myles 2017-06-07 14:01:08 +01:00
parent ef04346019
commit 2292175e9a

View File

@ -4,10 +4,13 @@ import com.google.common.collect.Lists;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.base.VersionProvider; import us.myles.ViaVersion.protocols.base.VersionProvider;
import us.myles.ViaVersion.util.ReflectionUtil; import us.myles.ViaVersion.util.ReflectionUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
public class BungeeVersionProvider extends VersionProvider { public class BungeeVersionProvider extends VersionProvider {
@ -28,21 +31,26 @@ public class BungeeVersionProvider extends VersionProvider {
return super.getServerProtocol(user); return super.getServerProtocol(user);
// TODO Have one constant list forever until restart? (Might limit plugins if they change this) // TODO Have one constant list forever until restart? (Might limit plugins if they change this)
List<Integer> list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSION_IDS", List.class); List<Integer> list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSION_IDS", List.class);
List<Integer> sorted = new ArrayList<>(list);
Collections.sort(sorted);
ProtocolInfo info = user.get(ProtocolInfo.class); ProtocolInfo info = user.get(ProtocolInfo.class);
// Bungee supports it // Bungee supports it
if (list.contains(info.getProtocolVersion())) if (sorted.contains(info.getProtocolVersion()))
return info.getProtocolVersion(); return info.getProtocolVersion();
// Older than bungee supports, get the lowest version // Older than bungee supports, get the lowest version
if (info.getProtocolVersion() < list.get(0)) { if (info.getProtocolVersion() < sorted.get(0)) {
return getLowestSupportedVersion(); return getLowestSupportedVersion();
} }
// Loop through all protocols to get the closest protocol id that bungee supports // Loop through all protocols to get the closest protocol id that bungee supports (and that viaversion does too)
for (Integer protocol : Lists.reverse(list)) {
if (info.getProtocolVersion() > protocol) // TODO: This needs a better fix, i.e checking ProtocolRegistry to see if it would work.
// This is more of a workaround for snapshot support by bungee.
for (Integer protocol : Lists.reverse(sorted)) {
if (info.getProtocolVersion() > protocol && ProtocolVersion.isRegistered(protocol))
return protocol; return protocol;
} }