Skip to content

Add methods to Audience allowing access to previously shown BossBars #820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions api/src/main/java/net/kyori/adventure/audience/Audience.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
package net.kyori.adventure.audience;

import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collector;
Expand All @@ -43,6 +45,7 @@
import net.kyori.adventure.title.TitlePart;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.UnmodifiableView;

/**
* A receiver of Minecraft media.
Expand Down Expand Up @@ -608,6 +611,25 @@ default void showBossBar(final @NotNull BossBar bar) {
default void hideBossBar(final @NotNull BossBar bar) {
}

/**
* Check if this audience has been shown this BossBar
* @param bar BossBar
* @return boolean
* @since 4.12.0
*/
default boolean hasBossBar(final @NotNull BossBar bar) {
return false;
}

/**
* Returns a set containing all BossBars this Audience has been shown
* @return An unmodifiable set of BossBars
* @since 4.12.0
*/
default @NotNull @UnmodifiableView Set<BossBar> getBossBars() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This does not follow Kyori's organizational naming standards -- you shouldn't have get prefixes.
  2. We can't really get all boss bars here, especially if we're in a proxy environment.

return Collections.emptySet();
}

/**
* Plays a sound at the location of the recipient of the sound.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.HashSet;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand All @@ -47,6 +49,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnknownNullability;
import org.jetbrains.annotations.UnmodifiableView;

/**
* A receiver that wraps one or more receivers.
Expand Down Expand Up @@ -174,6 +177,21 @@ default void hideBossBar(final @NotNull BossBar bar) {
for (final Audience audience : this.audiences()) audience.hideBossBar(bar);
}

@Override
default boolean hasBossBar(final @NotNull BossBar bar) {
for (final Audience audience : this.audiences()) {
if (audience.hasBossBar(bar)) return true;
}
return false;
}

@Override
default @NotNull @UnmodifiableView Set<BossBar> getBossBars() {
Set<BossBar> ret = new HashSet<>();
for (final Audience audience : this.audiences()) ret.addAll(audience.getBossBars());
return Collections.unmodifiableSet(ret);
}

@Override
default void playSound(final @NotNull Sound sound) {
for (final Audience audience : this.audiences()) audience.playSound(sound);
Expand Down Expand Up @@ -337,6 +355,16 @@ default void hideBossBar(final @NotNull BossBar bar) {
this.audience().hideBossBar(bar);
}

@Override
default boolean hasBossBar(final @NotNull BossBar bar) {
return this.audience().hasBossBar(bar);
}

@Override
default @NotNull @UnmodifiableView Set<BossBar> getBossBars() {
return this.audience().getBossBars();
}

@Override
default void playSound(final @NotNull Sound sound) {
this.audience().playSound(sound);
Expand Down