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 Details

    • packetSupplier

      public PacketRegistration<P> packetSupplier(@NotNull @NotNull Supplier<@NotNull P> packetSupplier)
      Sets the supplier of this Packet

      This 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 registration

      Direction 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)
      Sets the state registry of this Packet registration

      State types: HANDSHAKE, STATUS, LOGIN PLAY

      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 Id
      version - Protocol version
      encodeOnly - When true packet decoding will be disabled
      lastValidProtocolVersion - 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 Id
      version - Protocol version
      encodeOnly - 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.Direction or StateRegistry have not been assigned
      IllegalStateException - 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