@Override public int getServerProtocolVersion() throws Exception { return (int) ReflectionUtil.getStatic(Class.forName("net.md_5.bungee.protocol.ProtocolConstants"), "SUPPORTED_VERSION_IDS", List.class).get(0); }
public static int getLowestSupportedVersion() { List<Integer> list; try { list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSION_IDS", List.class); return list.get(0); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } // Fallback return ProxyServer.getInstance().getProtocolVersion(); } }
@Override public int getServerProtocol(UserConnection user) throws Exception { if (ref == null) return super.getServerProtocol(user); // 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> sorted = new ArrayList<>(list); Collections.sort(sorted); ProtocolInfo info = user.get(ProtocolInfo.class); // Bungee supports it if (sorted.contains(info.getProtocolVersion())) return info.getProtocolVersion(); // Older than bungee supports, get the lowest version if (info.getProtocolVersion() < sorted.get(0)) { return getLowestSupportedVersion(); } // 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; } Via.getPlatform().getLogger().severe("Panic, no protocol id found for " + info.getProtocolVersion()); return info.getProtocolVersion(); }