Package net.minestom.server.utils
Class PacketSendingUtils
java.lang.Object
net.minestom.server.utils.PacketSendingUtils
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
broadcastPlayPacket
(@NotNull ServerPacket packet) static void
sendGroupedPacket
(@NotNull Collection<Player> players, @NotNull ServerPacket packet) Same assendGroupedPacket(Collection, ServerPacket, Predicate)
but without any predicate.static void
sendGroupedPacket
(@NotNull Collection<Player> players, @NotNull ServerPacket packet, @NotNull Predicate<Player> predicate) Sends aServerPacket
to multiple players.static void
sendPacket
(@NotNull Audience audience, @NotNull ServerPacket packet) Sends a packet to an audience.
-
Constructor Details
-
PacketSendingUtils
public PacketSendingUtils()
-
-
Method Details
-
sendPacket
public static void sendPacket(@NotNull @NotNull Audience audience, @NotNull @NotNull ServerPacket packet) Sends a packet to an audience. This method performs the following steps in the following order:- If
audience
is aPlayer
, send the packet to them. - Otherwise, if
audience
is aPacketGroupingAudience
, callsendGroupedPacket(Collection, ServerPacket)
on the players that the grouping audience contains. - Otherwise, if
audience
is aForwardingAudience.Single
, call this method on the single audience inside the forwarding audience. - Otherwise, if
audience
is aForwardingAudience
, call this method for each audience member of the forwarding audience. - Otherwise, do nothing.
- Parameters:
audience
- the audiencepacket
- the packet
- If
-
sendGroupedPacket
public static void sendGroupedPacket(@NotNull @NotNull Collection<Player> players, @NotNull @NotNull ServerPacket packet, @NotNull @NotNull Predicate<Player> predicate) Sends aServerPacket
to multiple players.Can drastically improve performance since the packet will not have to be processed as much.
- Parameters:
players
- the players to send the packet topacket
- the packet to send to the playerspredicate
- predicate to ignore specific players
-
sendGroupedPacket
public static void sendGroupedPacket(@NotNull @NotNull Collection<Player> players, @NotNull @NotNull ServerPacket packet) Same assendGroupedPacket(Collection, ServerPacket, Predicate)
but without any predicate.- See Also:
-
broadcastPlayPacket
-