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/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(
|
||||||
|
|||||||
@@ -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,8 +49,8 @@ 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;
|
||||||
this.description = Preconditions.checkNotNull(description, "description");
|
this.description = Preconditions.checkNotNull(description, "description");
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public class ComponentHolder {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.error(
|
logger.error(
|
||||||
"Error converting binary component to JSON component! "
|
"Error converting binary component to JSON component! "
|
||||||
+ "Binary: " + binaryTag + " JSON: " + json, ex);
|
+ "Binary: " + binaryTag + " JSON: " + json, ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,7 @@ public class ComponentHolder {
|
|||||||
|
|
||||||
public static BinaryTag serialize(JsonElement json) {
|
public static BinaryTag serialize(JsonElement json) {
|
||||||
if (json instanceof JsonPrimitive jsonPrimitive) {
|
if (json instanceof JsonPrimitive jsonPrimitive) {
|
||||||
if (jsonPrimitive.isNumber()) {
|
if (jsonPrimitive.isNumber()) {
|
||||||
Number number = json.getAsNumber();
|
Number number = json.getAsNumber();
|
||||||
|
|
||||||
if (number instanceof Byte) {
|
if (number instanceof Byte) {
|
||||||
|
|||||||
Reference in New Issue
Block a user