Type Parameters:
CU - unmapped clientbound packet types
CM - mapped clientbound packet types
SM - mapped serverbound packet types
SU - unmapped serverbound packet types
All Known Subinterfaces:
ProtocolPipeline, SimpleProtocol
All Known Implementing Classes:
AbstractProtocol, AbstractSimpleProtocol

public interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
Abstract protocol class handling packet transformation between two protocol versions. Clientbound and serverbount packet types can be set to enforce correct usage of them.
See Also:
  • Method Details

    • registerClientbound

      default void registerClientbound(State state, ClientboundPacketType packetType, @Nullable PacketHandler handler)
    • registerServerbound

      default void registerServerbound(State state, ServerboundPacketType packetType, @Nullable PacketHandler handler)
    • registerServerbound

      default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler)
    • registerServerbound

      void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override)
      Registers a serverbound packet, with id transformation and remapper.
      Parameters:
      state - state which the packet is sent in.
      unmappedPacketId - unmapped packet id
      mappedPacketId - mapped packet id
      handler - packet handler
      override - whether an existing mapper should be overridden
      See Also:
    • cancelServerbound

      void cancelServerbound(State state, int mappedPacketId)
    • registerClientbound

      default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler)
    • cancelClientbound

      void cancelClientbound(State state, int unmappedPacketId)
    • registerClientbound

      void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override)
      Registers a clientbound packet, with id transformation and remapper.
      Parameters:
      state - state which the packet is sent in.
      unmappedPacketId - unmapped packet id
      mappedPacketId - mapped packet id
      handler - packet handler
      override - whether an existing mapper should be overridden
      See Also:
    • registerClientbound

      void registerClientbound(CU packetType, @Nullable PacketHandler handler)
      Registers a clientbound protocol and automatically maps it to the new id.
      Parameters:
      packetType - clientbound packet type the server sends
      handler - packet handler
    • registerClientbound

      default void registerClientbound(CU packetType, @Nullable CM mappedPacketType)
      Maps a packet type to another packet type without a packet handler. Note that this should not be called for simple channel mappings of the same packet; this is already done automatically.
      Parameters:
      packetType - clientbound packet type the server initially sends
      mappedPacketType - clientbound packet type after transforming for the client
    • registerClientbound

      default void registerClientbound(CU packetType, @Nullable CM mappedPacketType, @Nullable PacketHandler handler)
      Registers a clientbound packet mapping.
      Parameters:
      packetType - clientbound packet type the server initially sends
      mappedPacketType - clientbound packet type after transforming for the client
      handler - packet handler
    • registerClientbound

      void registerClientbound(CU packetType, @Nullable CM mappedPacketType, @Nullable PacketHandler handler, boolean override)
      Registers a clientbound packet mapping.
      Parameters:
      packetType - clientbound packet type the server initially sends
      mappedPacketType - clientbound packet type after transforming for the client
      handler - packet handler
      override - whether an existing mapping should be overridden if present
    • cancelClientbound

      void cancelClientbound(CU packetType)
      Cancels any clientbound packets from the given type.
      Parameters:
      packetType - clientbound packet type to cancel
    • registerServerbound

      default void registerServerbound(SU packetType, @Nullable SM mappedPacketType)
      Maps a packet type to another packet type without a packet handler. Note that this should not be called for simple channel mappings of the same packet; this is already done automatically.
      Parameters:
      packetType - serverbound packet type the client initially sends
      mappedPacketType - serverbound packet type after transforming for the client
    • registerServerbound

      void registerServerbound(SU packetType, @Nullable PacketHandler handler)
      Registers a serverbound protocol and automatically maps it to the server's id.
      Parameters:
      packetType - serverbound packet type the client sends
      handler - packet handler
    • registerServerbound

      default void registerServerbound(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketHandler handler)
      Registers a serverbound protocol.
      Parameters:
      packetType - serverbound packet type initially sent by the client
      mappedPacketType - serverbound packet type after transforming for the server
      handler - packet handler
    • registerServerbound

      void registerServerbound(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketHandler handler, boolean override)
      Registers a serverbound packet mapping.
      Parameters:
      packetType - serverbound packet type initially sent by the client
      mappedPacketType - serverbound packet type after transforming for the server
      handler - packet handler
      override - whether an existing mapping should be overridden if present
    • cancelServerbound

      void cancelServerbound(SU packetType)
      Cancels any serverbound packets from the given type.
      Parameters:
      packetType - serverbound packet type to cancel
    • hasRegisteredClientbound

      default boolean hasRegisteredClientbound(CU packetType)
      Checks if a clientbound packet has already been registered.
      Parameters:
      packetType - clientbound packet type
      Returns:
      true if already registered
    • hasRegisteredServerbound

      default boolean hasRegisteredServerbound(SU packetType)
      Checks if a serverbound packet has already been registered.
      Parameters:
      packetType - serverbound packet type
      Returns:
      true if already registered
    • hasRegisteredClientbound

      boolean hasRegisteredClientbound(State state, int unmappedPacketId)
      Checks if a clientbound packet has already been registered.
      Parameters:
      state - state which the packet is sent in
      unmappedPacketId - unmapped packet id
      Returns:
      true if already registered
    • hasRegisteredServerbound

      boolean hasRegisteredServerbound(State state, int unmappedPacketId)
      Checks if a serverbound packet has already been registered.
      Parameters:
      state - state which the packet is sent in
      unmappedPacketId - mapped packet id
      Returns:
      true if already registered
    • appendClientbound

      void appendClientbound(CU type, PacketHandler handler)
      Appends a clientbound packet type handler with another, as opposed to replacing it entirely.

      Use PacketWrapper.set(Type, int, Object) to change individual parts, or call PacketWrapper.resetReader() to reset the reader index.

      Parameters:
      type - clientbound packet type
      handler - packet handler
    • appendServerbound

      void appendServerbound(SU type, PacketHandler handler)
      Appends a serverbound packet type handler with another, as opposed to replacing it entirely.

      Use PacketWrapper.set(Type, int, Object) to change individual parts, or call PacketWrapper.resetReader() to reset the reader index.

      Parameters:
      type - serverbound packet type
      handler - packet handler
    • transform

      void transform(Direction direction, State state, PacketWrapper packetWrapper) throws InformativeException, CancelException
      Transform a packet using this protocol
      Parameters:
      direction - The direction the packet is going in
      state - The current protocol state
      packetWrapper - The packet wrapper to transform
      Throws:
      InformativeException
      CancelException
    • getPacketTypesProvider

      PacketTypesProvider<CU,CM,SM,SU> getPacketTypesProvider()
      Returns a packet type provider for this protocol to get packet types by id. Depending on the Protocol, not every state may be populated.
      Returns:
      the packet types provider
    • get

      @Deprecated <T> @Nullable T get(Class<T> objectClass)
      Deprecated.
      Returns a cached object by the given type if present.
      Type Parameters:
      T - type
      Parameters:
      objectClass - class of the object to get
      Returns:
      object if present, else null
    • put

      @Deprecated void put(Object object)
      Deprecated.
      Caches an object, retrievable by using get(Class).
      Parameters:
      object - object to cache
    • initialize

      void initialize()
      Throws:
      IllegalArgumentException - if this method has already been called
    • hasMappingDataToLoad

      default boolean hasMappingDataToLoad()
      Returns true if this Protocol's loadMappingData() method should be called.

      This does *not* necessarily mean that getMappingData() is non-null, since this may be overriden, depending on special cases.

      Returns:
      true if this Protocol's loadMappingData() method should be called
    • loadMappingData

      void loadMappingData()
      Loads the protocol's mapping data.
      Throws:
      NullPointerException - if this protocol has no mapping data
    • register

      default void register(ViaProviders providers)
      Handle protocol registration phase, use this to register providers / tasks.

      To be overridden if needed.

      Parameters:
      providers - The current providers
    • init

      default void init(UserConnection connection)
      Initialise a user for this protocol setting up objects. /!\ WARNING - May be called more than once in a single UserConnection

      To be overridden if needed.

      Parameters:
      connection - user to initialise
    • getMappingData

      default @Nullable MappingData getMappingData()
      Returns the protocol's mapping data if present.
      Returns:
      mapping data if present
    • getLogger

      ProtocolLogger getLogger()
      Returns the protocol's logger.
      Returns:
      logger
    • getEntityRewriter

      default @Nullable EntityRewriter<?> getEntityRewriter()
      Returns the protocol's entity rewriter if present.
      Returns:
      entity rewriter
    • getItemRewriter

      default @Nullable ItemRewriter<?> getItemRewriter()
      Returns the protocol's item rewriter if present.
      Returns:
      item rewriter
    • getTagRewriter

      default @Nullable TagRewriter getTagRewriter()
      Returns the protocol's tag rewriter if present.
      Returns:
      tag rewriter
    • getComponentRewriter

      default @Nullable ComponentRewriter getComponentRewriter()
    • isBaseProtocol

      default boolean isBaseProtocol()
      Returns whether this protocol is a base protocol.
      Returns:
      whether this represents a base protocol