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

      public void newClientSession(Session session)
      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.
    • 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.
    • getInboundPacketRegistry

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

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

      protected EncryptionConfig createEncryption(Key key)
    • resetStates

      public void resetStates()
      Resets the protocol states to ProtocolState.HANDSHAKE.
    • getInboundState

      public ProtocolState getInboundState()
      Gets the current inbound ProtocolState we're in.
      Returns:
      The current inbound ProtocolState.
    • getOutboundState

      public ProtocolState getOutboundState()
      Gets the current outbound ProtocolState we're in.
      Returns:
      The current outbound ProtocolState.
    • setInboundState

      public void setInboundState(ProtocolState state)
    • setOutboundState

      public void setOutboundState(ProtocolState state)
    • loadNetworkCodec

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

      public static org.cloudburstmc.nbt.NbtMap loadNetworkTags()
    • 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.