@Override public int getPlayerVersion(@NonNull UUID uuid) { if (!isPorted(uuid)) { return VelocityPlugin.PROXY.getPlayer(uuid) .map(InboundConnection::getProtocolVersion) .map(ProtocolVersion::getProtocol) .orElse(ProtocolRegistry.SERVER_PROTOCOL); } return getPortedPlayers().get(uuid).get(ProtocolInfo.class).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(); }
@Override public int getPlayerVersion(@NonNull UUID uuid) { if (!isPorted(uuid)) return ProtocolRegistry.SERVER_PROTOCOL; return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion(); }
@Override public int getPlayerVersion(@NonNull Player player) { if (!isPorted(player)) return getExternalVersion(player); return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion(); }
@Override public int getPlayerVersion(@NonNull Player player) { if (!isPorted(player.getUniqueId())) return ProtocolRegistry.SERVER_PROTOCOL; return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion(); }
@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 getPlayerVersion(@NonNull UUID uuid) { if (!isPorted(uuid)) return getExternalVersion(Bukkit.getPlayer(uuid)); return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion(); }
@Override public int getPlayerVersion(@NonNull ProxiedPlayer player) { if (!isPorted(player.getUniqueId())) return player.getPendingConnection().getVersion(); return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion(); }
@Override public int getPlayerVersion(@NonNull UUID uuid) { if (!isPorted(uuid)) { ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); if (player != null) return player.getPendingConnection().getVersion(); return ProtocolRegistry.SERVER_PROTOCOL; } return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion(); }
@Override public int getPlayerVersion(@NonNull Player player) { if (!isPorted(player.getUniqueId())) return player.getProtocolVersion().getProtocol(); return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion(); }
@EventHandler public void onServerConnect(ServerConnectEvent e) { UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); if (user == null) return; if (!user.has(BungeeStorage.class)) { user.put(new BungeeStorage(user, e.getPlayer())); } int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName()); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.get(ProtocolInfo.class).getProtocolVersion(), protocolId); // Check if ViaVersion can support that version try { //Object pendingConnection = getPendingConnection.invoke(e.getPlayer()); Object handshake = getHandshake.invoke(e.getPlayer().getPendingConnection()); setProtocol.invoke(handshake, protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId); } catch (InvocationTargetException | IllegalAccessException e1) { e1.printStackTrace(); } }
@Subscribe public void preServerConnect(ServerPreConnectEvent e) { try { UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); if (user == null) return; if (!user.has(VelocityStorage.class)) { user.put(new VelocityStorage(user, e.getPlayer())); } int protocolId = ProtocolDetectorService.getProtocolId(e.getOriginalServer().getServerInfo().getName()); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.get(ProtocolInfo.class).getProtocolVersion(), protocolId); // Check if ViaVersion can support that version Object connection = getMinecraftConnection.invoke(e.getPlayer()); setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId)); } catch (IllegalAccessException | InvocationTargetException e1) { e1.printStackTrace(); } }
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); user.clearStoredObjects(); if (protocols == null) { protocolId = info.getProtocolVersion(); } else { for (Pair<Integer, Protocol> prot : protocols) {
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); user.clearStoredObjects(); if (protocols == null) { protocolId = info.getProtocolVersion(); } else { for (Pair<Integer, Protocol> prot : protocols) {
int clientProtocol = userConnection.get(ProtocolInfo.class).getProtocolVersion();