Interface UserConnection


  • public interface UserConnection
    • Method Detail

      • get

        <T extends StorableObject> @Nullable T get​(java.lang.Class<T> objectClass)
        Get an object from the storage.
        Type Parameters:
        T - The type of the class you want to get.
        Parameters:
        objectClass - The class of the object to get
        Returns:
        The requested object
      • has

        boolean has​(java.lang.Class<? extends StorableObject> objectClass)
        Check if the storage has an object.
        Parameters:
        objectClass - The object class to check
        Returns:
        True if the object is in the storage
      • put

        void put​(StorableObject object)
        Put an object into the stored objects based on class.
        Parameters:
        object - The object to store.
      • getEntityTrackers

        java.util.Collection<EntityTracker> getEntityTrackers()
        Returns a collection of entity trackers currently registered.
        Returns:
        collection of entity trackers currently registered
      • getEntityTracker

        <T extends EntityTracker> @Nullable T getEntityTracker​(java.lang.Class<? extends Protocol> protocolClass)
        Returns the entity tracker by the given protocol class if present.
        Type Parameters:
        T - entity tracker type
        Parameters:
        protocolClass - protocol class
        Returns:
        entity tracker if present
      • addEntityTracker

        void addEntityTracker​(java.lang.Class<? extends Protocol> protocolClass,
                              EntityTracker tracker)
        Adds an entity tracker to the user connection.
        Parameters:
        protocolClass - protocol class
        tracker - entity tracker
      • clearStoredObjects

        void clearStoredObjects()
        Clear stored objects and entity trackers. Used for Bungee when switching servers.
      • sendRawPacket

        void sendRawPacket​(io.netty.buffer.ByteBuf packet)
        Sends a raw packet to the connection on the current thread.
        Parameters:
        packet - raw packet to send
      • scheduleSendRawPacket

        void scheduleSendRawPacket​(io.netty.buffer.ByteBuf packet)
        Send a raw packet to the player, submitted to the netty event loop.
        Parameters:
        packet - raw packet to send
      • sendRawPacketFuture

        io.netty.channel.ChannelFuture sendRawPacketFuture​(io.netty.buffer.ByteBuf packet)
        Send a raw packet to the player with returning the future.
        Parameters:
        packet - The raw packet to send
        Returns:
        ChannelFuture of the packet being sent
      • getPacketTracker

        PacketTracker getPacketTracker()
        Returns the user's packet tracker used for the inbuilt packet-limiter.
        Returns:
        packet tracker
      • disconnect

        void disconnect​(java.lang.String reason)
        Disconnect a connection.
        Parameters:
        reason - The reason to use, not used if player is not active.
      • sendRawPacketToServer

        void sendRawPacketToServer​(io.netty.buffer.ByteBuf packet)
        Sends a raw packet to the server on the current thread.
        Parameters:
        packet - raw packet to be sent
      • scheduleSendRawPacketToServer

        void scheduleSendRawPacketToServer​(io.netty.buffer.ByteBuf packet)
        Sends a raw packet to the server, submitted to the netty event loop.
        Parameters:
        packet - raw packet to be sent
      • checkServerboundPacket

        boolean checkServerboundPacket()
        Monitors serverbound packets and returns whether a packet can/should be processed.
        Returns:
        false if this packet should be cancelled
      • checkClientboundPacket

        boolean checkClientboundPacket()
        Monitors clientbound packets and returns whether a packet can/should be processed.
        Returns:
        false if this packet should be cancelled
      • shouldTransformPacket

        boolean shouldTransformPacket()
        Checks if packets needs transforming.
        Returns:
        whether packets should be passed through
      • transformClientbound

        void transformClientbound​(io.netty.buffer.ByteBuf buf,
                                  java.util.function.Function<java.lang.Throwable,​java.lang.Exception> cancelSupplier)
                           throws java.lang.Exception
        Transforms the clientbound packet contained in ByteBuf.
        Parameters:
        buf - ByteBuf with packet id and packet contents
        cancelSupplier - function called with original CancelException for generating the Exception when the packet is cancelled
        Throws:
        CancelException - if the packet should be cancelled
        InformativeException - if packet transforming failed
        java.lang.Exception - if any other processing outside of transforming fails
      • transformServerbound

        void transformServerbound​(io.netty.buffer.ByteBuf buf,
                                  java.util.function.Function<java.lang.Throwable,​java.lang.Exception> cancelSupplier)
                           throws java.lang.Exception
        Transforms the serverbound packet contained in ByteBuf.
        Parameters:
        buf - ByteBuf with packet id and packet contents
        cancelSupplier - Function called with original CancelException for generating the Exception used when packet is cancelled
        Throws:
        CancelException - if the packet should be cancelled
        InformativeException - if packet transforming failed
        java.lang.Exception - if any other processing outside of transforming fails
      • transformOutgoing

        default void transformOutgoing​(io.netty.buffer.ByteBuf buf,
                                       java.util.function.Function<java.lang.Throwable,​java.lang.Exception> cancelSupplier)
                                throws java.lang.Exception
        Transforms the packet depending on whether the connection is clientside or not.
        Throws:
        java.lang.Exception
        See Also:
        transformClientbound(ByteBuf, Function), transformServerbound(ByteBuf, Function)
      • transformIncoming

        default void transformIncoming​(io.netty.buffer.ByteBuf buf,
                                       java.util.function.Function<java.lang.Throwable,​java.lang.Exception> cancelSupplier)
                                throws java.lang.Exception
        Transforms the packet depending on whether the connection is clientside or not.
        Throws:
        java.lang.Exception
        See Also:
        transformClientbound(ByteBuf, Function), transformServerbound(ByteBuf, Function)
      • getId

        long getId()
        Returns the internal id incremented for each new connection.
        Returns:
        internal id
      • getChannel

        @Nullable io.netty.channel.Channel getChannel()
        Returns the netty channel if present.
        Returns:
        netty channel if present
      • getProtocolInfo

        ProtocolInfo getProtocolInfo()
        Returns info containing the current protocol state and userdata.
        Returns:
        info containing the current protocol state and userdata
      • isActive

        boolean isActive()
        Returns whether the connection has protocols other than the base protocol applied.
        Returns:
        whether the connection is active
      • setActive

        void setActive​(boolean active)
      • isPendingDisconnect

        boolean isPendingDisconnect()
        Returns whether the connection is pending a disconnect, initiated through disconnect(String).
        Returns:
        whether the connection is pending a disconnect
      • setPendingDisconnect

        void setPendingDisconnect​(boolean pendingDisconnect)
      • isClientSide

        boolean isClientSide()
        Returns whether this is a client-side connection. This is a mod integrated into the client itself, or for example a backend Velocity connection.
        Returns:
        whether this is a client-side connection
      • shouldApplyBlockProtocol

        boolean shouldApplyBlockProtocol()
        Returns whether ViaVersionConfig.blockedProtocolVersions() should be checked for this connection.
        Returns:
        whether blocked protocols should be applied
      • isPacketLimiterEnabled

        boolean isPacketLimiterEnabled()
        Returns whether the packet limiter applies to this user.
        Returns:
        whether the packet limiter applies to this user
      • setPacketLimiterEnabled

        void setPacketLimiterEnabled​(boolean packetLimiterEnabled)
        Sets the status of the packet limiter.
        Parameters:
        packetLimiterEnabled - whether the packet limiter should be enabled
      • generatePassthroughToken

        java.util.UUID generatePassthroughToken()
        Returns a newly generated uuid that will let a packet be passed through without transformig its contents if used together with PacketWrapper.PASSTHROUGH_ID.
        Returns:
        generated passthrough token