public interface ProtocolManager
Modifier and Type | Method and Description |
---|---|
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. |
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. |
boolean |
checkForMappingCompletion()
Shuts down the executor and uncaches mappings if all futures have been completed.
|
void |
completeMappingDataLoading(java.lang.Class<? extends Protocol> protocolClass)
Ensure that mapping data for that protocol has already been loaded, completes it otherwise.
|
<C extends ClientboundPacketType,S extends ServerboundPacketType> |
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.
|
PacketWrapper |
createPacketWrapper(int packetId,
@Nullable io.netty.buffer.ByteBuf buf,
UserConnection connection)
Deprecated.
magic id; prefer using
createPacketWrapper(PacketType, ByteBuf, UserConnection) |
PacketWrapper |
createPacketWrapper(@Nullable PacketType packetType,
@Nullable io.netty.buffer.ByteBuf buf,
UserConnection connection)
Creates a new packet wrapper instance.
|
Protocol |
getBaseProtocol()
Returns the base protocol handling serverbound handshake packets.
|
Protocol |
getBaseProtocol(int serverVersion)
Returns the base protocol for a specific server protocol version.
|
@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.
|
int |
getMaxProtocolPathSize()
Returns the maximum protocol path size applied to
getProtocolPath(int, int) . |
<T extends Protocol> |
getProtocol(java.lang.Class<T> protocolClass)
Returns a protocol instance by its class.
|
@Nullable Protocol |
getProtocol(int clientVersion,
int serverVersion)
Returns a protocol transforming packets for server version to the given client version.
|
default @Nullable Protocol |
getProtocol(ProtocolVersion clientVersion,
ProtocolVersion serverVersion)
Returns a protocol transforming packets for server version to the given client version.
|
@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.
|
ServerProtocolVersion |
getServerProtocolVersion()
Returns the server protocol version.
|
java.util.SortedSet<java.lang.Integer> |
getSupportedVersions()
Returns the protocol versions compatible with the server.
|
default boolean |
isBaseProtocol(Protocol protocol)
Returns whether the given protocol is a base protocol.
|
boolean |
isWorkingPipe()
Check if this plugin is useful to the server.
|
boolean |
onlyCheckLoweringPathEntries()
Returns whether protocol path calculation expects the path to come closer to the expected version with each entry, true by default.
|
void |
registerBaseProtocol(Protocol baseProtocol,
com.google.common.collect.Range<java.lang.Integer> supportedProtocols)
Registers and initializes a base protocol.
|
void |
registerProtocol(Protocol protocol,
java.util.List<java.lang.Integer> supportedClientVersion,
int serverVersion)
Register and initializes protocol.
|
void |
registerProtocol(Protocol protocol,
ProtocolVersion clientVersion,
ProtocolVersion serverVersion)
Register and initializes a protocol.
|
void |
setMaxProtocolPathSize(int maxProtocolPathSize)
Sets the maximum protocol path size applied to
getProtocolPath(int, int) . |
void |
setOnlyCheckLoweringPathEntries(boolean onlyCheckLoweringPathEntries)
Sets whether protocol path calculation expects the path to come closer to the expected version with each entry.
|
ServerProtocolVersion getServerProtocolVersion()
<T extends Protocol> T getProtocol(java.lang.Class<T> protocolClass)
T
- protocolprotocolClass
- class of the protocoldefault @Nullable Protocol getProtocol(ProtocolVersion clientVersion, ProtocolVersion serverVersion)
clientVersion
- client protocol versionserverVersion
- server protocol versionto get a full path of Protocols between a larger gap of versions
@Nullable Protocol getProtocol(int clientVersion, int serverVersion)
clientVersion
- client protocol versionserverVersion
- server protocol versionto get a full path of Protocols between a larger gap of versions
Protocol getBaseProtocol()
Protocol getBaseProtocol(int serverVersion)
serverVersion
- server protocol versionjava.lang.IllegalStateException
- if no base protocol could be founddefault boolean isBaseProtocol(Protocol protocol)
protocol
- protocolProtocol.isBaseProtocol()
void registerProtocol(Protocol protocol, ProtocolVersion clientVersion, ProtocolVersion serverVersion)
protocol
- protocol to registerclientVersion
- supported client protocol versionsserverVersion
- output server protocol version the protocol converts tojava.lang.IllegalArgumentException
- if the client protocol version is equal to the server protocol versionvoid registerProtocol(Protocol protocol, java.util.List<java.lang.Integer> supportedClientVersion, int serverVersion)
protocol
- protocol to registersupportedClientVersion
- supported client protocol versionsserverVersion
- output server protocol version the protocol converts tojava.lang.IllegalArgumentException
- if a supported client protocol version is equal to the server protocol versionvoid registerBaseProtocol(Protocol baseProtocol, com.google.common.collect.Range<java.lang.Integer> supportedProtocols)
baseProtocol
- base protocol to registersupportedProtocols
- protocol versions supported by the base protocoljava.lang.IllegalArgumentException
- if the protocol is not a base protocol as given by Protocol.isBaseProtocol()
@Nullable java.util.List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion)
getMaxProtocolPathSize()
.clientVersion
- input client protocol versionserverVersion
- desired output server protocol versiongetMaxProtocolPathSize()
<C extends ClientboundPacketType,S extends ServerboundPacketType> VersionedPacketTransformer<C,S> createPacketTransformer(ProtocolVersion inputVersion, @Nullable java.lang.Class<C> clientboundPacketsClass, @Nullable java.lang.Class<S> serverboundPacketsClass)
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);
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 thisjava.lang.IllegalArgumentException
- if either of the packet classes are the base ClientboundPacketType
or ServerboundPacketType
interfacesjava.lang.IllegalArgumentException
- if both packet classes are nullboolean onlyCheckLoweringPathEntries()
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:
Negative examples if this returns false:
void setOnlyCheckLoweringPathEntries(boolean onlyCheckLoweringPathEntries)
onlyCheckLoweringPathEntries
- whether protocol path calculation expects the path to come closer to the expected version with each entryonlyCheckLoweringPathEntries()
int getMaxProtocolPathSize()
getProtocolPath(int, int)
.void setMaxProtocolPathSize(int maxProtocolPathSize)
getProtocolPath(int, int)
.
Its default is 50.maxProtocolPathSize
- maximum protocol path sizejava.util.SortedSet<java.lang.Integer> getSupportedVersions()
boolean isWorkingPipe()
void completeMappingDataLoading(java.lang.Class<? extends Protocol> protocolClass) throws java.lang.Exception
protocolClass
- protocol classjava.lang.Exception
boolean checkForMappingCompletion()
void addMappingLoaderFuture(java.lang.Class<? extends Protocol> protocolClass, java.lang.Runnable runnable)
CompletableFuture
to the list of data to load bound to their protocols.protocolClass
- protocol classrunnable
- runnable to be executed asynchronouslyvoid addMappingLoaderFuture(java.lang.Class<? extends Protocol> protocolClass, java.lang.Class<? extends Protocol> dependsOn, java.lang.Runnable runnable)
CompletableFuture
to the list of data to load bound to their protocols.protocolClass
- protocol classdependsOn
- class of the protocol that the data loading depends onrunnable
- runnable to be executed asynchronously@Nullable java.util.concurrent.CompletableFuture<java.lang.Void> getMappingLoaderFuture(java.lang.Class<? extends Protocol> protocolClass)
protocolClass
- protocol classPacketWrapper createPacketWrapper(@Nullable PacketType packetType, @Nullable io.netty.buffer.ByteBuf buf, UserConnection connection)
packetType
- packet type, or null if none should be written to the packet (raw id = -1)buf
- input bufferconnection
- user connectionPacketWrapper.create(PacketType, ByteBuf, UserConnection)
@Deprecated PacketWrapper createPacketWrapper(int packetId, @Nullable io.netty.buffer.ByteBuf buf, UserConnection connection)
createPacketWrapper(PacketType, ByteBuf, UserConnection)
packetId
- packet idbuf
- input bufferconnection
- user connection