Interface ProtocolTranslation


public interface ProtocolTranslation
Protocol translator.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.viaversion.viaversion.api.protocol.version.ProtocolVersion
    The protocol version used when version auto-detection is enabled.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    @Nullable com.viaversion.viaversion.api.protocol.version.ProtocolVersion
    serverVersion(net.minecraft.client.multiplayer.ServerData serverData)
    The pre-server version of the server.
    void
    setServerVersion(net.minecraft.client.multiplayer.ServerData serverData, com.viaversion.viaversion.api.protocol.version.ProtocolVersion version)
    Sets the pre-server version of the server.
    default void
    setTargetVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion targetVersion)
    Sets the global target version permanently.
    void
    setTargetVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion targetVersion, boolean revertOnDisconnect)
    Sets the global target version.
    com.viaversion.viaversion.api.protocol.version.ProtocolVersion
    The target version either selected by the user in the global menu or set per server.
    com.viaversion.viaversion.api.protocol.version.ProtocolVersion
    targetVersion(io.netty.channel.Channel channel)
    Same as targetVersion(Connection) but for the given channel.
    com.viaversion.viaversion.api.protocol.version.ProtocolVersion
    targetVersion(net.minecraft.network.Connection connection)
    The target version for the given connection.
    @Nullable com.viaversion.viaversion.api.connection.UserConnection
    ViaVersion's user connection object.
    @Nullable com.viaversion.viaversion.api.connection.UserConnection
    userConnection(net.minecraft.network.Connection connection)
    Similar to userConnection(), but for the given connection.
  • Field Details

    • AUTO_DETECT_VERSION

      static final com.viaversion.viaversion.api.protocol.version.ProtocolVersion AUTO_DETECT_VERSION
      The 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 as targetVersion(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 version
      revertOnDisconnect - 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 to userConnection(), 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 data
      version - the version