Interface ProtocolManager


public interface ProtocolManager
  • Method Details

    • getServerProtocolVersion

      ServerProtocolVersion getServerProtocolVersion()
      Returns the server protocol version. Its methods will return -1 if not set yet.
      Returns:
      server protocol version
    • getProtocol

      <T extends Protocol> @Nullable T getProtocol(Class<T> protocolClass)
      Returns a protocol instance by its class.
      Type Parameters:
      T - protocol
      Parameters:
      protocolClass - class of the protocol
      Returns:
      protocol if present
    • getProtocol

      @Nullable Protocol getProtocol(ProtocolVersion clientVersion, ProtocolVersion serverVersion)
      Returns a protocol transforming packets for server version to the given client version.
      Parameters:
      clientVersion - client protocol version
      serverVersion - server protocol version
      Returns:
      protocol if present, else null
    • getBaseProtocol

      Protocol getBaseProtocol()
      Returns the base protocol handling serverbound handshake packets.
      Returns:
      base protocol
    • getBaseProtocol

      @Nullable Protocol getBaseProtocol(ProtocolVersion serverVersion)
      Returns the base protocol for a specific server protocol version. The standard base protocols deal with status and login packets for userconnection initialization.
      Parameters:
      serverVersion - server protocol version
      Returns:
      base protocol for the given server protocol version if present, else null
    • getProtocols

      Collection<Protocol<?,?,?,?>> getProtocols()
      Returns an immutable collection of registered protocols.
      Returns:
      immutable collection of registered protocols
    • isBaseProtocol

      @Deprecated(forRemoval=true) default boolean isBaseProtocol(Protocol protocol)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use Protocol#isBaseProtocol()
    • registerProtocol

      void registerProtocol(Protocol protocol, ProtocolVersion clientVersion, ProtocolVersion serverVersion)
      Register and initializes a protocol.
      Parameters:
      protocol - protocol to register
      clientVersion - supported client protocol versions
      serverVersion - output server protocol version the protocol converts to
      Throws:
      IllegalArgumentException - if the client protocol version is equal to the server protocol version
    • registerProtocol

      void registerProtocol(Protocol protocol, List<ProtocolVersion> supportedClientVersion, ProtocolVersion serverVersion)
      Register and initializes protocol.
      Parameters:
      protocol - protocol to register
      supportedClientVersion - supported client protocol versions
      serverVersion - output server protocol version the protocol converts to
      Throws:
      IllegalArgumentException - if a supported client protocol version is equal to the server protocol version
    • registerBaseProtocol

      void registerBaseProtocol(Protocol baseProtocol, com.google.common.collect.Range<ProtocolVersion> supportedProtocols)
      Registers and initializes a base protocol. Base Protocols registered later have higher priority. Only base protocol will always be added to pipeline.
      Parameters:
      baseProtocol - base protocol to register
      supportedProtocols - protocol versions supported by the base protocol
      Throws:
      IllegalArgumentException - if the protocol is not a base protocol as given by Protocol.isBaseProtocol()
    • getProtocolPath

      @Nullable List<ProtocolPathEntry> getProtocolPath(ProtocolVersion clientVersion, ProtocolVersion serverVersion)
      Calculates and returns the protocol path from a client protocol version to server protocol version. Returns null if no path could be found or the path length exceeds the value given by getMaxProtocolPathSize().
      Parameters:
      clientVersion - input client protocol version
      serverVersion - desired output server protocol version
      Returns:
      path generated, or null if not supported or the length exceeds getMaxProtocolPathSize()
    • getProtocolPath

      @Deprecated default @Nullable List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion)
      Deprecated.
    • createPacketTransformer

      <C extends ClientboundPacketType, S extends ServerboundPacketType> VersionedPacketTransformer<C,S> createPacketTransformer(ProtocolVersion inputVersion, @Nullable Class<C> clientboundPacketsClass, @Nullable Class<S> serverboundPacketsClass)
      Returns a versioned packet transformer to transform and send packets from a given base version to any client version supported by Via. The used packet types have to match the given protocol version.

      It is important the correct packet type classes are passed. The ViaVersion given packet type enums are found in the common module. Examples for correct invocations are:

       createPacketTransformer(ProtocolVersion.v1_17_1, ClientboundPackets1_17_1.class, ServerboundPackets1_17.class);
       createPacketTransformer(ProtocolVersion.v1_12_2, ClientboundPackets1_12_1.class, ServerboundPackets1_12_1.class);
       createPacketTransformer(ProtocolVersion.v1_8, ClientboundPackets1_8.class, ServerboundPackets1_8.class);
       
      If only clientbound or serverbound packets are used, the other class can be passed as null, see:
       VersionedPacketTransformer<?, ServerboundHandshakePackets> creator
           = createPacketTransformer(ProtocolVersion.v1_17_1, null, ServerboundHandshakePackets.class);
       
      Parameters:
      inputVersion - input protocol version
      clientboundPacketsClass - clientbound packets class, or null if no clientbound packets will be sent or transformed with this
      serverboundPacketsClass - serverbound packets class, or null if no serverbound packets will be sent or transformed with this
      Returns:
      versioned packet transformer to transform and send packets from a given protocol version
      Throws:
      IllegalArgumentException - if either of the packet classes are the base ClientboundPacketType or ServerboundPacketType interfaces
      IllegalArgumentException - if both packet classes are null
    • setMaxPathDeltaIncrease

      void setMaxPathDeltaIncrease(int maxPathDeltaIncrease)
      Sets the max delta the path calculation allows the distance to the target protocol version to increase.

      If set to 0, protocol paths will have to come closer to the target protocol version with every entry, never going farther away from it (1→5→10 and 1→11→10 are ok, 1→20→10 is not ok). If set to -1, no distance checks will be applied (1→20→10 is ok).

      Parameters:
      maxPathDeltaIncrease - the max delta the path calculation allows the distance to the target protocol version to increase
    • getMaxPathDeltaIncrease

      int getMaxPathDeltaIncrease()
      Returns the max delta the path calculation allows the distance to the target protocol version to increase. 0 by default.

      In practice, a value of 0 means a path will never go to a protocol version that puts it farther from the desired server protocol version, even if a path existed. If this is set to -1, *all* possible paths will be checked until a fitting one is found.

      Negative examples if this returns 0:

        A possible path from 3 to 5 in order of 3→10→5 will be dismissed. A possible path from 5 to 3 in order of 5→0→3 will be dismissed.

      Negative examples if this returns -1:

        While searching for a path from 3 to 5, 3→2→1 could be checked first before 3→4→5 is found. While searching for a path from 5 to 3, 5→6→7 could be checked first before 5→4→3 is found.
      Returns:
      max delta the path calculation allows the distance to the target protocol version to increase
    • getMaxProtocolPathSize

      int getMaxProtocolPathSize()
      Returns the maximum protocol path size applied to getProtocolPath(ProtocolVersion, ProtocolVersion).
      Returns:
      maximum protocol path size
    • setMaxProtocolPathSize

      void setMaxProtocolPathSize(int maxProtocolPathSize)
      Sets the maximum protocol path size applied to getProtocolPath(ProtocolVersion, ProtocolVersion). Its default is 50.
      Parameters:
      maxProtocolPathSize - maximum protocol path size
    • getSupportedVersions

      SortedSet<ProtocolVersion> getSupportedVersions()
      Returns the protocol versions compatible with the server.
      Returns:
      sorted, immutable set of supported protocol versions
    • isWorkingPipe

      boolean isWorkingPipe()
      Check if this plugin is useful to the server.
      Returns:
      true if there is a useful pipe
    • completeMappingDataLoading

      void completeMappingDataLoading(Class<? extends Protocol> protocolClass)
      Ensure that mapping data for that protocol has already been loaded, completes it otherwise.
      Parameters:
      protocolClass - protocol class
    • checkForMappingCompletion

      boolean checkForMappingCompletion()
      Shuts down the executor and uncaches mappings if all futures have been completed.
      Returns:
      true if the executor has now been shut down
    • addMappingLoaderFuture

      void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Runnable runnable)
      Executes the given runnable asynchronously, adding a CompletableFuture to the list of data to load bound to their protocols.
      Parameters:
      protocolClass - protocol class
      runnable - runnable to be executed asynchronously
    • addMappingLoaderFuture

      void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Class<? extends Protocol> dependsOn, Runnable runnable)
      Executes the given runnable asynchronously after the other protocol has finished its data loading, adding a CompletableFuture to the list of data to load bound to their protocols.
      Parameters:
      protocolClass - protocol class
      dependsOn - class of the protocol that the data loading depends on
      runnable - runnable to be executed asynchronously
    • getMappingLoaderFuture

      @Nullable CompletableFuture<Void> getMappingLoaderFuture(Class<? extends Protocol> protocolClass)
      Returns the data loading future bound to the protocol, or null if all loading is complete. The future may or may not have already been completed.
      Parameters:
      protocolClass - protocol class
      Returns:
      data loading future bound to the protocol, or null if all loading is complete
    • createPacketWrapper

      PacketWrapper createPacketWrapper(@Nullable PacketType packetType, @Nullable io.netty.buffer.ByteBuf buf, UserConnection connection)
      Creates a new packet wrapper instance.
      Parameters:
      packetType - packet type, or null if none should be written to the packet (raw id = -1)
      buf - input buffer
      connection - user connection
      Returns:
      new packet wrapper instance
      See Also:
    • createPacketWrapper

      @Deprecated PacketWrapper createPacketWrapper(int packetId, @Nullable io.netty.buffer.ByteBuf buf, UserConnection connection)
      Creates a new packet wrapper instance.
      Parameters:
      packetId - packet id
      buf - input buffer
      connection - user connection
      Returns:
      new packet wrapper instance
    • hasLoadedMappings

      boolean hasLoadedMappings()
      Returns whether the mappings have been loaded and the mapping loader executor shutdown.
      Returns:
      whether the mappings have been loaded