Skip to content

Commit

Permalink
Switch all ping passthroughs to json to avoid parsing warning (#5363)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE authored Feb 25, 2025
1 parent ba87207 commit 5f0611f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
package org.geysermc.geyser.platform.bungeecord;

import lombok.AllArgsConstructor;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.BaseComponent;
Expand Down Expand Up @@ -74,7 +76,7 @@ public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {

ServerPing response = event.getResponse();
return new GeyserPingInfo(
response.getDescriptionComponent().toLegacyText(),
GsonComponentSerializer.gson().serialize(BungeeComponentSerializer.get().deserialize(new BaseComponent[]{ response.getDescriptionComponent() })),
response.getPlayers().getMax(),
response.getPlayers().getOnline()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
}
}

String jsonDescription = net.minecraft.network.chat.Component.Serializer.toJson(status.description(), RegistryAccess.EMPTY);
String legacyDescription = LEGACY_SERIALIZER.serialize(GSON_SERIALIZER.deserializeOr(jsonDescription, Component.empty()));

return new GeyserPingInfo(
legacyDescription,
net.minecraft.network.chat.Component.Serializer.toJson(status.description(), RegistryAccess.EMPTY),
status.players().map(ServerStatus.Players::max).orElse(1),
status.players().map(ServerStatus.Players::online).orElse(0)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import com.destroystokyo.paper.network.StatusClient;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -81,7 +83,10 @@ public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
players = new GeyserPingInfo.Players(event.getMaxPlayers(), event.getNumPlayers());
}

return new GeyserPingInfo(event.getMotd(), players);
return new GeyserPingInfo(
GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(event.getMotd())),
players
);
} catch (Exception | LinkageError e) { // LinkageError in the event that method/constructor signatures change
logger.debug("Error while getting Paper ping passthrough: " + e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
package org.geysermc.geyser.platform.spigot;

import lombok.AllArgsConstructor;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.server.ServerListPingEvent;
Expand All @@ -52,7 +54,11 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough {
try {
ServerListPingEvent event = new GeyserPingEvent(inetSocketAddress.getAddress(), Bukkit.getMotd(), Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers());
Bukkit.getPluginManager().callEvent(event);
return new GeyserPingInfo(event.getMotd(), event.getMaxPlayers(), event.getNumPlayers());
return new GeyserPingInfo(
GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(event.getMotd())),
event.getMaxPlayers(),
event.getNumPlayers()
);
} catch (Exception | LinkageError e) { // LinkageError in the event that method/constructor signatures change
logger.debug("Error while getting Bukkit ping passthrough: " + e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.velocitypowered.api.proxy.server.ServerPing;
import com.velocitypowered.api.proxy.server.ServerPing.Version;
import lombok.AllArgsConstructor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.geysermc.geyser.network.GameProtocol;
import org.geysermc.geyser.ping.GeyserPingInfo;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
Expand All @@ -60,7 +60,7 @@ public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
throw new RuntimeException(e);
}
return new GeyserPingInfo(
LegacyComponentSerializer.legacy('§').serialize(event.getPing().getDescriptionComponent()),
GsonComponentSerializer.gson().serialize(event.getPing().getDescriptionComponent()),
event.getPing().getPlayers().map(ServerPing.Players::getMax).orElse(1),
event.getPing().getPlayers().map(ServerPing.Players::getOnline).orElse(0)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String name() {

@Override
public void sendMessage(@NonNull String message) {
handle.sendMessage(LegacyComponentSerializer.legacy('§').deserialize(message));
handle.sendMessage(LegacyComponentSerializer.legacySection().deserialize(message));
}

@Override
Expand Down

0 comments on commit 5f0611f

Please sign in to comment.