@Override public int getServerProtocol(UserConnection user) throws Exception { int playerVersion = user.get(ProtocolInfo.class).getProtocolVersion(); // Bungee supports it if (Collections.binarySearch(VELOCITY_PROTOCOLS, playerVersion) >= 0) return playerVersion; // Older than bungee supports, get the lowest version if (playerVersion < VELOCITY_PROTOCOLS.get(0)) { return VelocityViaInjector.getLowestSupportedProtocolVersion(); } // 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(VELOCITY_PROTOCOLS)) { if (playerVersion > protocol && ProtocolVersion.isRegistered(protocol)) return protocol; } Via.getPlatform().getLogger().severe("Panic, no protocol id found for " + playerVersion); return playerVersion; } }
@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(); }