Class MinecraftProtocol
java.lang.Object
org.geysermc.mcprotocollib.network.packet.PacketProtocol
org.geysermc.mcprotocollib.protocol.MinecraftProtocol
Implements the Minecraft protocol.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new MinecraftProtocol instance for making status queries.MinecraftProtocol(@NonNull String username) Constructs a new MinecraftProtocol instance for logging in using offline mode.MinecraftProtocol(@NonNull GameProfile profile, String accessToken) Constructs a new MinecraftProtocol instance for logging in.MinecraftProtocol(@NonNull PacketCodec codec, @NonNull String username) Constructs a new MinecraftProtocol instance for logging in using offline mode.MinecraftProtocol(@NonNull PacketCodec codec, @NonNull GameProfile profile, String accessToken) Constructs a new MinecraftProtocol instance for logging in.MinecraftProtocol(PacketCodec codec) Constructs a new MinecraftProtocol instance for making status queries. -
Method Summary
Modifier and TypeMethodDescriptioncreateClientboundPacket(int id, io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper) Creates a new instance of a clientbound packet with the given id and read the clientbound input.Creates a newPacketCodecHelperthat can be used for each session.createServerboundPacket(int id, io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper) Creates a new instance of a serverbound packet with the given id and read the serverbound input.protected PacketEncryptionenableEncryption(Key key) Authentication access token.getClientboundClass(int id) Gets the packet class for a packet id.PacketDefinition<?,?> getClientboundDefinition(int id) Gets the clientbound packet definition for the given packet id.intgetClientboundId(Class<? extends Packet> packetClass) Gets the registered id of a clientbound packet class.intgetClientboundId(Packet packet) Gets the registered id of a clientboundPacketinstance.getCodec()The codec used for the Minecraft protocol.Gets the packet header of this protocol.The player's identity.getServerboundClass(int id) Gets the packet class for a packet id.PacketDefinition<?,?> getServerboundDefinition(int id) Gets the serverbound packet definition for the given packet id.intgetServerboundId(Class<? extends Packet> packetClass) Gets the registered id of a serverbound packet class.intgetServerboundId(Packet packet) Gets the registered id of a serverboundPacketinstance.Gets the prefix used when locating SRV records for this protocol.getState()Gets the currentProtocolStatethe client is in.booleanWhether to add the default client and server listeners for performing initial login.static org.cloudburstmc.nbt.NbtMapvoidnewClientSession(Session session, boolean transferring) Called when a client session is created with this protocol.voidnewServerSession(Server server, Session session) Called when a server session is created with this protocol.voidsetState(ProtocolState state) voidsetUseDefaultListeners(boolean useDefaultListeners) Whether to add the default client and server listeners for performing initial login.Methods inherited from class org.geysermc.mcprotocollib.network.packet.PacketProtocol
clearPackets, register, register, registerClientbound, registerClientbound, registerServerbound, registerServerbound
-
Constructor Details
-
MinecraftProtocol
public MinecraftProtocol()Constructs a new MinecraftProtocol instance for making status queries. -
MinecraftProtocol
Constructs a new MinecraftProtocol instance for making status queries.- Parameters:
codec- The packet codec to use.
-
MinecraftProtocol
Constructs a new MinecraftProtocol instance for logging in using offline mode.- Parameters:
username- Username to use.
-
MinecraftProtocol
Constructs a new MinecraftProtocol instance for logging in using offline mode.- Parameters:
codec- The packet codec to use.username- Username to use.
-
MinecraftProtocol
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
Description copied from class:PacketProtocolGets the prefix used when locating SRV records for this protocol.- Specified by:
getSRVRecordPrefixin classPacketProtocol- Returns:
- The protocol's SRV record prefix.
-
getPacketHeader
Description copied from class:PacketProtocolGets the packet header of this protocol.- Specified by:
getPacketHeaderin classPacketProtocol- Returns:
- The protocol's packet header.
-
createHelper
Description copied from class:PacketProtocolCreates a newPacketCodecHelperthat can be used for each session.- Specified by:
createHelperin classPacketProtocol- Returns:
- A new
PacketCodecHelper.
-
newClientSession
Description copied from class:PacketProtocolCalled when a client session is created with this protocol.- Specified by:
newClientSessionin classPacketProtocol- Parameters:
session- The created session.transferring- If the client is being transferred between servers.
-
newServerSession
Description copied from class:PacketProtocolCalled when a server session is created with this protocol.- Specified by:
newServerSessionin classPacketProtocol- Parameters:
server- The server that the session belongs to.session- The created session.
-
enableEncryption
-
getState
Gets the currentProtocolStatethe client is in.- Returns:
- The current
ProtocolState.
-
setState
-
createClientboundPacket
public Packet createClientboundPacket(int id, io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper) Description copied from class:PacketProtocolCreates a new instance of a clientbound packet with the given id and read the clientbound input.- Overrides:
createClientboundPacketin classPacketProtocol- 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
Description copied from class:PacketProtocolGets the registered id of a clientbound packet class.- Overrides:
getClientboundIdin classPacketProtocol- Parameters:
packetClass- Class of the packet to get the id for.- Returns:
- The packet's registered id.
-
getClientboundId
Description copied from class:PacketProtocolGets the registered id of a clientboundPacketinstance.- Overrides:
getClientboundIdin classPacketProtocol- Parameters:
packet- Instance ofPacketto get the id for.- Returns:
- The packet's registered id.
-
getClientboundClass
Description copied from class:PacketProtocolGets the packet class for a packet id.- Overrides:
getClientboundClassin classPacketProtocol- 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:PacketProtocolCreates a new instance of a serverbound packet with the given id and read the serverbound input.- Overrides:
createServerboundPacketin classPacketProtocol- 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
Description copied from class:PacketProtocolGets the registered id of a serverbound packet class.- Overrides:
getServerboundIdin classPacketProtocol- Parameters:
packetClass- Class of the packet to get the id for.- Returns:
- The packet's registered id.
-
getServerboundId
Description copied from class:PacketProtocolGets the registered id of a serverboundPacketinstance.- Overrides:
getServerboundIdin classPacketProtocol- Parameters:
packet- Instance ofPacketto get the id for.- Returns:
- The packet's registered id.
-
getServerboundClass
Description copied from class:PacketProtocolGets the packet class for a packet id.- Overrides:
getServerboundClassin classPacketProtocol- Parameters:
id- The packet id.- Returns:
- The registered packet's class
-
getServerboundDefinition
Description copied from class:PacketProtocolGets the serverbound packet definition for the given packet id.- Overrides:
getServerboundDefinitionin classPacketProtocol- Parameters:
id- The packet id.- Returns:
- The registered packet's class
-
getClientboundDefinition
Description copied from class:PacketProtocolGets the clientbound packet definition for the given packet id.- Overrides:
getClientboundDefinitionin classPacketProtocol- Parameters:
id- The packet id.- Returns:
- The registered packet's class
-
loadNetworkCodec
public static org.cloudburstmc.nbt.NbtMap loadNetworkCodec() -
getCodec
The codec used for the Minecraft protocol. -
getProfile
The player's identity. -
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.
-