From 2292175e9ad5e23f58f092a899427258a5f40f34 Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 7 Jun 2017 14:01:08 +0100 Subject: [PATCH] Ensure Bungee protocol order as well as ensuring it picks a protocol that viaversion knows. --- .../providers/BungeeVersionProvider.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeVersionProvider.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeVersionProvider.java index 674b6a367..73370cf89 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeVersionProvider.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeVersionProvider.java @@ -4,10 +4,13 @@ import com.google.common.collect.Lists; import net.md_5.bungee.api.ProxyServer; import us.myles.ViaVersion.api.Via; 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.VersionProvider; import us.myles.ViaVersion.util.ReflectionUtil; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class BungeeVersionProvider extends VersionProvider { @@ -28,21 +31,26 @@ public class BungeeVersionProvider extends VersionProvider { return super.getServerProtocol(user); // TODO Have one constant list forever until restart? (Might limit plugins if they change this) List list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSION_IDS", List.class); + List sorted = new ArrayList<>(list); + Collections.sort(sorted); ProtocolInfo info = user.get(ProtocolInfo.class); // Bungee supports it - if (list.contains(info.getProtocolVersion())) + if (sorted.contains(info.getProtocolVersion())) return info.getProtocolVersion(); // Older than bungee supports, get the lowest version - if (info.getProtocolVersion() < list.get(0)) { + if (info.getProtocolVersion() < sorted.get(0)) { return getLowestSupportedVersion(); } - // Loop through all protocols to get the closest protocol id that bungee supports - for (Integer protocol : Lists.reverse(list)) { - if (info.getProtocolVersion() > protocol) + // Loop through all protocols to get the closest protocol id that bungee supports (and that viaversion does too) + + // 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; }