public interface PlayerConnection
Interface used to handle packet sending.
It it a non-reflective wrapper of NMS PlayerConnection
that is used to send Minecraft packets.
Roughly speaking, it stores and uses a certain player's NMS PlayerConnection.
If you plan to send more than 4-5 packets to one
of Player somewhere, then using this wrapper slightly faster
than using particles lists due to
caching NMS PlayerConnection directly in field.
It is better not to cache it long-term (for ex.
in HashMap/ArrayList etc.) and any complications to do it
anyways will be significantly slower than particles lists.
PlayerConnection from particles lists is fast, really.
It is instantiated by particles lists and should only be obtained from them.
ServerConnection| Modifier and Type | Method and Description |
|---|---|
void |
sendPacket(Object packet)
Sends packet to a Player using its NMS
PlayerConnection. |
void sendPacket(Object packet)
Sends packet to a Player using its NMS PlayerConnection.
A generated code for this method looks roughly like this:
void sendPacket(Object packet) {
playerConnection.sendPacket((Packet) packet);
}
If you plan to send more than 4-5 packets to one
of Player somewhere, then using this wrapper slightly faster
than using particles lists due to
caching NMS PlayerConnection directly in field.
It is better not to cache it long-term (for ex.
in HashMap/ArrayList etc.) and any complications to do it
anyways will be significantly slower than particles lists.
PlayerConnection from particles lists is fast, really.
A packet parameter must be an instance of Minecraft packet interface.
Otherwise, you might get ClassCastException on packet parameter.
You can use this method to send other packet than instances created using this API. Any valid Minecraft packet can be used by this method.
packet - a valid Minecraft packet created either by this API or
via reflections.ClassCastException - when provided packet object is not
an instance of Minecraft packet interfaceCopyright © 2022. All Rights Reserved.