Class PacketRegistration<P extends com.velocitypowered.proxy.protocol.MinecraftPacket>
java.lang.Object
io.github._4drian3d.vpacketevents.api.register.PacketRegistration<P>
- Type Parameters:
P- the packet class
public final class PacketRegistration<P extends com.velocitypowered.proxy.protocol.MinecraftPacket>
extends Object
Process of registering a packet in the internal Velocity State's PacketRegistry
// UpdateTeamsPacket registration
PacketRegistration.of(UpdateTeamsPacket.class)
.direction(ProtocolUtils.Direction.CLIENTBOUND)
.packetSupplier(UpdateTeamsPacket::new)
.stateRegistry(StateRegistry.PLAY)
.mapping(0x47, MINECRAFT_1_13, false)
.mapping(0x4B, MINECRAFT_1_14, false)
.mapping(0x4C, MINECRAFT_1_15, false)
.mapping(0x55, MINECRAFT_1_17, false)
.mapping(0x58, MINECRAFT_1_19_1, false)
.mapping(0x56, MINECRAFT_1_19_3, false)
.mapping(0x5A, MINECRAFT_1_19_4, false)
.register();
-
Method Summary
Modifier and TypeMethodDescriptiondirection(@NotNull com.velocitypowered.proxy.protocol.ProtocolUtils.Direction direction) Sets the packet direction of this Packet registrationmapping(int id, @NotNull ProtocolVersion version, boolean encodeOnly) Adds a PacketMapping using the provided arguments.mapping(int id, @NotNull ProtocolVersion version, @NotNull ProtocolVersion lastValidProtocolVersion, boolean encodeOnly) Adds a PacketMapping using the provided arguments.static <P extends com.velocitypowered.proxy.protocol.MinecraftPacket>
PacketRegistration<P>Initiates a new packet registration processpacketSupplier(@NotNull Supplier<@NotNull P> packetSupplier) Sets the supplier of this Packetvoidregister()Registers the packet in the PacketRegistry of a supplied StatestateRegistry(@NotNull com.velocitypowered.proxy.protocol.StateRegistry stateRegistry) Sets the state registry of this Packet registration
-
Method Details
-
packetSupplier
Sets the supplier of this PacketThis supplier will be used to generate the new packets to serialize, which you can use in PacketSentEvent and PacketReceiveEvent events
PacketRegistration.of(SomeMinecraftPacket.class) .packetSupplier(SomeMinecraftPacket::new);- Parameters:
packetSupplier- this packet supplier creator- Returns:
- this packet registration
- See Also:
-
direction
public PacketRegistration<P> direction(@NotNull com.velocitypowered.proxy.protocol.ProtocolUtils.Direction direction) Sets the packet direction of this Packet registrationDirection Types: CLIENTBOUND, SERVERBOUND
- Parameters:
direction- the packet direction- Returns:
- this packet registration
-
stateRegistry
public PacketRegistration<P> stateRegistry(@NotNull @NotNull com.velocitypowered.proxy.protocol.StateRegistry stateRegistry) - Parameters:
stateRegistry- the state registry- Returns:
- this packet registration
-
mapping
public PacketRegistration<P> mapping(int id, @NotNull @NotNull ProtocolVersion version, @NotNull @NotNull ProtocolVersion lastValidProtocolVersion, boolean encodeOnly) Adds a PacketMapping using the provided arguments.This must be the last mapping assigned, otherwise, an error will occur when trying to register the mapping
- Parameters:
id- Packet Idversion- Protocol versionencodeOnly- When true packet decoding will be disabledlastValidProtocolVersion- Last version this Mapping is valid at- Returns:
- this packet registration
-
mapping
public PacketRegistration<P> mapping(int id, @NotNull @NotNull ProtocolVersion version, boolean encodeOnly) Adds a PacketMapping using the provided arguments.- Parameters:
id- Packet Idversion- Protocol versionencodeOnly- When true packet decoding will be disabled- Returns:
- this packet registration
-
register
public void register()Registers the packet in the PacketRegistry of a supplied State- Throws:
NullPointerException- in case the packet supplier,ProtocolUtils.DirectionorStateRegistryhave not been assignedIllegalStateException- if no mappings have been assigned to this packet- See Also:
-
of
public static <P extends com.velocitypowered.proxy.protocol.MinecraftPacket> PacketRegistration<P> of(Class<P> packetClass) Initiates a new packet registration process- Type Parameters:
P- the packet class to register- Parameters:
packetClass- the packet class- Returns:
- a new Packet Registration of the type P
-