Interface ProtocolManager


  • public interface ProtocolManager
    • Method Detail

      • 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​(java.lang.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​(int clientVersion,
                                       int 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
        See Also:
        to get a full path of Protocols between a larger gap of versions
      • getBaseProtocol

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

        Protocol getBaseProtocol​(int 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
        Throws:
        java.lang.IllegalStateException - if no base protocol could be found
      • isBaseProtocol

        default boolean isBaseProtocol​(Protocol protocol)
        Returns whether the given protocol is a base protocol.
        Parameters:
        protocol - protocol
        Returns:
        whether the protocol is a base protocol
        See Also:
        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:
        java.lang.IllegalArgumentException - if the client protocol version is equal to the server protocol version
      • registerProtocol

        void registerProtocol​(Protocol protocol,
                              java.util.List<java.lang.Integer> supportedClientVersion,
                              int 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:
        java.lang.IllegalArgumentException - if a supported client protocol version is equal to the server protocol version
      • registerBaseProtocol

        void registerBaseProtocol​(Protocol baseProtocol,
                                  com.google.common.collect.Range<java.lang.Integer> 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:
        java.lang.IllegalArgumentException - if the protocol is not a base protocol as given by Protocol.isBaseProtocol()
      • getProtocolPath

        @Nullable java.util.List<ProtocolPathEntry> getProtocolPath​(int clientVersion,
                                                                    int 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()
      • createPacketTransformer

        <C extends ClientboundPacketType,​S extends ServerboundPacketTypeVersionedPacketTransformer<C,​S> createPacketTransformer​(ProtocolVersion inputVersion,
                                                                                                                                              @Nullable java.lang.Class<C> clientboundPacketsClass,
                                                                                                                                              @Nullable java.lang.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:
        java.lang.IllegalArgumentException - if either of the packet classes are the base ClientboundPacketType or ServerboundPacketType interfaces
        java.lang.IllegalArgumentException - if both packet classes are null
      • onlyCheckLoweringPathEntries

        boolean onlyCheckLoweringPathEntries()
        Returns whether protocol path calculation expects the path to come closer to the expected version with each entry, true by default.

        In practice, this 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 false, *all* possible paths will be checked until a fitting one is found.

        Negative examples if this returns true:

          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 false:

          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:
        whether protocol path calculation expects the path to come closer to the expected version with each entry
      • setOnlyCheckLoweringPathEntries

        void setOnlyCheckLoweringPathEntries​(boolean onlyCheckLoweringPathEntries)
        Sets whether protocol path calculation expects the path to come closer to the expected version with each entry.
        Parameters:
        onlyCheckLoweringPathEntries - whether protocol path calculation expects the path to come closer to the expected version with each entry
        See Also:
        onlyCheckLoweringPathEntries()
      • getMaxProtocolPathSize

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

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

        java.util.SortedSet<java.lang.Integer> 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​(java.lang.Class<? extends Protocol> protocolClass)
                                 throws java.lang.Exception
        Ensure that mapping data for that protocol has already been loaded, completes it otherwise.
        Parameters:
        protocolClass - protocol class
        Throws:
        java.lang.Exception
      • 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​(java.lang.Class<? extends Protocol> protocolClass,
                                    java.lang.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​(java.lang.Class<? extends Protocol> protocolClass,
                                    java.lang.Class<? extends Protocol> dependsOn,
                                    java.lang.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 java.util.concurrent.CompletableFuture<java.lang.Void> getMappingLoaderFuture​(java.lang.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