Fixed sending ServerData packets if the description component from the backend server is null (#1673)

This commit is contained in:
Adrian
2025-10-20 19:51:47 -05:00
committed by GitHub
parent 02cf349075
commit 7412aca81c
4 changed files with 22 additions and 11 deletions

View File

@@ -70,7 +70,7 @@ tasks {
"https://jd.advntr.dev/api/${libs.adventure.bom.get().version}/", "https://jd.advntr.dev/api/${libs.adventure.bom.get().version}/",
"https://jd.advntr.dev/text-minimessage/${libs.adventure.bom.get().version}/", "https://jd.advntr.dev/text-minimessage/${libs.adventure.bom.get().version}/",
"https://jd.advntr.dev/key/${libs.adventure.bom.get().version}/", "https://jd.advntr.dev/key/${libs.adventure.bom.get().version}/",
"https://javadoc.io/doc/com.github.ben-manes.caffeine/caffeine/${libs.caffeine.get().version}/", "https://www.javadocs.dev/com.github.ben-manes.caffeine/caffeine/${libs.caffeine.get().version}/",
) )
o.tags( o.tags(

View File

@@ -19,7 +19,9 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable; import net.kyori.adventure.text.Component;
import org.jspecify.annotations.Nullable;
/** /**
* Represents a 1.7 and above server list ping response. This class is immutable. * Represents a 1.7 and above server list ping response. This class is immutable.
@@ -28,7 +30,7 @@ public final class ServerPing {
private final Version version; private final Version version;
private final @Nullable Players players; private final @Nullable Players players;
private final net.kyori.adventure.text.Component description; private final @Nullable Component description;
private final @Nullable Favicon favicon; private final @Nullable Favicon favicon;
private final @Nullable ModInfo modinfo; private final @Nullable ModInfo modinfo;
@@ -47,7 +49,7 @@ public final class ServerPing {
* @param modinfo the mods this server runs * @param modinfo the mods this server runs
*/ */
public ServerPing(Version version, @Nullable Players players, public ServerPing(Version version, @Nullable Players players,
net.kyori.adventure.text.Component description, @Nullable Favicon favicon, Component description, @Nullable Favicon favicon,
@Nullable ModInfo modinfo) { @Nullable ModInfo modinfo) {
this.version = Preconditions.checkNotNull(version, "version"); this.version = Preconditions.checkNotNull(version, "version");
this.players = players; this.players = players;
@@ -64,7 +66,8 @@ public final class ServerPing {
return Optional.ofNullable(players); return Optional.ofNullable(players);
} }
public net.kyori.adventure.text.Component getDescriptionComponent() { @Nullable
public Component getDescriptionComponent() {
return description; return description;
} }
@@ -151,7 +154,7 @@ public final class ServerPing {
private final List<SamplePlayer> samplePlayers = new ArrayList<>(); private final List<SamplePlayer> samplePlayers = new ArrayList<>();
private String modType = "FML"; private String modType = "FML";
private final List<ModInfo.Mod> mods = new ArrayList<>(); private final List<ModInfo.Mod> mods = new ArrayList<>();
private net.kyori.adventure.text.Component description; private Component description;
private @Nullable Favicon favicon; private @Nullable Favicon favicon;
private boolean nullOutPlayers; private boolean nullOutPlayers;
private boolean nullOutModinfo; private boolean nullOutModinfo;
@@ -299,7 +302,7 @@ public final class ServerPing {
* @param description Component to use as the description. * @param description Component to use as the description.
* @return this builder, for chaining * @return this builder, for chaining
*/ */
public Builder description(net.kyori.adventure.text.Component description) { public Builder description(Component description) {
this.description = Preconditions.checkNotNull(description, "description"); this.description = Preconditions.checkNotNull(description, "description");
return this; return this;
} }
@@ -359,7 +362,7 @@ public final class ServerPing {
return samplePlayers; return samplePlayers;
} }
public Optional<net.kyori.adventure.text.Component> getDescriptionComponent() { public Optional<Component> getDescriptionComponent() {
return Optional.ofNullable(description); return Optional.ofNullable(description);
} }

View File

@@ -36,6 +36,7 @@ import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
/** /**
* Common utilities for handling server list ping results. * Common utilities for handling server list ping results.
@@ -107,6 +108,13 @@ public class ServerListPingHandler {
if (response == fallback) { if (response == fallback) {
continue; continue;
} }
if (response.getDescriptionComponent() == null) {
return response.asBuilder()
.description(Component.empty())
.build();
}
return response; return response;
} }
return fallback; return fallback;