public interface PlayerConnectionArray
Interface used to handle packet sending.
It it a non-reflective wrapper of NMS PlayerConnection objects
that are used to send Minecraft packets.
Roughly speaking, it stores and uses a certain group of player's NMS PlayerConnection.
If you plan to send more than 4-5 packets to players
somewhere, then using this wrapper will be
more beneficial (faster) than using ServerConnection due
to caching array of NMS PlayerConnection directly in field.
It is better not to cache it long-term, however if you
really want to do so, you ought to update underlying array content
using update method at least on player disconnect to make
sure all NMS PlayerConnection objects are valid inside.
It is instantiated by ServerConnection instance and should
only be obtained from it.
ServerConnection| Modifier and Type | Method and Description |
|---|---|
void |
sendPacket(java.lang.Object packet)
Sends packet to players using their NMS
PlayerConnection. |
void |
updateArray(java.util.Collection<org.bukkit.entity.Player> players)
Updates underlying
PlayerConnection array
with NMS PlayerConnection objects acquired
from Player collection. |
void sendPacket(java.lang.Object packet)
Sends packet to players using their NMS PlayerConnection.
A generated code for this method looks roughly like this:
void sendPacket(Object packet) {
PlayerConnection[] pcs = this.playerConnectionArr;
int length = pcs.length;
while (length > 0) {
pcs[--length].sendPacket((Packet) packet);
}
}
If you plan to send more than 4-5 packets players
somewhere, then using this wrapper will be
more beneficial (faster) than using ServerConnection due
to caching array of NMS PlayerConnection directly in field.
It is better not to cache it long-term, however if you
really want to do so, you ought to update underlying array content
using update method at least on player disconnect to make
sure all NMS PlayerConnection objects are valid inside.
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.java.lang.ClassCastException - when provided packet object is not
an instance of Minecraft packet interfacevoid updateArray(java.util.Collection<org.bukkit.entity.Player> players)
Updates underlying PlayerConnection array
with NMS PlayerConnection objects acquired
from Player collection.
A generated code for this method looks roughly like this:
void update(Collection<Player> players) {
int length = players.size();
PlayerConnection[] pcs = new PlayerConnection[length];
Iterator<Player> it = players.iterator();
while (length > 0) {
pcs[--length] = ((CraftPlayer) it.next()).getHandle()
.playerConnection;
}
this.playerConnectionArr = pcs;
}
You usually don't have to use this method if you don't cache this wrapper anywhere.
However, if you store this wrapper long-term, you ought to update
underlying array content using this method at least on player disconnect to make
sure all NMS PlayerConnection objects are valid inside.
players - a collection of players which should be used
to update underlying array.Copyright © 2020. All Rights Reserved.