Interface UserConnection


public interface UserConnection
  • Method Details

    • get

      <T extends StorableObject> @Nullable T get(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(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
    • remove

      <T extends StorableObject> @Nullable T remove(Class<T> objectClass)
      Removes and returns an object from the storage.
      Type Parameters:
      T - type of the class you want to get
      Parameters:
      objectClass - class of the object to get
      Returns:
      removed storable object if present
    • put

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

      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(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(Class<? extends Protocol> protocolClass, EntityTracker tracker)
      Adds an entity tracker to the user connection. Does not override existing entity trackers.
      Parameters:
      protocolClass - protocol class
      tracker - entity tracker
    • clearStoredObjects

      default void clearStoredObjects()
      Clear stored objects and entity trackers.
    • clearStoredObjects

      void clearStoredObjects(boolean isServerSwitch)
      Clear stored objects and entity trackers. If cleared for a proxy server switch, some stored objects and tracker data will be retained.
      Parameters:
      isServerSwitch - whether the clear is due to a server switch
    • 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(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
    • checkIncomingPacket

      default boolean checkIncomingPacket()
      See Also:
    • checkOutgoingPacket

      default boolean checkOutgoingPacket()
      See Also:
    • shouldTransformPacket

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

      void transformClientbound(io.netty.buffer.ByteBuf buf, Function<Throwable,io.netty.handler.codec.CodecException> cancelSupplier) throws InformativeException
      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:
      io.netty.handler.codec.CodecException - if the packet should be cancelled (by netty)
      InformativeException - if packet transforming failed
    • transformServerbound

      void transformServerbound(io.netty.buffer.ByteBuf buf, Function<Throwable,io.netty.handler.codec.CodecException> cancelSupplier) throws InformativeException
      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:
      io.netty.handler.codec.CodecException - if the packet should be cancelled (by netty)
      InformativeException - if packet transforming failed
    • transformOutgoing

      default void transformOutgoing(io.netty.buffer.ByteBuf buf, Function<Throwable,io.netty.handler.codec.CodecException> cancelSupplier) throws InformativeException
      Transforms the packet depending on whether the connection is clientside or not.
      Throws:
      InformativeException
      See Also:
    • transformIncoming

      default void transformIncoming(io.netty.buffer.ByteBuf buf, Function<Throwable,io.netty.handler.codec.CodecException> cancelSupplier) throws InformativeException
      Transforms the packet depending on whether the connection is clientside or not.
      Throws:
      InformativeException
      See Also:
    • 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
    • getStoredObjects

      Map<Class<?>,StorableObject> getStoredObjects()
      Returns a map of stored objects.
      Returns:
      map of stored objects
      See Also:
    • 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
    • generatePassthroughToken

      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