Interface Protocol<C1 extends ClientboundPacketType,​C2 extends ClientboundPacketType,​S1 extends ServerboundPacketType,​S2 extends ServerboundPacketType>

    • Method Detail

      • registerServerbound

        default void registerServerbound​(State state,
                                         int oldPacketID,
                                         int newPacketID)
      • registerServerbound

        default void registerServerbound​(State state,
                                         int oldPacketID,
                                         int newPacketID,
                                         PacketRemapper packetRemapper)
      • cancelServerbound

        void cancelServerbound​(State state,
                               int newPacketID)
      • registerClientbound

        default void registerClientbound​(State state,
                                         int oldPacketID,
                                         int newPacketID)
      • registerClientbound

        default void registerClientbound​(State state,
                                         int oldPacketID,
                                         int newPacketID,
                                         PacketRemapper packetRemapper)
      • cancelClientbound

        void cancelClientbound​(State state,
                               int oldPacketID)
      • registerClientbound

        void registerClientbound​(C1 packetType,
                                 @Nullable PacketRemapper packetRemapper)
        Registers a clientbound protocol and automatically maps it to the new id.
        Parameters:
        packetType - clientbound packet type the server sends
        packetRemapper - remapper
      • registerClientbound

        default void registerClientbound​(C1 packetType,
                                         @Nullable C2 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​(C1 packetType,
                                         @Nullable C2 mappedPacketType,
                                         @Nullable PacketRemapper packetRemapper)
        Registers a clientbound packet mapping.
        Parameters:
        packetType - clientbound packet type the server initially sends
        mappedPacketType - clientbound packet type after transforming for the client
        packetRemapper - remapper
      • registerClientbound

        void registerClientbound​(C1 packetType,
                                 @Nullable C2 mappedPacketType,
                                 @Nullable PacketRemapper packetRemapper,
                                 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
        packetRemapper - remapper
        override - whether an existing mapping should be overridden if present
      • cancelClientbound

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

        default void registerServerbound​(S2 packetType,
                                         @Nullable S1 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​(S2 packetType,
                                 @Nullable PacketRemapper packetRemapper)
        Registers a serverbound protocol and automatically maps it to the server's id.
        Parameters:
        packetType - serverbound packet type the client sends
        packetRemapper - remapper
      • registerServerbound

        default void registerServerbound​(S2 packetType,
                                         @Nullable S1 mappedPacketType,
                                         @Nullable PacketRemapper packetRemapper)
        Registers a serverbound protocol.
        Parameters:
        packetType - serverbound packet type initially sent by the client
        mappedPacketType - serverbound packet type after transforming for the server
        packetRemapper - remapper
      • registerServerbound

        void registerServerbound​(S2 packetType,
                                 @Nullable S1 mappedPacketType,
                                 @Nullable PacketRemapper packetRemapper,
                                 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
        packetRemapper - remapper
        override - whether an existing mapping should be overridden if present
      • cancelServerbound

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

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

        boolean hasRegisteredServerbound​(S2 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 oldPacketId)
        Checks if a clientbound packet has already been registered.
        Parameters:
        state - state which the packet is sent in
        oldPacketId - old 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 - new packet id
        Returns:
        true if already registered
      • transform

        void transform​(Direction direction,
                       State state,
                       PacketWrapper packetWrapper)
                throws java.lang.Exception
        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:
        java.lang.Exception - Throws exception if it fails to transform
      • get

        <T> @Nullable T get​(java.lang.Class<T> objectClass)
        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

        void put​(java.lang.Object object)
        Caches an object, retrievable by using get(Class).
        Parameters:
        object - object to cache
      • hasMappingDataToLoad

        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:
        java.lang.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 userConnection)
        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:
        userConnection - The user to initialise
      • getMappingData

        default @Nullable MappingData getMappingData()
        Returns the protocol's mapping data if present.
        Returns:
        mapping data if present
      • 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
      • isBaseProtocol

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