Skip to content
Open
2 changes: 1 addition & 1 deletion .checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<!-- https://checkstyle.org/config_javadoc.html#AtclauseOrder -->
<module name="AtclauseOrder">
<property name="violateExecutionOnNonTightHtml" value="true"/>
<property name="tagOrder" value="@author, @exception, @param, @return, @serial, @serialData, @serialField, @throws, @see, @since, @sinceMinecraft, @obsoleteSinceMinecraft, @version, @deprecated"/>
<property name="tagOrder" value="@author, @exception, @param, @return, @serial, @serialData, @serialField, @throws, @see, @since, @sinceMinecraft, @obsolete, @obsoleteSinceMinecraft, @version, @deprecated"/>
</module>

<!-- https://checkstyle.org/config_imports.html#AvoidStarImport -->
Expand Down
14 changes: 12 additions & 2 deletions api/src/main/java/net/kyori/adventure/audience/Audience.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.function.Predicate;
import java.util.stream.Collector;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.bossbar.BossBarViewer;
import net.kyori.adventure.chat.ChatType;
import net.kyori.adventure.chat.SignedMessage;
import net.kyori.adventure.dialog.DialogLike;
Expand All @@ -50,6 +49,7 @@
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.title.Title;
import net.kyori.adventure.title.TitlePart;
import org.jetbrains.annotations.UnmodifiableView;

/**
* A receiver of Minecraft media.
Expand Down Expand Up @@ -95,7 +95,6 @@
* and any new methods will be stubbed by default.</p>
*
* @see ForwardingAudience
* @see BossBarViewer
* @since 4.0.0
*/
public interface Audience extends Pointered {
Expand Down Expand Up @@ -441,6 +440,17 @@ default void showBossBar(final BossBar bar) {
default void hideBossBar(final BossBar bar) {
}

/**
* Gets an unmodifiable view of all known currently active bossbars.
*
* @return an unmodifiable view of all known currently active bossbars
* @since 4.14.0
*/
@UnmodifiableView
default Iterable<? extends BossBar> activeBossBars() {
return List.of();
}

/**
* 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 @@ -25,8 +25,10 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Predicate;
Expand All @@ -46,6 +48,7 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.UnknownNullability;
import org.jetbrains.annotations.UnmodifiableView;
import org.jspecify.annotations.Nullable;

/**
Expand Down Expand Up @@ -162,6 +165,16 @@ default void hideBossBar(final BossBar bar) {
for (final Audience audience : this.audiences()) audience.hideBossBar(bar);
}

@Override
default @UnmodifiableView Iterable<? extends BossBar> activeBossBars() {
final Set<BossBar> bossBars = new HashSet<>();
for (final Audience audience : this.audiences()) {
for (final BossBar bb : audience.activeBossBars()) bossBars.add(bb);
}

return bossBars;
}

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

@Override
default @UnmodifiableView Iterable<? extends BossBar> activeBossBars() {
return this.audience().activeBossBars();
}

@Override
default void playSound(final Sound sound) {
this.audience().playSound(sound);
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/net/kyori/adventure/bossbar/BossBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ default BossBar name(final ComponentLike name) {
* @since 4.14.0
*/
@UnmodifiableView
Iterable<? extends BossBarViewer> viewers();
Iterable<? extends Audience> viewers();

/**
* Show this bossbar to {@code viewer}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.util.Services;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -261,7 +262,7 @@ public BossBar removeListener(final Listener listener) {
}

@Override
public Iterable<? extends BossBarViewer> viewers() {
public Iterable<? extends Audience> viewers() {
if (this.implementation != null) {
return this.implementation.viewers();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package net.kyori.adventure.bossbar;

import java.util.List;
import net.kyori.adventure.audience.Audience;
import org.jetbrains.annotations.ApiStatus;

/**
Expand Down Expand Up @@ -54,7 +55,7 @@ static <I extends BossBarImplementation> I get(final BossBar bar, final Class<I>
* @since 4.14.0
*/
@ApiStatus.Internal
default Iterable<? extends BossBarViewer> viewers() {
default Iterable<? extends Audience> viewers() {
return List.of();
}

Expand Down
42 changes: 0 additions & 42 deletions api/src/main/java/net/kyori/adventure/bossbar/BossBarViewer.java

This file was deleted.

1 change: 1 addition & 0 deletions api/src/main/java/net/kyori/adventure/chat/ChatType.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @since 4.12.0
* @sinceMinecraft 1.19
*/
@SuppressWarnings("ClassInitializationDeadlock") // It's fine.
public interface ChatType {
/**
* A chat message from a player.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public String toString() {
* @param <T> the payload type
* @since 4.0.0
*/
@SuppressWarnings("StaticInitializerReferencesSubClass") // We have private subclasses and private constructors for them, so this is fine.
@SuppressWarnings({"StaticInitializerReferencesSubClass", "ClassInitializationDeadlock"}) // We have private subclasses and private constructors for them, so this is fine.
public static sealed abstract class Action<T extends Payload> permits Action.ChangePage, Action.Custom, Action.ShowDialog, Action.TextCarrier {
/**
* Opens a url when clicked.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public static ShowItem showItem(final Key item, final @Range(from = 0, to = Inte
* @param nbt the nbt
* @return a {@code ShowItem}
* @since 4.14.0
* @deprecated since 1.20.5 and replaced with data components
* @obsolete since 1.20.5 and replaced with data components
*/
@ApiStatus.Obsolete
public static ShowItem showItem(final Keyed item, final @Range(from = 0, to = Integer.MAX_VALUE) int count, final @Nullable BinaryTagHolder nbt) {
Expand Down Expand Up @@ -498,7 +498,7 @@ public ShowItem count(final @Range(from = 0, to = Integer.MAX_VALUE) int count)
* @param nbt the nbt
* @return a {@code ShowItem}
* @since 4.0.0
* @deprecated since 1.20.5 and replaced with data components
* @obsoleteSinceMinecraft 1.20.5 and replaced with data components
*/
@ApiStatus.Obsolete
public ShowItem nbt(final @Nullable BinaryTagHolder nbt) {
Expand Down
5 changes: 3 additions & 2 deletions api/src/main/java/net/kyori/adventure/text/format/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import net.kyori.adventure.util.Buildable;
import net.kyori.adventure.util.MonkeyBars;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.UnknownNullability;
import org.jetbrains.annotations.Unmodifiable;
import org.jspecify.annotations.Nullable;

Expand Down Expand Up @@ -160,7 +159,8 @@ static Style style(final @Nullable TextColor color, final Set<TextDecoration> de
* @return a style
* @since 4.0.0
*/
static Style style(final @UnknownNullability StyleBuilderApplicable... applicables) {
@SuppressWarnings("overloads") // It's fine, it's not really correct.
static Style style(final @Nullable StyleBuilderApplicable... applicables) {
final int length = applicables.length;
if (length == 0) return empty();
final Builder builder = style();
Expand Down Expand Up @@ -548,6 +548,7 @@ default Style merge(final Style that, final Set<Merge> merges) {
* @return a builder
* @since 4.0.0
*/
@Override
Builder toBuilder();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ protected Component renderTranslatable(TranslatableComponent component, final C
return this.renderTranslatableInner(component, context);
}

@SuppressWarnings("JdkObsolete") // The MessageFormat API requires StringBuffer.
protected Component renderTranslatableInner(final TranslatableComponent component, final C context) {
final MessageFormat format = this.translate(component.key(), component.fallback(), context);
if (format == null) return this.optionallyRenderChildrenAndStyle(component, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

@SuppressWarnings("unchecked") // We do a whole bunch of unchecked casts, but it's okay because if any fail the tests will fail too.
abstract class AbstractComponentTest<C extends ScopedComponent<C>, B extends ComponentBuilder<C, B>> {
abstract B builder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ void testJoinTextWithChildren() {
assertEquals(expectedCompact, notCompact.compact());
}

@SuppressWarnings("UnusedMethod") // It is used literaly right below this.
private static boolean shouldSkipSimplifyingStyleForBlankComponents() {
return !ComponentCompaction.SIMPLIFY_STYLE_FOR_BLANK_COMPONENTS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public void testOfDfs() {
.build();

for (final Component inner : component.iterable(ComponentIteratorType.DEPTH_FIRST)) {
if (inner instanceof TextComponent) {
final String content = ((TextComponent) inner).content();
if (inner instanceof TextComponent textComponent) {
final String content = textComponent.content();

if (content.equals("WIDE")) {
fail("WIDE before DEEP");
Expand All @@ -97,8 +97,8 @@ public void testOfBfs() {
.build();

for (final Component inner : component.iterable(ComponentIteratorType.BREADTH_FIRST)) {
if (inner instanceof TextComponent) {
final String content = ((TextComponent) inner).content();
if (inner instanceof TextComponent textComponent) {
final String content = textComponent.content();

if (content.equals("DEEP")) {
fail("DEEP before WIDE");
Expand All @@ -124,9 +124,7 @@ public void testOfHover() {
boolean foundEntity = false;

for (final Component inner : component.iterable(ComponentIteratorType.BREADTH_FIRST, ComponentIteratorFlag.INCLUDE_HOVER_SHOW_TEXT_COMPONENT, ComponentIteratorFlag.INCLUDE_HOVER_SHOW_ENTITY_NAME)) {
if (inner instanceof TextComponent) {
final TextComponent text = (TextComponent) inner;

if (inner instanceof TextComponent text) {
if (text.content().equals("TEXT")) foundText = true;
else if (text.content().equals("ENTITY")) foundEntity = true;
}
Expand All @@ -144,9 +142,7 @@ public void testOfTranslatableArguments() {
.build();

for (final Component inner : component.iterable(ComponentIteratorType.BREADTH_FIRST, ComponentIteratorFlag.INCLUDE_TRANSLATABLE_COMPONENT_ARGUMENTS)) {
if (inner instanceof TextComponent) {
final TextComponent text = (TextComponent) inner;

if (inner instanceof TextComponent text) {
if (text.content().equals("ARG")) return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ void testGetOrConvertMessage() {
assertNull(ComponentMessageThrowable.getOrConvertMessage(new IllegalStateException((String) null)));
}

@SuppressWarnings("serial")
static class Checked extends Exception implements ComponentMessageThrowable {
private final @Nullable Component componentMessage;

Expand Down
1 change: 1 addition & 0 deletions api/src/test/java/net/kyori/adventure/util/TicksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

class TicksTest {
@SuppressWarnings("JavaDurationGetSecondsToToSeconds") // This is intentional.
@Test
void testTicks() {
final Duration d0 = Ticks.duration(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ tasks {
javadoc {
val options = options as? StandardJavadocDocletOptions ?: return@javadoc
options.tags(
"obsolete:a:Obsolete",
"sinceMinecraft:a:Since Minecraft:",
"obsoleteSinceMinecraft:a:Obsolete since Minecraft",
)
Expand All @@ -101,6 +102,10 @@ tasks {
disable("ReferenceEquality") // lots of comparison against EMPTY objects
disable("CanIgnoreReturnValueSuggester") // suggests errorprone annotation, not JB Contract annotation
}

options.compilerArgs.add("-Xlint:all")
options.compilerArgs.add("-Xlint:-processing") // unclaimed ap warnings are not needed
options.compilerArgs.add("-Xlint:-serial") // nobody cares about serialization
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* @since 4.0.0
*/
@SuppressWarnings("ClassInitializationDeadlock") // It's fine.
public sealed interface ByteBinaryTag extends NumberBinaryTag permits ByteBinaryTagImpl {
/**
* A tag with the value {@code 0}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ final class ComponentLoggingEventBuilderImpl extends DefaultLoggingEventBuilder
}

private @Nullable Object maybeSerialize(final @Nullable Object input) {
if (input instanceof ComponentLike) {
return this.serialize(((ComponentLike) input).asComponent());
if (input instanceof ComponentLike componentLike) {
return this.serialize(componentLike.asComponent());
} else {
return input;
}
Expand Down
Loading