Interface ProtocolManager
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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 aCompletableFuture
to the list of data to load bound to their protocols.void
addMappingLoaderFuture
(Class<? extends Protocol> protocolClass, Runnable runnable) Executes the given runnable asynchronously, adding aCompletableFuture
to the list of data to load bound to their protocols.boolean
Shuts down the executor and uncaches mappings if all futures have been completed.void
completeMappingDataLoading
(Class<? extends Protocol> protocolClass) Ensure that mapping data for that protocol has already been loaded, completes it otherwise.<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.createPacketWrapper
(int packetId, @Nullable io.netty.buffer.ByteBuf buf, UserConnection connection) Deprecated.createPacketWrapper
(@Nullable PacketType packetType, @Nullable io.netty.buffer.ByteBuf buf, UserConnection connection) Creates a new packet wrapper instance.Returns the base protocol handling serverbound handshake packets.getBaseProtocols
(@Nullable ProtocolVersion clientVersion, @Nullable ProtocolVersion serverVersion) Returns the base protocols for a specific server and client protocol version.@Nullable CompletableFuture<Void>
getMappingLoaderFuture
(Class<? extends Protocol> protocolClass) Returns the data loading future bound to the protocol, or null if all loading is complete.int
Returns the max delta the path calculation allows the distance to the target protocol version to increase.int
Returns the maximum protocol path size applied togetProtocolPath(ProtocolVersion, ProtocolVersion)
.@Nullable Protocol
getProtocol
(ProtocolVersion clientVersion, ProtocolVersion serverVersion) Returns a protocol transforming packets for server version to the given client version.<T extends Protocol>
@Nullable TgetProtocol
(Class<T> protocolClass) Returns a protocol instance by its class.default @Nullable List<ProtocolPathEntry>
getProtocolPath
(int clientVersion, int serverVersion) Deprecated.@Nullable List<ProtocolPathEntry>
getProtocolPath
(ProtocolVersion clientVersion, ProtocolVersion serverVersion) Calculates and returns the protocol path from a client protocol version to server protocol version.Collection<Protocol<?,
?, ?, ?>> Returns an immutable collection of registered protocols.Returns the server protocol version.Returns the protocol versions compatible with the server.boolean
Returns whether the mappings have been loaded and the mapping loader executor shutdown.default boolean
isBaseProtocol
(Protocol protocol) Deprecated, for removal: This API element is subject to removal in a future version.use Protocol#isBaseProtocol()boolean
Check if this plugin is useful to the server.void
registerBaseProtocol
(Direction direction, Protocol baseProtocol, com.google.common.collect.Range<ProtocolVersion> supportedProtocols) Registers and initializes a base protocol.void
registerProtocol
(Protocol protocol, ProtocolVersion clientVersion, ProtocolVersion serverVersion) Register and initializes a protocol.void
registerProtocol
(Protocol protocol, List<ProtocolVersion> supportedClientVersion, ProtocolVersion serverVersion) Register and initializes protocol.void
setMaxPathDeltaIncrease
(int maxPathDeltaIncrease) Sets the max delta the path calculation allows the distance to the target protocol version to increase.void
setMaxProtocolPathSize
(int maxProtocolPathSize) Sets the maximum protocol path size applied togetProtocolPath(ProtocolVersion, ProtocolVersion)
.
-
Method Details
-
getServerProtocolVersion
ServerProtocolVersion getServerProtocolVersion()Returns the server protocol version. Its methods will return -1 if not set yet.- Returns:
- server protocol version
-
getProtocol
Returns a protocol instance by its class.- Type Parameters:
T
- protocol- Parameters:
protocolClass
- class of the protocol- Returns:
- protocol if present
-
getProtocol
Returns a protocol transforming packets for server version to the given client version.- Parameters:
clientVersion
- client protocol versionserverVersion
- server protocol version- Returns:
- protocol if present, else null
-
getBaseProtocol
Protocol getBaseProtocol()Returns the base protocol handling serverbound handshake packets.- Returns:
- base protocol
-
getBaseProtocols
List<Protocol> getBaseProtocols(@Nullable ProtocolVersion clientVersion, @Nullable ProtocolVersion serverVersion) Returns the base protocols for a specific server and client protocol version. The standard base protocols deal with status and login packets for userconnection initialization.- Parameters:
clientVersion
- client protocol versionserverVersion
- server protocol version- Returns:
- base protocols for the given server and client protocol version
-
getProtocols
Collection<Protocol<?,?, getProtocols()?, ?>> Returns an immutable collection of registered protocols.- Returns:
- immutable collection of registered protocols
-
isBaseProtocol
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 registerclientVersion
- supported client protocol versionsserverVersion
- 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 registersupportedClientVersion
- supported client protocol versionsserverVersion
- 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(Direction direction, 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:
direction
- direction of the base protocolbaseProtocol
- base protocol to registersupportedProtocols
- protocol versions supported by the base protocol- Throws:
IllegalArgumentException
- if the protocol is not a base protocol as given byProtocol.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 bygetMaxProtocolPathSize()
.- Parameters:
clientVersion
- input client protocol versionserverVersion
- 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 versionclientboundPacketsClass
- clientbound packets class, or null if no clientbound packets will be sent or transformed with thisserverboundPacketsClass
- 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 baseClientboundPacketType
orServerboundPacketType
interfacesIllegalArgumentException
- 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 togetProtocolPath(ProtocolVersion, ProtocolVersion)
.- Returns:
- maximum protocol path size
-
setMaxProtocolPathSize
void setMaxProtocolPathSize(int maxProtocolPathSize) Sets the maximum protocol path size applied togetProtocolPath(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
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
Executes the given runnable asynchronously, adding aCompletableFuture
to the list of data to load bound to their protocols.- Parameters:
protocolClass
- protocol classrunnable
- 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 aCompletableFuture
to the list of data to load bound to their protocols.- Parameters:
protocolClass
- protocol classdependsOn
- class of the protocol that the data loading depends onrunnable
- runnable to be executed asynchronously
-
getMappingLoaderFuture
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 bufferconnection
- user connection- Returns:
- new packet wrapper instance
- See Also:
-
createPacketWrapper
@Deprecated PacketWrapper createPacketWrapper(int packetId, @Nullable io.netty.buffer.ByteBuf buf, UserConnection connection) Deprecated.magic id; prefer usingcreatePacketWrapper(PacketType, ByteBuf, UserConnection)
Creates a new packet wrapper instance.- Parameters:
packetId
- packet idbuf
- input bufferconnection
- 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
-
createPacketWrapper(PacketType, ByteBuf, UserConnection)