From d84964d55b07784a543180b52ce815daeffd73ee Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 25 Jun 2021 20:32:13 +0800 Subject: [PATCH 1/3] Add sendGroupedPacket convenience method to PacketGroupingAudience --- .../server/adventure/audience/PacketGroupingAudience.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java b/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java index cd18eeec1..9f4c4dc0f 100644 --- a/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java +++ b/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java @@ -14,6 +14,7 @@ import net.minestom.server.adventure.AdventurePacketConvertor; import net.minestom.server.entity.Player; import net.minestom.server.message.ChatPosition; import net.minestom.server.message.Messenger; +import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.play.*; import net.minestom.server.utils.PacketUtils; import org.jetbrains.annotations.NotNull; @@ -44,6 +45,10 @@ public interface PacketGroupingAudience extends ForwardingAudience { */ @NotNull Collection getPlayers(); + default void sendGroupedPacket(ServerPacket packet) { + PacketUtils.sendGroupedPacket(this.getPlayers(), packet); + } + @Override default void sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) { Messenger.sendMessage(this.getPlayers(), message, ChatPosition.fromMessageType(type), source.uuid()); From 07a2b37f3582c63ed8bbccc3216090683b94e64e Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 25 Jun 2021 20:34:19 +0800 Subject: [PATCH 2/3] Add Javadoc --- .../server/adventure/audience/PacketGroupingAudience.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java b/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java index 9f4c4dc0f..9e20b2567 100644 --- a/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java +++ b/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java @@ -45,6 +45,10 @@ public interface PacketGroupingAudience extends ForwardingAudience { */ @NotNull Collection getPlayers(); + /** + * Broadcast a ServerPacket to all players of this audience + * @param packet the packet to broadcast + */ default void sendGroupedPacket(ServerPacket packet) { PacketUtils.sendGroupedPacket(this.getPlayers(), packet); } From e69c02f46d597e73b6455a00f04bd7333775b7ec Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 25 Jun 2021 20:41:54 +0800 Subject: [PATCH 3/3] Change other usages of PacketUtils#sendGroupedPacket to use new convenience method --- .../audience/PacketGroupingAudience.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java b/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java index 9e20b2567..40775bf96 100644 --- a/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java +++ b/src/main/java/net/minestom/server/adventure/audience/PacketGroupingAudience.java @@ -60,28 +60,28 @@ public interface PacketGroupingAudience extends ForwardingAudience { @Override default void sendActionBar(@NotNull Component message) { - PacketUtils.sendGroupedPacket(this.getPlayers(), new ActionBarPacket(message)); + sendGroupedPacket(new ActionBarPacket(message)); } @Override default void sendPlayerListHeaderAndFooter(@NotNull Component header, @NotNull Component footer) { - PacketUtils.sendGroupedPacket(this.getPlayers(), new PlayerListHeaderAndFooterPacket(header, footer)); + sendGroupedPacket(new PlayerListHeaderAndFooterPacket(header, footer)); } @Override default void showTitle(@NotNull Title title) { - PacketUtils.sendGroupedPacket(this.getPlayers(), new SetTitleTextPacket(title.title())); - PacketUtils.sendGroupedPacket(this.getPlayers(), new SetTitleSubTitlePacket(title.subtitle())); + sendGroupedPacket(new SetTitleTextPacket(title.title())); + sendGroupedPacket(new SetTitleSubTitlePacket(title.subtitle())); } @Override default void clearTitle() { - PacketUtils.sendGroupedPacket(this.getPlayers(), new ClearTitlesPacket()); + sendGroupedPacket(new ClearTitlesPacket()); } @Override default void resetTitle() { - PacketUtils.sendGroupedPacket(this.getPlayers(), new ClearTitlesPacket(true)); + sendGroupedPacket(new ClearTitlesPacket(true)); } @Override @@ -96,13 +96,13 @@ public interface PacketGroupingAudience extends ForwardingAudience { @Override default void playSound(@NotNull Sound sound, double x, double y, double z) { - PacketUtils.sendGroupedPacket(this.getPlayers(), AdventurePacketConvertor.createSoundPacket(sound, x, y, z)); + sendGroupedPacket(AdventurePacketConvertor.createSoundPacket(sound, x, y, z)); } @Override default void playSound(@NotNull Sound sound, Sound.@NotNull Emitter emitter) { if (emitter != Sound.Emitter.self()) { - PacketUtils.sendGroupedPacket(this.getPlayers(), AdventurePacketConvertor.createSoundPacket(sound, emitter)); + sendGroupedPacket(AdventurePacketConvertor.createSoundPacket(sound, emitter)); } else { // if we're playing on self, we need to delegate to each audience member for (Audience audience : this.audiences()) { @@ -113,7 +113,7 @@ public interface PacketGroupingAudience extends ForwardingAudience { @Override default void stopSound(@NotNull SoundStop stop) { - PacketUtils.sendGroupedPacket(this.getPlayers(), AdventurePacketConvertor.createSoundStopPacket(stop)); + sendGroupedPacket(AdventurePacketConvertor.createSoundStopPacket(stop)); }