Class MinecraftProtocol

java.lang.Object
org.geysermc.mcprotocollib.network.packet.PacketProtocol
org.geysermc.mcprotocollib.protocol.MinecraftProtocol

public class MinecraftProtocol extends PacketProtocol
Implements the Minecraft protocol.
  • Constructor Details

    • MinecraftProtocol

      public MinecraftProtocol()
      Constructs a new MinecraftProtocol instance for making status queries.
    • MinecraftProtocol

      public MinecraftProtocol(PacketCodec codec)
      Constructs a new MinecraftProtocol instance for making status queries.
      Parameters:
      codec - The packet codec to use.
    • MinecraftProtocol

      public MinecraftProtocol(@NonNull @NonNull String username)
      Constructs a new MinecraftProtocol instance for logging in using offline mode.
      Parameters:
      username - Username to use.
    • MinecraftProtocol

      public MinecraftProtocol(@NonNull @NonNull PacketCodec codec, @NonNull @NonNull String username)
      Constructs a new MinecraftProtocol instance for logging in using offline mode.
      Parameters:
      codec - The packet codec to use.
      username - Username to use.
    • MinecraftProtocol

      public MinecraftProtocol(@NonNull @NonNull GameProfile profile, String accessToken)
      Constructs a new MinecraftProtocol instance for logging in.
      Parameters:
      profile - GameProfile to use.
      accessToken - Access token to use, or null if using offline mode.
    • MinecraftProtocol

      public MinecraftProtocol(@NonNull @NonNull PacketCodec codec, @NonNull @NonNull GameProfile profile, String accessToken)
      Constructs a new MinecraftProtocol instance for logging in.
      Parameters:
      codec - The packet codec to use.
      profile - GameProfile to use.
      accessToken - Access token to use, or null if using offline mode.
  • Method Details

    • getSRVRecordPrefix

      public String getSRVRecordPrefix()
      Description copied from class: PacketProtocol
      Gets the prefix used when locating SRV records for this protocol.
      Specified by:
      getSRVRecordPrefix in class PacketProtocol
      Returns:
      The protocol's SRV record prefix.
    • getPacketHeader

      public PacketHeader getPacketHeader()
      Description copied from class: PacketProtocol
      Gets the packet header of this protocol.
      Specified by:
      getPacketHeader in class PacketProtocol
      Returns:
      The protocol's packet header.
    • createHelper

      public MinecraftCodecHelper createHelper()
      Description copied from class: PacketProtocol
      Creates a new PacketCodecHelper that can be used for each session.
      Specified by:
      createHelper in class PacketProtocol
      Returns:
      A new PacketCodecHelper.
    • newClientSession

      public void newClientSession(Session session, boolean transferring)
      Description copied from class: PacketProtocol
      Called when a client session is created with this protocol.
      Specified by:
      newClientSession in class PacketProtocol
      Parameters:
      session - The created session.
      transferring - If the client is being transferred between servers.
    • newServerSession

      public void newServerSession(Server server, Session session)
      Description copied from class: PacketProtocol
      Called when a server session is created with this protocol.
      Specified by:
      newServerSession in class PacketProtocol
      Parameters:
      server - The server that the session belongs to.
      session - The created session.
    • getPacketRegistry

      public PacketRegistry getPacketRegistry()
      Description copied from class: PacketProtocol
      Gets the packet registry for this protocol.
      Specified by:
      getPacketRegistry in class PacketProtocol
      Returns:
      The protocol's packet registry.
    • createEncryption

      protected EncryptionConfig createEncryption(Key key)
    • getState

      public ProtocolState getState()
      Gets the current ProtocolState the client is in.
      Returns:
      The current ProtocolState.
    • setState

      public void setState(ProtocolState state)
    • loadNetworkCodec

      public static org.cloudburstmc.nbt.NbtMap loadNetworkCodec()
    • getCodec

      public PacketCodec getCodec()
      The codec used for the Minecraft protocol.
    • getProfile

      public GameProfile getProfile()
      The player's identity.
    • getAccessToken

      public String getAccessToken()
      Authentication access token.
    • isUseDefaultListeners

      public boolean isUseDefaultListeners()
      Whether to add the default client and server listeners for performing initial login.
    • setUseDefaultListeners

      public void setUseDefaultListeners(boolean useDefaultListeners)
      Whether to add the default client and server listeners for performing initial login.