From 79262306820cc874d1830210b71729884efaa918 Mon Sep 17 00:00:00 2001 From: Thinkofdeath Date: Tue, 1 Mar 2016 12:37:45 +1100 Subject: [PATCH] #1765: Fix ServerInfo.ping to handle chat components. --- .../java/net/md_5/bungee/api/ServerPing.java | 28 +++++++++++++++++-- .../main/java/net/md_5/bungee/BungeeCord.java | 6 ++++ .../bungee/connection/InitialHandler.java | 3 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/ServerPing.java b/api/src/main/java/net/md_5/bungee/api/ServerPing.java index 19337a55..f3e7a56e 100644 --- a/api/src/main/java/net/md_5/bungee/api/ServerPing.java +++ b/api/src/main/java/net/md_5/bungee/api/ServerPing.java @@ -5,8 +5,11 @@ import java.util.List; import java.util.UUID; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; import net.md_5.bungee.Util; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; /** * Represents the standard list data returned by opening a server in the @@ -73,7 +76,8 @@ public class ServerPing return uniqueId.toString().replaceAll( "-", "" ); } } - private String description; + + private BaseComponent description; private Favicon favicon; @Data @@ -100,7 +104,13 @@ public class ServerPing @Deprecated public ServerPing(Protocol version, Players players, String description, String favicon) { - this( version, players, description, favicon == null ? null : Favicon.create( favicon ) ); + this( version, players, new TextComponent( TextComponent.fromLegacyText(description) ), favicon == null ? null : Favicon.create( favicon ) ); + } + + @Deprecated + public ServerPing(Protocol version, Players players, String description, Favicon favicon) + { + this( version, players, new TextComponent( TextComponent.fromLegacyText(description) ), favicon ); } @Deprecated @@ -124,4 +134,18 @@ public class ServerPing { this.favicon = favicon; } + + @Deprecated + public void setDescription(String description) { + this.description = new TextComponent( TextComponent.fromLegacyText( description ) ); + } + + @Deprecated + public String getDescription() { + return BaseComponent.toLegacyText( description ); + } + + public BaseComponent getDescriptionComponent() { + return description; + } } diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 176c71cf..e5afb89e 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -11,6 +11,9 @@ import com.google.gson.GsonBuilder; import net.md_5.bungee.api.Favicon; import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.Title; +import net.md_5.bungee.api.chat.TranslatableComponent; +import net.md_5.bungee.chat.TextComponentSerializer; +import net.md_5.bungee.chat.TranslatableComponentSerializer; import net.md_5.bungee.module.ModuleManager; import com.google.common.io.ByteStreams; import net.md_5.bungee.api.chat.BaseComponent; @@ -140,6 +143,9 @@ public class BungeeCord extends ProxyServer @Getter private final Logger logger; public final Gson gson = new GsonBuilder() + .registerTypeAdapter( BaseComponent.class, new ComponentSerializer() ) + .registerTypeAdapter( TextComponent.class, new TextComponentSerializer() ) + .registerTypeAdapter( TranslatableComponent.class, new TranslatableComponentSerializer() ) .registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer() ) .registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create(); @Getter diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index f972e42d..34b1a4bc 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -142,7 +142,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection final boolean v1_5 = ping.isV1_5(); ServerPing legacy = new ServerPing( new ServerPing.Protocol( bungee.getName() + " " + bungee.getGameVersion(), bungee.getProtocolVersion() ), - new ServerPing.Players( listener.getMaxPlayers(), bungee.getOnlineCount(), null ), listener.getMotd(), (Favicon) null ); + new ServerPing.Players( listener.getMaxPlayers(), bungee.getOnlineCount(), null ), + new TextComponent( TextComponent.fromLegacyText( listener.getMotd() ) ), (Favicon) null ); Callback callback = new Callback() {