diff --git a/src/main/java/net/minestom/server/adventure/bossbar/BossBarManager.java b/src/main/java/net/minestom/server/adventure/bossbar/BossBarManager.java index a9b938f19..e3760e643 100644 --- a/src/main/java/net/minestom/server/adventure/bossbar/BossBarManager.java +++ b/src/main/java/net/minestom/server/adventure/bossbar/BossBarManager.java @@ -135,6 +135,38 @@ public class BossBarManager { } } + /** + * Gets a collection of all boss bars currently visible to a given player. + * + * @param player the player + * @return the boss bars + */ + public @NotNull Collection getPlayersBossBars(@NotNull Player player) { + Collection holders = this.playerBars.get(player.getUuid()); + + if (holders == null) { + return Collections.emptyList(); + } else { + return holders.stream().map(holder -> holder.bar).collect(Collectors.toUnmodifiableList()); + } + } + + /** + * Gets all the players for whom the given boss bar is currently visible. + * + * @param bossBar the boss bar + * @return the players + */ + public @NotNull Collection getBossBarViewers(@NotNull BossBar bossBar) { + BossBarHolder holder = this.bars.get(bossBar); + + if (holder == null) { + return Collections.emptyList(); + } else { + return Collections.unmodifiableCollection(holder.players); + } + } + /** * Gets or creates a handler for this bar. *