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.
|
@Nullable Protocol |
getBaseProtocol(ProtocolVersion 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 |
getMaxPathDeltaIncrease()
Returns the max delta the path calculation allows the distance to the target protocol version to increase.
|
int |
getMaxProtocolPathSize()
Returns the maximum protocol path size applied to
getProtocolPath(ProtocolVersion, ProtocolVersion) . |
<T extends Protocol> |
getProtocol(java.lang.Class<T> protocolClass)
Returns a protocol instance by its class.
|
@Nullable Protocol |
getProtocol(ProtocolVersion clientVersion,
ProtocolVersion serverVersion)
Returns a protocol transforming packets for server version to the given client version.
|
default @Nullable java.util.List<ProtocolPathEntry> |
getProtocolPath(int clientVersion,
int serverVersion)
Deprecated.
|
@Nullable java.util.List<ProtocolPathEntry> |
getProtocolPath(ProtocolVersion clientVersion,
ProtocolVersion serverVersion)
Calculates and returns the protocol path from a client protocol version to server protocol version.
|
java.util.Collection<Protocol<?,?,?,?>> |
getProtocols()
Returns an immutable collection of registered protocols.
|
ServerProtocolVersion |
getServerProtocolVersion()
Returns the server protocol version.
|
java.util.SortedSet<ProtocolVersion> |
getSupportedVersions()
Returns the protocol versions compatible with the server.
|
boolean |
hasLoadedMappings()
Returns whether the mappings have been loaded and the mapping loader executor shutdown.
|
default boolean |
isBaseProtocol(Protocol protocol)
Deprecated.
use Protocol#isBaseProtocol()
|
boolean |
isWorkingPipe()
Check if this plugin is useful to the server.
|
default boolean |
onlyCheckLoweringPathEntries()
Deprecated.
|
void |
registerBaseProtocol(Protocol baseProtocol,
com.google.common.collect.Range<ProtocolVersion> supportedProtocols)
Registers and initializes a base protocol.
|
void |
registerProtocol(Protocol protocol,
java.util.List<ProtocolVersion> supportedClientVersion,
ProtocolVersion serverVersion)
Register and initializes protocol.
|
void |
registerProtocol(Protocol protocol,
ProtocolVersion clientVersion,
ProtocolVersion serverVersion)
Register and initializes a 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 to
getProtocolPath(ProtocolVersion, ProtocolVersion) . |
default void |
setOnlyCheckLoweringPathEntries(boolean onlyCheckLoweringPathEntries)
Deprecated.
|
ServerProtocolVersion getServerProtocolVersion()
<T extends Protocol> T getProtocol(java.lang.Class<T> protocolClass)
T
- protocolprotocolClass
- class of the protocol@Nullable Protocol getProtocol(ProtocolVersion clientVersion, ProtocolVersion serverVersion)
clientVersion
- client protocol versionserverVersion
- server protocol versionProtocol getBaseProtocol()
@Nullable Protocol getBaseProtocol(ProtocolVersion serverVersion)
serverVersion
- server protocol versionjava.util.Collection<Protocol<?,?,?,?>> getProtocols()
@Deprecated default boolean isBaseProtocol(Protocol protocol)
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<ProtocolVersion> supportedClientVersion, ProtocolVersion 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<ProtocolVersion> 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(ProtocolVersion clientVersion, ProtocolVersion serverVersion)
getMaxProtocolPathSize()
.clientVersion
- input client protocol versionserverVersion
- desired output server protocol versiongetMaxProtocolPathSize()
@Deprecated default @Nullable java.util.List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion)
<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 nullvoid setMaxPathDeltaIncrease(int maxPathDeltaIncrease)
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).
maxPathDeltaIncrease
- the max delta the path calculation allows the distance to the target protocol version to increaseonlyCheckLoweringPathEntries()
int getMaxPathDeltaIncrease()
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:
Negative examples if this returns -1:
@Deprecated default void setOnlyCheckLoweringPathEntries(boolean onlyCheckLoweringPathEntries)
@Deprecated default boolean onlyCheckLoweringPathEntries()
int getMaxProtocolPathSize()
getProtocolPath(ProtocolVersion, ProtocolVersion)
.void setMaxProtocolPathSize(int maxProtocolPathSize)
getProtocolPath(ProtocolVersion, ProtocolVersion)
.
Its default is 50.maxProtocolPathSize
- maximum protocol path sizejava.util.SortedSet<ProtocolVersion> 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 connectionboolean hasLoadedMappings()