Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch all ping passthroughs to json to avoid parsing warning #5363

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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