#1765: Fix ServerInfo.ping to handle chat components.

This commit is contained in:
Thinkofdeath 2016-03-01 12:37:45 +11:00 committed by md_5
parent dd66e3068a
commit 7926230682
3 changed files with 34 additions and 3 deletions

View File

@ -5,8 +5,11 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import net.md_5.bungee.Util; 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 * Represents the standard list data returned by opening a server in the
@ -73,7 +76,8 @@ public class ServerPing
return uniqueId.toString().replaceAll( "-", "" ); return uniqueId.toString().replaceAll( "-", "" );
} }
} }
private String description;
private BaseComponent description;
private Favicon favicon; private Favicon favicon;
@Data @Data
@ -100,7 +104,13 @@ public class ServerPing
@Deprecated @Deprecated
public ServerPing(Protocol version, Players players, String description, String favicon) 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 @Deprecated
@ -124,4 +134,18 @@ public class ServerPing
{ {
this.favicon = favicon; 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;
}
} }

View File

@ -11,6 +11,9 @@ import com.google.gson.GsonBuilder;
import net.md_5.bungee.api.Favicon; import net.md_5.bungee.api.Favicon;
import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.Title; 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 net.md_5.bungee.module.ModuleManager;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
@ -140,6 +143,9 @@ public class BungeeCord extends ProxyServer
@Getter @Getter
private final Logger logger; private final Logger logger;
public final Gson gson = new GsonBuilder() 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( ServerPing.PlayerInfo.class, new PlayerInfoSerializer() )
.registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create(); .registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create();
@Getter @Getter

View File

@ -142,7 +142,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
final boolean v1_5 = ping.isV1_5(); final boolean v1_5 = ping.isV1_5();
ServerPing legacy = new ServerPing( new ServerPing.Protocol( bungee.getName() + " " + bungee.getGameVersion(), bungee.getProtocolVersion() ), 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<ProxyPingEvent> callback = new Callback<ProxyPingEvent>() Callback<ProxyPingEvent> callback = new Callback<ProxyPingEvent>()
{ {