use of com.viaversion.viaversion.api.protocol.ProtocolPathEntry in project ViaVersion by ViaVersion.
the class ProtocolManagerImpl method getProtocolPath.
@Override
@Nullable
public List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion) {
// Nothing to do!
if (clientVersion == serverVersion)
return null;
// Check cache
ProtocolPathKey protocolKey = new ProtocolPathKeyImpl(clientVersion, serverVersion);
List<ProtocolPathEntry> protocolList = pathCache.get(protocolKey);
if (protocolList != null) {
return protocolList;
}
// Calculate path
Int2ObjectSortedMap<Protocol> outputPath = getProtocolPath(new Int2ObjectLinkedOpenHashMap<>(), clientVersion, serverVersion);
if (outputPath == null) {
return null;
}
List<ProtocolPathEntry> path = new ArrayList<>(outputPath.size());
for (Int2ObjectMap.Entry<Protocol> entry : outputPath.int2ObjectEntrySet()) {
path.add(new ProtocolPathEntryImpl(entry.getIntKey(), entry.getValue()));
}
pathCache.put(protocolKey, path);
return path;
}
use of com.viaversion.viaversion.api.protocol.ProtocolPathEntry in project ViaVersion by ViaVersion.
the class BungeeServerHandler method onServerConnect.
// Set the handshake version every time someone connects to any server
@EventHandler(priority = 120)
public void onServerConnect(ServerConnectEvent e) {
if (e.isCancelled()) {
return;
}
UserConnection user = Via.getManager().getConnectionManager().getConnectedClient(e.getPlayer().getUniqueId());
if (user == null)
return;
if (!user.has(BungeeStorage.class)) {
user.put(new BungeeStorage(e.getPlayer()));
}
int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName());
List<ProtocolPathEntry> protocols = Via.getManager().getProtocolManager().getProtocolPath(user.getProtocolInfo().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.getProtocolInfo().getProtocolVersion() : protocolId);
} catch (InvocationTargetException | IllegalAccessException e1) {
e1.printStackTrace();
}
}
Aggregations