Interface UserConnection
public interface UserConnection
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddClientWorld(Class<? extends Protocol> protocolClass, ClientWorld clientWorld) Adds a client world to the user connection.voidaddEntityTracker(Class<? extends Protocol> protocolClass, EntityTracker tracker) Adds an entity tracker to the user connection.voidaddItemHasher(Class<? extends Protocol> protocolClass, ItemHasher itemHasher) Adds an item hasher to the user connection.booleanMonitors clientbound packets and returns whether a packet can/should be processed.default booleanDeprecated, for removal: This API element is subject to removal in a future version.default booleancheckIncomingPacket(int bytes) default booleandefault booleanDeprecated, for removal: This API element is subject to removal in a future version.booleancheckServerboundPacket(int bytes) Monitors serverbound packets and returns whether a packet can/should be processed.voidClear stored objects, entity trackers and client worlds.voiddisconnect(String reason) Disconnect a connection.Returns a newly generated uuid that will let a packet be passed through without transforming its contents if used together withPacketWrapper.PASSTHROUGH_ID.<T extends StorableObject>
@Nullable TGet an object from the storage.@Nullable io.netty.channel.ChannelReturns 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.longgetId()Returns the internal id incremented for each new connection.<T extends ItemHasher>
@Nullable TgetItemHasher(Class<? extends Protocol> protocolClass) Returns the item hasher by the given protocol class if present.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.booleanhas(Class<? extends StorableObject> objectClass) Check if the storage has an object.booleanisActive()Returns whether the connection has protocols other than the base protocol applied.booleanReturns whether this is a backend connection.booleanReturns whether the connection is pending a disconnect, initiated throughdisconnect(String).default booleanReturns whether this is a frontend connection.voidput(StorableObject object) Put an object into the stored objects based on class.<T extends StorableObject>
@Nullable TRemoves and returns an object from the storage.voidscheduleSendRawPacket(io.netty.buffer.ByteBuf packet) Send a raw packet to the player, submitted to the netty event loop.voidscheduleSendRawPacketToServer(io.netty.buffer.ByteBuf packet) Sends a raw packet to the server, submitted to the netty event loop.voidsendRawPacket(io.netty.buffer.ByteBuf packet) Sends a raw packet to the connection on the current thread.io.netty.channel.ChannelFuturesendRawPacketFuture(io.netty.buffer.ByteBuf packet) Send a raw packet to the player with returning the future.voidsendRawPacketToServer(io.netty.buffer.ByteBuf packet) Sends a raw packet to the server on the current thread.voidsetActive(boolean active) voidsetPendingDisconnect(boolean pendingDisconnect) default booleanReturns whetherViaVersionConfig.blockedProtocolVersions()should be checked for this connection.booleanChecks if packets needs transforming.voidtransformClientbound(io.netty.buffer.ByteBuf buf, Function<Throwable, io.netty.handler.codec.CodecException> cancelSupplier) Transforms the clientbound packet contained in ByteBuf.default voidtransformIncoming(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 voidtransformOutgoing(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.voidtransformServerbound(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
-
addItemHasher
Adds an item hasher to the user connection.- Parameters:
protocolClass- protocol classitemHasher- item hasher
-
getItemHasher
Returns the item hasher by the given protocol class if present.- Type Parameters:
T- item hasher type- Parameters:
protocolClass- protocol class- Returns:
- item hasher if present
-
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
void clearStoredObjects()Clear stored objects, entity trackers and client worlds. -
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(int bytes) Monitors serverbound packets and returns whether a packet can/should be processed.- Parameters:
bytes- the number of bytes in the packet- Returns:
- false if this packet should be cancelled
-
checkServerboundPacket
Deprecated, for removal: This API element is subject to removal in a future version. -
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(int bytes) -
checkIncomingPacket
Deprecated, for removal: This API element is subject to removal in a future version. -
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 backend connection. This is a mod integrated into the client, or for example a backend Velocity connection.- Returns:
- whether this is a backend connection
-
isServerSide
default boolean isServerSide()Returns whether this is a frontend connection. This is a plugin integrated into the server, or for example a frontend Velocity connection.- Returns:
- whether this is a frontend connection
-
shouldApplyBlockProtocol
default 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 transforming its contents if used together withPacketWrapper.PASSTHROUGH_ID.- Returns:
- generated passthrough token
-