Interface UserConnection
public interface UserConnection
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addClientWorld
(Class<? extends Protocol> protocolClass, ClientWorld clientWorld) Adds a client world to the user connection.void
addEntityTracker
(Class<? extends Protocol> protocolClass, EntityTracker tracker) Adds an entity tracker to the user connection.boolean
Monitors clientbound packets and returns whether a packet can/should be processed.default boolean
default boolean
boolean
Monitors serverbound packets and returns whether a packet can/should be processed.default void
Clear stored objects, entity trackers and client worlds.void
clearStoredObjects
(boolean isServerSwitch) Clear stored objects, entity trackers and client worlds.void
disconnect
(String reason) Disconnect a connection.Returns a newly generated uuid that will let a packet be passed through without transformig its contents if used together withPacketWrapper.PASSTHROUGH_ID
.<T extends StorableObject>
@Nullable TGet an object from the storage.@Nullable io.netty.channel.Channel
Returns the netty channel if present.<T extends ClientWorld>
@Nullable TgetClientWorld
(Class<? extends Protocol> protocolClass) Returns the client world by the given protocol class if present.<T extends EntityTracker>
@Nullable TgetEntityTracker
(Class<? extends Protocol> protocolClass) Returns the entity tracker by the given protocol class if present.Returns a collection of entity trackers currently registered.long
getId()
Returns the internal id incremented for each new connection.Returns the user's packet tracker used for the inbuilt packet-limiter.Returns info containing the current protocol state and userdata.Map<Class<?>,
StorableObject> Returns a map of stored objects.boolean
has
(Class<? extends StorableObject> objectClass) Check if the storage has an object.boolean
isActive()
Returns whether the connection has protocols other than the base protocol applied.boolean
Returns whether this is a client-side connection.boolean
Returns whether the connection is pending a disconnect, initiated throughdisconnect(String)
.void
put
(StorableObject object) Put an object into the stored objects based on class.<T extends StorableObject>
@Nullable TRemoves and returns an object from the storage.void
scheduleSendRawPacket
(io.netty.buffer.ByteBuf packet) Send a raw packet to the player, submitted to the netty event loop.void
scheduleSendRawPacketToServer
(io.netty.buffer.ByteBuf packet) Sends a raw packet to the server, submitted to the netty event loop.void
sendRawPacket
(io.netty.buffer.ByteBuf packet) Sends a raw packet to the connection on the current thread.io.netty.channel.ChannelFuture
sendRawPacketFuture
(io.netty.buffer.ByteBuf packet) Send a raw packet to the player with returning the future.void
sendRawPacketToServer
(io.netty.buffer.ByteBuf packet) Sends a raw packet to the server on the current thread.void
setActive
(boolean active) void
setPendingDisconnect
(boolean pendingDisconnect) boolean
Returns whetherViaVersionConfig.blockedProtocolVersions()
should be checked for this connection.boolean
Checks if packets needs transforming.void
transformClientbound
(io.netty.buffer.ByteBuf buf, Function<Throwable, io.netty.handler.codec.CodecException> cancelSupplier) Transforms the clientbound packet contained in ByteBuf.default void
transformIncoming
(io.netty.buffer.ByteBuf buf, Function<Throwable, io.netty.handler.codec.CodecException> cancelSupplier) Transforms the packet depending on whether the connection is clientside or not.default void
transformOutgoing
(io.netty.buffer.ByteBuf buf, Function<Throwable, io.netty.handler.codec.CodecException> cancelSupplier) Transforms the packet depending on whether the connection is clientside or not.void
transformServerbound
(io.netty.buffer.ByteBuf buf, Function<Throwable, io.netty.handler.codec.CodecException> cancelSupplier) Transforms the serverbound packet contained in ByteBuf.
-
Method Details
-
get
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
Check if the storage has an object.- Parameters:
objectClass
- The object class to check- Returns:
- True if the object is in the storage
-
remove
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
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
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
Adds an entity tracker to the user connection. Does not override existing entity trackers.- Parameters:
protocolClass
- protocol classtracker
- entity tracker
-
getClientWorld
Returns the client world by the given protocol class if present.- Type Parameters:
T
- client world type- Parameters:
protocolClass
- protocol class- Returns:
- client world if present
-
addClientWorld
Adds a client world to the user connection. Does not override existing client worlds.- Parameters:
protocolClass
- protocol classclientWorld
- client world
-
clearStoredObjects
default void clearStoredObjects()Clear stored objects, entity trackers and client worlds. -
clearStoredObjects
void clearStoredObjects(boolean isServerSwitch) Clear stored objects, entity trackers and client worlds. 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
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() -
checkOutgoingPacket
default boolean checkOutgoingPacket() -
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 InformativeExceptionTransforms the clientbound packet contained in ByteBuf.- Parameters:
buf
- ByteBuf with packet id and packet contentscancelSupplier
- 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 InformativeExceptionTransforms the serverbound packet contained in ByteBuf.- Parameters:
buf
- ByteBuf with packet id and packet contentscancelSupplier
- 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 InformativeExceptionTransforms the packet depending on whether the connection is clientside or not. -
transformIncoming
default void transformIncoming(io.netty.buffer.ByteBuf buf, Function<Throwable, io.netty.handler.codec.CodecException> cancelSupplier) throws InformativeExceptionTransforms the packet depending on whether the connection is clientside or not. -
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 throughdisconnect(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 whetherViaVersionConfig.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 withPacketWrapper.PASSTHROUGH_ID
.- Returns:
- generated passthrough token
-