Skip to content

Commit

Permalink
Add stream online players method (#2457)
Browse files Browse the repository at this point in the history
* Add stream online players method

* run spotless apply
  • Loading branch information
ImMorpheus authored Apr 22, 2023
1 parent 5bafc99 commit f69db9f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/spongepowered/api/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.Collection;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;

/**
* Represents a typical Minecraft Server.
Expand Down Expand Up @@ -225,6 +226,13 @@ public interface Server extends ForwardingAudience, Engine, LocaleSource {
*/
TeleportHelper teleportHelper();

/**
* Gets a {@link Stream} of all the {@link ServerPlayer}s currently online.
*
* @return The stream of online players
*/
Stream<ServerPlayer> streamOnlinePlayers();

/**
* Gets the {@link ServerPlayer}s currently online.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface PacketDispatcher {
* @param packet The packet to send
*/
default void sendToAllPlayers(final Packet packet) {
Sponge.server().onlinePlayers().forEach(player -> this.sendTo(player, packet));
Sponge.server().streamOnlinePlayers().forEach(player -> this.sendTo(player, packet));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public interface RawPlayDataChannel {
* @param payload A consumer to write the data to
*/
default void sendToAllPlayers(final Consumer<ChannelBuf> payload) {
Sponge.server().onlinePlayers().forEach(player -> this.sendTo(player, payload));
Sponge.server().streamOnlinePlayers().forEach(player -> this.sendTo(player, payload));
}

/**
Expand Down

0 comments on commit f69db9f

Please sign in to comment.