Class ProtocolManager
Do not call this manager if ProtocolLib is not loaded and enabled on the server! It will not work.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionasync()Get the async protocol manager for working with asynchronous listeners.voidbroadcastServerPacket(PacketContainer packet) Broadcast a packet to the entire server.voidbroadcastServerPacket(PacketContainer packet, Collection<? extends Player> targetPlayers) Broadcast a packet to a specified list of players.voidbroadcastServerPacket(PacketContainer packet, Entity entity) Broadcast a packet to players receiving information about a particular entity.voidbroadcastServerPacket(PacketContainer packet, Entity entity, boolean includeTracker) Broadcast a packet to players receiving information about a particular entity.voidbroadcastServerPacket(PacketContainer packet, Location origin, int maxObserverDistance) Broadcast a packet to all players within a given max observer distance from an origin location (center point).createPacket(PacketType type) Create a new packet with the given type.static ProtocolManagerget()Get the singleton instance of this ProtocolManager.getPacketListener(dev.magicmq.pyspigot.manager.script.Script script, PacketType packetType) Get the normal packet listener for a particular packet type associated with a script.getPacketListeners(dev.magicmq.pyspigot.manager.script.Script script) Get all normal packet listeners associated with a script, excluding asynchronous packet listeners.Get the current ProtocolLib ProtocolManager.registerPacketListener(PyFunction function, PacketType type) Register a new packet listener with default priority.registerPacketListener(PyFunction function, PacketType type, ListenerPriority priority) Register a new packet listener.voidsendServerPacket(Player player, PacketContainer packet) Send a packet to a player.voidunregisterPacketListener(ScriptPacketListener listener) Unregister a packet listener.voidunregisterPacketListeners(dev.magicmq.pyspigot.manager.script.Script script) Unregister all normal packet listeners belonging to a script, excluding asynchronous packet listeners.
-
Method Details
-
getProtocolManager
Get the current ProtocolLib ProtocolManager.- Returns:
- The
ProtocolManager
-
async
Get the async protocol manager for working with asynchronous listeners.- Returns:
- The
AsyncProtocolManager
-
registerPacketListener
Register a new packet listener with default priority.This method will automatically register a
PacketReceivingListeneror aPacketSendingListener, depending on if thePacketTypeis for the server or client, respectively.Note: This should be called from scripts only!
- Parameters:
function- The function that should be called when the packet event occurstype- The packet type to listen for- Returns:
- A
ScriptPacketListenerrepresenting the packet listener that was registered
-
registerPacketListener
public ScriptPacketListener registerPacketListener(PyFunction function, PacketType type, ListenerPriority priority) Register a new packet listener.This method will automatically register a
PacketReceivingListeneror aPacketSendingListener, depending on if thePacketTypeis for the server or client, respectively.Note: This should be called from scripts only!
- Parameters:
function- The function that should be called when the packet event occurstype- The packet type to listen forpriority- The priority of the packet listener relative to other packet listeners- Returns:
- A
ScriptPacketListenerrepresenting the packet listener that was registered
-
unregisterPacketListener
Unregister a packet listener.Note: This should be called from scripts only!
- Parameters:
listener- The packet listener to unregister
-
unregisterPacketListeners
public void unregisterPacketListeners(dev.magicmq.pyspigot.manager.script.Script script) Unregister all normal packet listeners belonging to a script, excluding asynchronous packet listeners.Use
AsyncProtocolManager.unregisterAsyncPacketListeners(Script)to unregister asynchronous packet listeners.- Parameters:
script- The script whose normal packet listeners should be unregistered
-
getPacketListeners
public List<ScriptPacketListener> getPacketListeners(dev.magicmq.pyspigot.manager.script.Script script) Get all normal packet listeners associated with a script, excluding asynchronous packet listeners.Use
AsyncProtocolManager.getAsyncPacketListeners(Script)to get a script's asynchronous packet listeners.- Parameters:
script- The script to get normal packet listeners from- Returns:
- An immutable list of
ScriptPacketListenercontaining all normal packet listeners associated with this script. Will return an empty list if there are no normal packet listeners associated with the script
-
getPacketListener
public ScriptPacketListener getPacketListener(dev.magicmq.pyspigot.manager.script.Script script, PacketType packetType) Get the normal packet listener for a particular packet type associated with a script.Use
AsyncProtocolManager.getAsyncPacketListener(Script, PacketType)to get a script's asynchronous packet listener of a specific packet type.- Parameters:
script- The scriptpacketType- The packet type- Returns:
- The
ScriptPacketListenerassociated with the script and packet type, or null if there is none
-
createPacket
Create a new packet with the given type. This method will assign sensible default values to all fields within the packet where a non-null value is required.This method is the preferred way to create a packet that will later be sent or broadcasted.
Note: This should be called from scripts only!
- Parameters:
type- The type of packet to create- Returns:
- A
PacketContainerrepresenting the packet that was created.
-
sendServerPacket
Send a packet to a player.Note: This should be called from scripts only!
- Parameters:
player- The player to send the packet topacket- The packet to send
-
broadcastServerPacket
Broadcast a packet to the entire server. The packet will be sent to all online players.Note: This should be called from scripts only!
- Parameters:
packet- The packet to broadcast
-
broadcastServerPacket
Broadcast a packet to players receiving information about a particular entity. Will also broadcast the packet to the entity, if the entity is a tracker.Note: This should be called from scripts only!
- Parameters:
packet- The packet to broadcastentity- The entity whose trackers will be informed- See Also:
-
broadcastServerPacket
Broadcast a packet to players receiving information about a particular entity.Usually, this would be every player in the same world within an observable distance. If the entity is a player, it will be included only if
includeTrackeris set totrue.Note: This should be called from scripts only!
- Parameters:
packet- The packet to broadcastentity- The entity whose trackers will be informedincludeTracker- Whether to also transmit the packet to the entity, if it is a tracker
-
broadcastServerPacket
Broadcast a packet to all players within a given max observer distance from an origin location (center point).Note: This should be called from scripts only!
- Parameters:
packet- The packet to broadcastorigin- The origin location (center point) to consider when calculating distance to each observermaxObserverDistance- The maximum distance from origin wherein packets will be broadcasted
-
broadcastServerPacket
public void broadcastServerPacket(PacketContainer packet, Collection<? extends Player> targetPlayers) Broadcast a packet to a specified list of players.Note: This should be called from scripts only!
- Parameters:
packet- The packet to broadcasttargetPlayers- The list of players to which the packet should be broadcasted
-
get
Get the singleton instance of this ProtocolManager.- Returns:
- The instance
-