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.
    • enableEncryption

      protected PacketEncryption enableEncryption(Key key)
    • getState

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

      public void setState(ProtocolState state)
    • createClientboundPacket

      public Packet createClientboundPacket(int id, io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper)
      Description copied from class: PacketProtocol
      Creates a new instance of a clientbound packet with the given id and read the clientbound input.
      Overrides:
      createClientboundPacket in class PacketProtocol
      Parameters:
      id - Id of the packet to create.
      buf - The buffer to read the packet from.
      codecHelper - The codec helper.
      Returns:
      The created packet.
    • getClientboundId

      public int getClientboundId(Class<? extends Packet> packetClass)
      Description copied from class: PacketProtocol
      Gets the registered id of a clientbound packet class.
      Overrides:
      getClientboundId in class PacketProtocol
      Parameters:
      packetClass - Class of the packet to get the id for.
      Returns:
      The packet's registered id.
    • getClientboundId

      public int getClientboundId(Packet packet)
      Description copied from class: PacketProtocol
      Gets the registered id of a clientbound Packet instance.
      Overrides:
      getClientboundId in class PacketProtocol
      Parameters:
      packet - Instance of Packet to get the id for.
      Returns:
      The packet's registered id.
    • getClientboundClass

      public Class<? extends Packet> getClientboundClass(int id)
      Description copied from class: PacketProtocol
      Gets the packet class for a packet id.
      Overrides:
      getClientboundClass in class PacketProtocol
      Parameters:
      id - The packet id.
      Returns:
      The registered packet's class
    • createServerboundPacket

      public Packet createServerboundPacket(int id, io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper)
      Description copied from class: PacketProtocol
      Creates a new instance of a serverbound packet with the given id and read the serverbound input.
      Overrides:
      createServerboundPacket in class PacketProtocol
      Parameters:
      id - Id of the packet to create.
      buf - The buffer to read the packet from.
      codecHelper - The codec helper.
      Returns:
      The created packet.
    • getServerboundId

      public int getServerboundId(Class<? extends Packet> packetClass)
      Description copied from class: PacketProtocol
      Gets the registered id of a serverbound packet class.
      Overrides:
      getServerboundId in class PacketProtocol
      Parameters:
      packetClass - Class of the packet to get the id for.
      Returns:
      The packet's registered id.
    • getServerboundId

      public int getServerboundId(Packet packet)
      Description copied from class: PacketProtocol
      Gets the registered id of a serverbound Packet instance.
      Overrides:
      getServerboundId in class PacketProtocol
      Parameters:
      packet - Instance of Packet to get the id for.
      Returns:
      The packet's registered id.
    • getServerboundClass

      public Class<? extends Packet> getServerboundClass(int id)
      Description copied from class: PacketProtocol
      Gets the packet class for a packet id.
      Overrides:
      getServerboundClass in class PacketProtocol
      Parameters:
      id - The packet id.
      Returns:
      The registered packet's class
    • getServerboundDefinition

      public PacketDefinition<?,?> getServerboundDefinition(int id)
      Description copied from class: PacketProtocol
      Gets the serverbound packet definition for the given packet id.
      Overrides:
      getServerboundDefinition in class PacketProtocol
      Parameters:
      id - The packet id.
      Returns:
      The registered packet's class
    • getClientboundDefinition

      public PacketDefinition<?,?> getClientboundDefinition(int id)
      Description copied from class: PacketProtocol
      Gets the clientbound packet definition for the given packet id.
      Overrides:
      getClientboundDefinition in class PacketProtocol
      Parameters:
      id - The packet id.
      Returns:
      The registered packet's class
    • 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.