Fixed sending ServerData packets if the description component from the backend server is null (#1673)
This commit is contained in:
@@ -70,7 +70,7 @@ tasks {
|
||||
"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/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(
|
||||
|
||||
@@ -19,7 +19,9 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
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.
|
||||
@@ -28,7 +30,7 @@ public final class ServerPing {
|
||||
|
||||
private final Version version;
|
||||
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 ModInfo modinfo;
|
||||
|
||||
@@ -47,7 +49,7 @@ public final class ServerPing {
|
||||
* @param modinfo the mods this server runs
|
||||
*/
|
||||
public ServerPing(Version version, @Nullable Players players,
|
||||
net.kyori.adventure.text.Component description, @Nullable Favicon favicon,
|
||||
Component description, @Nullable Favicon favicon,
|
||||
@Nullable ModInfo modinfo) {
|
||||
this.version = Preconditions.checkNotNull(version, "version");
|
||||
this.players = players;
|
||||
@@ -64,7 +66,8 @@ public final class ServerPing {
|
||||
return Optional.ofNullable(players);
|
||||
}
|
||||
|
||||
public net.kyori.adventure.text.Component getDescriptionComponent() {
|
||||
@Nullable
|
||||
public Component getDescriptionComponent() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@@ -151,7 +154,7 @@ public final class ServerPing {
|
||||
private final List<SamplePlayer> samplePlayers = new ArrayList<>();
|
||||
private String modType = "FML";
|
||||
private final List<ModInfo.Mod> mods = new ArrayList<>();
|
||||
private net.kyori.adventure.text.Component description;
|
||||
private Component description;
|
||||
private @Nullable Favicon favicon;
|
||||
private boolean nullOutPlayers;
|
||||
private boolean nullOutModinfo;
|
||||
@@ -299,7 +302,7 @@ public final class ServerPing {
|
||||
* @param description Component to use as the description.
|
||||
* @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");
|
||||
return this;
|
||||
}
|
||||
@@ -359,7 +362,7 @@ public final class ServerPing {
|
||||
return samplePlayers;
|
||||
}
|
||||
|
||||
public Optional<net.kyori.adventure.text.Component> getDescriptionComponent() {
|
||||
public Optional<Component> getDescriptionComponent() {
|
||||
return Optional.ofNullable(description);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
/**
|
||||
* Common utilities for handling server list ping results.
|
||||
@@ -107,6 +108,13 @@ public class ServerListPingHandler {
|
||||
if (response == fallback) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (response.getDescriptionComponent() == null) {
|
||||
return response.asBuilder()
|
||||
.description(Component.empty())
|
||||
.build();
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
return fallback;
|
||||
|
||||
Reference in New Issue
Block a user