getOnlinePlayers

public static Collection<? extends Player> getOnlinePlayers()

Gets view of all currently logged in players. This view is reused object, making some operations like size zero-allocation.

The collection is view backed by the internal representation, such that, changes to the internal state of the server will be reflected immediately. However, the reuse of the returned collection (identity) is not strictly guaranteed for future or all implementations. Casting the collection, or relying on interface implementations (like or List), is deprecated.

Iteration behavior is undefined outside of self-contained main-thread uses. Normal and immediate iterator use without consequences that affect the collection are fully supported. The effects following (non-exhaustive) teleportation, death, and kicking are undefined. Any use of this collection from asynchronous threads is unsafe.

For safe consequential iteration or mimicking the old array behavior, using toArray is recommended. For making snapshots, copyOf is recommended.

Return

view of currently online players.