From 3800610f66f56d946396d217b730ffbada73dad5 Mon Sep 17 00:00:00 2001 From: kashike Date: Mon, 6 May 2019 18:44:55 -0700 Subject: [PATCH] Bump text to 3.0.0 --- api/build.gradle | 5 ++++- .../api/event/ResultedEvent.java | 4 ++-- build.gradle | 1 + .../velocitypowered/proxy/VelocityServer.java | 5 ++--- .../proxy/command/ServerCommand.java | 6 +++--- .../proxy/command/VelocityCommand.java | 17 +++++++-------- .../proxy/config/VelocityConfiguration.java | 7 ++++--- .../connection/client/ConnectedPlayer.java | 21 +++++++++++-------- .../client/InitialInboundConnection.java | 5 +++-- .../util/ConnectionRequestResults.java | 6 +++--- .../proxy/console/VelocityConsole.java | 4 ++-- .../proxy/protocol/netty/GS4QueryHandler.java | 4 ++-- .../proxy/protocol/packet/Chat.java | 4 ++-- .../proxy/protocol/packet/Disconnect.java | 4 ++-- .../protocol/packet/HeaderAndFooter.java | 4 ++-- .../protocol/packet/LegacyDisconnect.java | 12 +++++------ .../proxy/protocol/packet/PlayerListItem.java | 6 +++--- .../protocol/packet/TabCompleteResponse.java | 6 +++--- 18 files changed, 63 insertions(+), 58 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index 7fb454545..aebf17db4 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -18,7 +18,10 @@ sourceSets { dependencies { compile 'com.google.code.gson:gson:2.8.5' compile "com.google.guava:guava:${guavaVersion}" - compile 'net.kyori:text:1.12-1.6.5' + compile "net.kyori:text-api:${textVersion}" + compile "net.kyori:text-serializer-gson:${textVersion}" + compile "net.kyori:text-serializer-legacy:${textVersion}" + compile "net.kyori:text-serializer-plain:${textVersion}" compile 'com.moandjiezana.toml:toml4j:0.7.2' compile "org.slf4j:slf4j-api:${slf4jVersion}" compile 'com.google.inject:guice:4.2.0' diff --git a/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java b/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java index bb09e00aa..3b25dcfc9 100644 --- a/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java @@ -3,7 +3,7 @@ package com.velocitypowered.api.event; import com.google.common.base.Preconditions; import java.util.Optional; import net.kyori.text.Component; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.plain.PlainComponentSerializer; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -102,7 +102,7 @@ public interface ResultedEvent { return "allowed"; } if (reason != null) { - return "denied: " + ComponentSerializers.PLAIN.serialize(reason); + return "denied: " + PlainComponentSerializer.INSTANCE.serialize(reason); } return "denied"; } diff --git a/build.gradle b/build.gradle index 0a59b3530..7ff37d4a2 100644 --- a/build.gradle +++ b/build.gradle @@ -20,6 +20,7 @@ allprojects { ext { // dependency versions + textVersion = '3.0.0' junitVersion = '5.3.0-M1' slf4jVersion = '1.7.25' log4jVersion = '2.11.2' diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 29bfd1418..826d46db7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -60,7 +60,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import net.kyori.text.Component; import net.kyori.text.TextComponent; -import net.kyori.text.serializer.GsonComponentSerializer; +import net.kyori.text.serializer.gson.GsonComponentSerializer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.EnsuresNonNull; @@ -70,8 +70,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; public class VelocityServer implements ProxyServer { private static final Logger logger = LogManager.getLogger(VelocityServer.class); - public static final Gson GSON = new GsonBuilder() - .registerTypeHierarchyAdapter(Component.class, new GsonComponentSerializer()) + public static final Gson GSON = GsonComponentSerializer.populate(new GsonBuilder()) .registerTypeHierarchyAdapter(Favicon.class, new FaviconSerializer()) .registerTypeHierarchyAdapter(GameProfile.class, new GameProfileSerializer()) .create(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java index 650911f38..9a64bc95b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java @@ -62,13 +62,13 @@ public class ServerCommand implements Command { String playersText = rs.getPlayersConnected().size() + " player(s) online"; if (rs.getServerInfo().getName().equals(currentServer)) { infoComponent = infoComponent.color(TextColor.GREEN) - .hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + .hoverEvent(HoverEvent.showText( TextComponent.of("Currently connected to this server\n" + playersText))); } else { infoComponent = infoComponent.color(TextColor.GRAY) - .clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, + .clickEvent(ClickEvent.runCommand( "/server " + rs.getServerInfo().getName())) - .hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + .hoverEvent(HoverEvent.showText( TextComponent.of("Click to connect to this server\n" + playersText))); } serverListBuilder.append(infoComponent); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommand.java index 42dcd3c1c..a67582a0a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommand.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; -import net.kyori.text.Components; import net.kyori.text.TextComponent; import net.kyori.text.event.ClickEvent; import net.kyori.text.event.HoverEvent; @@ -175,12 +174,12 @@ public class VelocityCommand implements Command { .append(TextComponent.builder("Velocity website") .color(TextColor.GREEN) .clickEvent( - new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.velocitypowered.com")) + ClickEvent.openUrl("https://www.velocitypowered.com")) .build()) - .append(TextComponent.of(" or the ").resetStyle()) + .append(TextComponent.of(" or the ")) .append(TextComponent.builder("Velocity GitHub") .color(TextColor.GREEN) - .clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, + .clickEvent(ClickEvent.openUrl( "https://github.com/VelocityPowered/Velocity")) .build()) .build(); @@ -237,11 +236,11 @@ public class VelocityCommand implements Command { TextComponent.Builder hoverText = TextComponent.builder(pluginInfo); description.getUrl().ifPresent(url -> { - hoverText.append(Components.newline()); + hoverText.append(TextComponent.newline()); hoverText.append(TextComponent.of("Website: " + url)); }); if (!description.getAuthors().isEmpty()) { - hoverText.append(Components.newline()); + hoverText.append(TextComponent.newline()); if (description.getAuthors().size() == 1) { hoverText.append(TextComponent.of("Author: " + description.getAuthors().get(0))); } else { @@ -250,13 +249,13 @@ public class VelocityCommand implements Command { } } description.getDescription().ifPresent(pdesc -> { - hoverText.append(Components.newline()); - hoverText.append(Components.newline()); + hoverText.append(TextComponent.newline()); + hoverText.append(TextComponent.newline()); hoverText.append(TextComponent.of(pdesc)); }); return TextComponent.of(description.getId(), TextColor.GRAY) - .hoverEvent(new HoverEvent(Action.SHOW_TEXT, hoverText.build())); + .hoverEvent(HoverEvent.showText(hoverText.build())); } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 806ea190b..4ab5d9c84 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -22,7 +22,8 @@ import java.util.Map; import java.util.Optional; import java.util.Random; import net.kyori.text.Component; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.gson.GsonComponentSerializer; +import net.kyori.text.serializer.legacy.LegacyComponentSerializer; import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -278,9 +279,9 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi public Component getMotdComponent() { if (motdAsComponent == null) { if (motd.startsWith("{")) { - motdAsComponent = ComponentSerializers.JSON.deserialize(motd); + motdAsComponent = GsonComponentSerializer.INSTANCE.deserialize(motd); } else { - motdAsComponent = ComponentSerializers.LEGACY.deserialize(motd, '&'); + motdAsComponent = LegacyComponentSerializer.INSTANCE.deserialize(motd, '&'); } } return motdAsComponent; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 937faabb5..68bfd0798 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -58,8 +58,9 @@ import net.kyori.text.Component; import net.kyori.text.TextComponent; import net.kyori.text.TranslatableComponent; import net.kyori.text.format.TextColor; -import net.kyori.text.serializer.ComponentSerializers; -import net.kyori.text.serializer.PlainComponentSerializer; +import net.kyori.text.serializer.gson.GsonComponentSerializer; +import net.kyori.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.text.serializer.plain.PlainComponentSerializer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @@ -190,18 +191,18 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { // We can use the title packet instead. TitlePacket pkt = new TitlePacket(); pkt.setAction(TitlePacket.SET_ACTION_BAR); - pkt.setComponent(ComponentSerializers.JSON.serialize(component)); + pkt.setComponent(GsonComponentSerializer.INSTANCE.serialize(component)); minecraftConnection.write(pkt); return; } else { // Due to issues with action bar packets, we'll need to convert the text message into a // legacy message and then inject the legacy text into a component... yuck! JsonObject object = new JsonObject(); - object.addProperty("text", ComponentSerializers.LEGACY.serialize(component)); + object.addProperty("text", LegacyComponentSerializer.INSTANCE.serialize(component)); json = object.toString(); } } else { - json = ComponentSerializers.JSON.serialize(component); + json = GsonComponentSerializer.INSTANCE.serialize(component); } Chat chat = new Chat(); @@ -242,7 +243,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { @Override public void disconnect(Component reason) { - logger.info("{} has disconnected: {}", this, ComponentSerializers.LEGACY.serialize(reason)); + logger.info("{} has disconnected: {}", this, + LegacyComponentSerializer.INSTANCE.serialize(reason)); minecraftConnection.closeWith(Disconnect.create(reason)); } @@ -266,7 +268,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { if (titleText.isPresent()) { TitlePacket titlePkt = new TitlePacket(); titlePkt.setAction(TitlePacket.SET_TITLE); - titlePkt.setComponent(ComponentSerializers.JSON.serialize(titleText.get())); + titlePkt.setComponent(GsonComponentSerializer.INSTANCE.serialize(titleText.get())); minecraftConnection.delayedWrite(titlePkt); } @@ -274,7 +276,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { if (subtitleText.isPresent()) { TitlePacket titlePkt = new TitlePacket(); titlePkt.setAction(TitlePacket.SET_SUBTITLE); - titlePkt.setComponent(ComponentSerializers.JSON.serialize(subtitleText.get())); + titlePkt.setComponent(GsonComponentSerializer.INSTANCE.serialize(subtitleText.get())); minecraftConnection.delayedWrite(titlePkt); } @@ -354,7 +356,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return; } - Component disconnectReason = ComponentSerializers.JSON.deserialize(disconnect.getReason()); + Component disconnectReason = GsonComponentSerializer.INSTANCE.deserialize( + disconnect.getReason()); String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason); if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) { logger.error("{}: kicked from server {}: {}", this, server.getServerInfo().getName(), diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java index fe6b53e3c..05a8b7b13 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java @@ -9,7 +9,7 @@ import com.velocitypowered.proxy.protocol.packet.Handshake; import java.net.InetSocketAddress; import java.util.Optional; import net.kyori.text.Component; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.legacy.LegacyComponentSerializer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -54,7 +54,8 @@ class InitialInboundConnection implements InboundConnection, MinecraftConnection } public void disconnect(Component reason) { - logger.info("{} has disconnected: {}", this, ComponentSerializers.LEGACY.serialize(reason)); + logger.info("{} has disconnected: {}", this, + LegacyComponentSerializer.INSTANCE.serialize(reason)); connection.closeWith(Disconnect.create(reason)); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java index 60bdcc995..2c3061ad1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java @@ -8,7 +8,7 @@ import com.velocitypowered.proxy.protocol.packet.Disconnect; import java.util.Optional; import javax.annotation.Nullable; import net.kyori.text.Component; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.gson.GsonComponentSerializer; public class ConnectionRequestResults { @@ -43,12 +43,12 @@ public class ConnectionRequestResults { } public static Impl forDisconnect(Disconnect disconnect, RegisteredServer server) { - Component deserialized = ComponentSerializers.JSON.deserialize(disconnect.getReason()); + Component deserialized = GsonComponentSerializer.INSTANCE.deserialize(disconnect.getReason()); return forDisconnect(deserialized, server); } public static Impl forUnsafeDisconnect(Disconnect disconnect, RegisteredServer server) { - Component deserialized = ComponentSerializers.JSON.deserialize(disconnect.getReason()); + Component deserialized = GsonComponentSerializer.INSTANCE.deserialize(disconnect.getReason()); return new Impl(Status.SERVER_DISCONNECTED, deserialized, server, false); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java index cb620eaaf..d31af224a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java @@ -11,7 +11,7 @@ import java.util.List; import net.kyori.text.Component; import net.kyori.text.TextComponent; import net.kyori.text.format.TextColor; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.legacy.LegacyComponentSerializer; import net.minecrell.terminalconsole.SimpleTerminalConsole; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; @@ -35,7 +35,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons @Override public void sendMessage(Component component) { - logger.info(ComponentSerializers.LEGACY.serialize(component)); + logger.info(LegacyComponentSerializer.INSTANCE.serialize(component)); } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java index ca4c6a119..8bcda72de 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java @@ -27,7 +27,7 @@ import java.util.Set; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.plain.PlainComponentSerializer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @@ -71,7 +71,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler private QueryResponse createInitialResponse() { return QueryResponse.builder() - .hostname(ComponentSerializers.PLAIN + .hostname(PlainComponentSerializer.INSTANCE .serialize(server.getConfiguration().getMotdComponent())) .gameVersion(ProtocolVersion.SUPPORTED_VERSION_STRING) .map(server.getConfiguration().getQueryMap()) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java index 92723d456..c4761a667 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java @@ -7,7 +7,7 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import net.kyori.text.Component; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.gson.GsonComponentSerializer; import org.checkerframework.checker.nullness.qual.Nullable; public class Chat implements MinecraftPacket { @@ -83,7 +83,7 @@ public class Chat implements MinecraftPacket { public static Chat createClientbound(Component component, byte type) { Preconditions.checkNotNull(component, "component"); - return new Chat(ComponentSerializers.JSON.serialize(component), type); + return new Chat(GsonComponentSerializer.INSTANCE.serialize(component), type); } public static Chat createServerbound(String message) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java index f7adb2b28..c3ece521e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java @@ -7,7 +7,7 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import net.kyori.text.Component; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.gson.GsonComponentSerializer; import org.checkerframework.checker.nullness.qual.Nullable; public class Disconnect implements MinecraftPacket { @@ -59,6 +59,6 @@ public class Disconnect implements MinecraftPacket { public static Disconnect create(Component component) { Preconditions.checkNotNull(component, "component"); - return new Disconnect(ComponentSerializers.JSON.serialize(component)); + return new Disconnect(GsonComponentSerializer.INSTANCE.serialize(component)); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java index cd1fa56d3..177d3a19d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HeaderAndFooter.java @@ -10,7 +10,7 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import net.kyori.text.Component; import net.kyori.text.serializer.ComponentSerializer; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.gson.GsonComponentSerializer; public class HeaderAndFooter implements MinecraftPacket { @@ -54,7 +54,7 @@ public class HeaderAndFooter implements MinecraftPacket { } public static HeaderAndFooter create(Component header, Component footer) { - ComponentSerializer json = ComponentSerializers.JSON; + ComponentSerializer json = GsonComponentSerializer.INSTANCE; return new HeaderAndFooter(json.serialize(header), json.serialize(footer)); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyDisconnect.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyDisconnect.java index 5edf23f50..864b7c048 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyDisconnect.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyDisconnect.java @@ -1,14 +1,12 @@ package com.velocitypowered.proxy.protocol.packet; -import static net.kyori.text.serializer.ComponentSerializers.LEGACY; -import static net.kyori.text.serializer.ComponentSerializers.PLAIN; - import com.google.common.collect.ImmutableList; import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing.Players; import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion; import net.kyori.text.TextComponent; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.text.serializer.plain.PlainComponentSerializer; public class LegacyDisconnect { @@ -39,7 +37,7 @@ public class LegacyDisconnect { // remove all section symbols, along with fetching just the first line of an (unformatted) // MOTD. return new LegacyDisconnect(String.join(LEGACY_COLOR_CODE, - cleanSectionSymbol(getFirstLine(PLAIN.serialize(response.getDescription()))), + cleanSectionSymbol(getFirstLine(PlainComponentSerializer.INSTANCE.serialize(response.getDescription()))), Integer.toString(players.getOnline()), Integer.toString(players.getMax()))); case MINECRAFT_1_4: @@ -49,7 +47,7 @@ public class LegacyDisconnect { LEGACY_COLOR_CODE + "1", Integer.toString(response.getVersion().getProtocol()), response.getVersion().getName(), - getFirstLine(LEGACY.serialize(response.getDescription())), + getFirstLine(LegacyComponentSerializer.INSTANCE.serialize(response.getDescription())), Integer.toString(players.getOnline()), Integer.toString(players.getMax()) )); @@ -75,7 +73,7 @@ public class LegacyDisconnect { public static LegacyDisconnect from(TextComponent component) { // We intentionally use the legacy serializers, because the old clients can't understand JSON. @SuppressWarnings("deprecation") - String serialized = ComponentSerializers.LEGACY.serialize(component); + String serialized = LegacyComponentSerializer.INSTANCE.serialize(component); return new LegacyDisconnect(serialized); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java index 618c5e344..4c31d92a4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java @@ -12,7 +12,7 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; import net.kyori.text.Component; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.gson.GsonComponentSerializer; import org.checkerframework.checker.nullness.qual.Nullable; public class PlayerListItem implements MinecraftPacket { @@ -77,7 +77,7 @@ public class PlayerListItem implements MinecraftPacket { private static @Nullable Component readOptionalComponent(ByteBuf buf) { if (buf.readBoolean()) { - return ComponentSerializers.JSON.deserialize(ProtocolUtils.readString(buf)); + return GsonComponentSerializer.INSTANCE.deserialize(ProtocolUtils.readString(buf)); } return null; } @@ -123,7 +123,7 @@ public class PlayerListItem implements MinecraftPacket { private void writeDisplayName(ByteBuf buf, @Nullable Component displayName) { buf.writeBoolean(displayName != null); if (displayName != null) { - ProtocolUtils.writeString(buf, ComponentSerializers.JSON.serialize(displayName)); + ProtocolUtils.writeString(buf, GsonComponentSerializer.INSTANCE.serialize(displayName)); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java index 4523d5cbf..c6db498d2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/TabCompleteResponse.java @@ -11,7 +11,7 @@ import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; import net.kyori.text.Component; -import net.kyori.text.serializer.ComponentSerializers; +import net.kyori.text.serializer.gson.GsonComponentSerializer; import org.checkerframework.checker.nullness.qual.Nullable; public class TabCompleteResponse implements MinecraftPacket { @@ -68,7 +68,7 @@ public class TabCompleteResponse implements MinecraftPacket { int offersAvailable = ProtocolUtils.readVarInt(buf); for (int i = 0; i < offersAvailable; i++) { String offer = ProtocolUtils.readString(buf); - Component tooltip = buf.readBoolean() ? ComponentSerializers.JSON.deserialize( + Component tooltip = buf.readBoolean() ? GsonComponentSerializer.INSTANCE.deserialize( ProtocolUtils.readString(buf)) : null; offers.add(new Offer(offer, tooltip)); } @@ -91,7 +91,7 @@ public class TabCompleteResponse implements MinecraftPacket { ProtocolUtils.writeString(buf, offer.text); buf.writeBoolean(offer.tooltip != null); if (offer.tooltip != null) { - ProtocolUtils.writeString(buf, ComponentSerializers.JSON.serialize(offer.tooltip)); + ProtocolUtils.writeString(buf, GsonComponentSerializer.INSTANCE.serialize(offer.tooltip)); } } } else {