Search in sources :

Example 1 with ProtocolPathKey

use of com.viaversion.viaversion.api.protocol.ProtocolPathKey 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)

Aggregations

Protocol (com.viaversion.viaversion.api.protocol.Protocol)1 ProtocolPathEntry (com.viaversion.viaversion.api.protocol.ProtocolPathEntry)1 ProtocolPathKey (com.viaversion.viaversion.api.protocol.ProtocolPathKey)1 BaseProtocol (com.viaversion.viaversion.protocols.base.BaseProtocol)1 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1 ArrayList (java.util.ArrayList)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1