Interface ProtocolTranslation
public interface ProtocolTranslation
Protocol translator.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.viaversion.viaversion.api.protocol.version.ProtocolVersionThe protocol version used when version auto-detection is enabled. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChangeProtocolVersionListener(BiConsumer<com.viaversion.viaversion.api.protocol.version.ProtocolVersion, com.viaversion.viaversion.api.protocol.version.ProtocolVersion> listener) Adds a listener for when the protocol version changes.@Nullable com.viaversion.viaversion.api.protocol.version.ProtocolVersionserverVersion(net.minecraft.client.multiplayer.ServerData serverData) The pre-server version of the server.voidsetServerVersion(net.minecraft.client.multiplayer.ServerData serverData, com.viaversion.viaversion.api.protocol.version.ProtocolVersion version) Sets the pre-server version of the server.default voidsetTargetVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion targetVersion) Sets the global target version permanently.voidsetTargetVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion targetVersion, boolean revertOnDisconnect) Sets the global target version.com.viaversion.viaversion.api.protocol.version.ProtocolVersionThe target version either selected by the user in the global menu or set per server.com.viaversion.viaversion.api.protocol.version.ProtocolVersiontargetVersion(io.netty.channel.Channel channel) Same astargetVersion(Connection)but for the given channel.com.viaversion.viaversion.api.protocol.version.ProtocolVersiontargetVersion(net.minecraft.network.Connection connection) The target version for the given connection.@Nullable com.viaversion.viaversion.api.connection.UserConnectionViaVersion's user connection object.@Nullable com.viaversion.viaversion.api.connection.UserConnectionuserConnection(net.minecraft.network.Connection connection) Similar touserConnection(), but for the given connection.
-
Field Details
-
AUTO_DETECT_VERSION
static final com.viaversion.viaversion.api.protocol.version.ProtocolVersion AUTO_DETECT_VERSIONThe protocol version used when version auto-detection is enabled. Note that this won't be returned on any version getters after the initial connection has been established (e.g.,targetVersion()).
-
-
Method Details
-
targetVersion
com.viaversion.viaversion.api.protocol.version.ProtocolVersion targetVersion()The target version either selected by the user in the global menu or set per server. Note that this method only works after the initial connection has been established.- Returns:
- the target version
-
targetVersion
com.viaversion.viaversion.api.protocol.version.ProtocolVersion targetVersion(net.minecraft.network.Connection connection) The target version for the given connection. This method is useful for retrieving the version before the global version has been set (targetVersion()) and might work in earlier stages of the connection. Note that there is no guarantee for the value returned here.- Parameters:
connection- the connection- Returns:
- the target version
-
targetVersion
com.viaversion.viaversion.api.protocol.version.ProtocolVersion targetVersion(io.netty.channel.Channel channel) Same astargetVersion(Connection)but for the given channel.- Parameters:
channel- the channel- Returns:
- the target version
-
setTargetVersion
default void setTargetVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion targetVersion) Sets the global target version permanently.- Parameters:
targetVersion- the target version
-
setTargetVersion
void setTargetVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion targetVersion, boolean revertOnDisconnect) Sets the global target version. If the client disconnects, the version will be reverted to the previous version.- Parameters:
targetVersion- the target versionrevertOnDisconnect- whether to revert the version on disconnect
-
addChangeProtocolVersionListener
void addChangeProtocolVersionListener(BiConsumer<com.viaversion.viaversion.api.protocol.version.ProtocolVersion, com.viaversion.viaversion.api.protocol.version.ProtocolVersion> listener) Adds a listener for when the protocol version changes.- Parameters:
listener- The listener to add, which will be called when the protocol version changes.
-
userConnection
@Nullable @Nullable com.viaversion.viaversion.api.connection.UserConnection userConnection()ViaVersion's user connection object. This is set after the initial connection has been established. Useful for when sending raw packets or modifying the client's state. Only valid as soon as the client switched its network state to PLAY (!)- Returns:
- the user connection
-
userConnection
@Nullable @Nullable com.viaversion.viaversion.api.connection.UserConnection userConnection(net.minecraft.network.Connection connection) Similar touserConnection(), but for the given connection. This method also works in earlier stages than PLAY (e.g., LOGIN; CONFIGURATION).- Parameters:
connection- the connection- Returns:
- the user connection
-
serverVersion
@Nullable @Nullable com.viaversion.viaversion.api.protocol.version.ProtocolVersion serverVersion(net.minecraft.client.multiplayer.ServerData serverData) The pre-server version of the server. This is only valid if the user has set a specific version for the given server.- Parameters:
serverData- the server data- Returns:
- the pre-server version of the server
-
setServerVersion
void setServerVersion(net.minecraft.client.multiplayer.ServerData serverData, com.viaversion.viaversion.api.protocol.version.ProtocolVersion version) Sets the pre-server version of the server.- Parameters:
serverData- the server dataversion- the version
-