Search in sources :

Example 6 with ProtocolPathEntry

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;
}
Also used : ProtocolPathEntry(com.viaversion.viaversion.api.protocol.ProtocolPathEntry) ProtocolPathKey(com.viaversion.viaversion.api.protocol.ProtocolPathKey) ArrayList(java.util.ArrayList) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) Protocol(com.viaversion.viaversion.api.protocol.Protocol) BaseProtocol(com.viaversion.viaversion.protocols.base.BaseProtocol) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 7 with ProtocolPathEntry

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();
    }
}
Also used : ProtocolPathEntry(com.viaversion.viaversion.api.protocol.ProtocolPathEntry) BungeeStorage(com.viaversion.viaversion.bungee.storage.BungeeStorage) StorableObject(com.viaversion.viaversion.api.connection.StorableObject) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) InvocationTargetException(java.lang.reflect.InvocationTargetException) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

ProtocolPathEntry (com.viaversion.viaversion.api.protocol.ProtocolPathEntry)7 Protocol (com.viaversion.viaversion.api.protocol.Protocol)3 ProtocolVersion (com.viaversion.viaversion.api.protocol.version.ProtocolVersion)3 ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)2 StorableObject (com.viaversion.viaversion.api.connection.StorableObject)2 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)2 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)2 BungeeStorage (com.viaversion.viaversion.bungee.storage.BungeeStorage)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 MappingData (com.viaversion.viaversion.api.data.MappingData)1 ProtocolPathKey (com.viaversion.viaversion.api.protocol.ProtocolPathKey)1 ProtocolPipeline (com.viaversion.viaversion.api.protocol.ProtocolPipeline)1 ClientboundPacketType (com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType)1 PacketType (com.viaversion.viaversion.api.protocol.packet.PacketType)1 ServerboundPacketType (com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType)1 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)1 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)1 ServerProtocolVersion (com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion)1