From 5285a3c155b3404a45e52a2d4d1ae88dcc0e2b3d Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 29 Jun 2020 23:34:59 -0400 Subject: [PATCH] Remove AdventureCompact in favor of the text 3.x serializer added in KyoriPowered/adventure-platform#23 --- api/build.gradle | 1 + .../api/command/CommandSource.java | 4 +- .../api/event/ResultedEvent.java | 7 ++-- .../api/event/connection/PreLoginEvent.java | 8 ++-- .../event/player/KickedFromServerEvent.java | 20 ++++----- .../api/proxy/player/TabListEntry.java | 4 +- .../api/proxy/server/ServerPing.java | 13 +++--- .../api/util/AdventureCompat.java | 41 ------------------- .../proxy/config/VelocityConfiguration.java | 4 +- .../util/ConnectionRequestResults.java | 4 +- .../proxy/tablist/VelocityTabListEntry.java | 9 ++-- 11 files changed, 40 insertions(+), 75 deletions(-) delete mode 100644 api/src/main/java/com/velocitypowered/api/util/AdventureCompat.java diff --git a/api/build.gradle b/api/build.gradle index b6dff0da7..3b8fa7c37 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -32,6 +32,7 @@ dependencies { compile "net.kyori:adventure-text-serializer-gson:${adventureVersion}" compile "net.kyori:adventure-text-serializer-legacy:${adventureVersion}" compile "net.kyori:adventure-text-serializer-plain:${adventureVersion}" + compile "net.kyori:adventure-text-serializer-legacy-text3:${adventureVersion}" compile "org.slf4j:slf4j-api:${slf4jVersion}" compile 'com.google.inject:guice:4.2.3' diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandSource.java b/api/src/main/java/com/velocitypowered/api/command/CommandSource.java index 63fa4bee4..d2862d404 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandSource.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandSource.java @@ -2,8 +2,8 @@ package com.velocitypowered.api.command; import com.velocitypowered.api.permission.PermissionSubject; import com.velocitypowered.api.proxy.ProxyAudience; -import com.velocitypowered.api.util.AdventureCompat; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer; import org.checkerframework.checker.nullness.qual.NonNull; /** @@ -22,6 +22,6 @@ public interface CommandSource extends PermissionSubject, ProxyAudience { @Override default void sendMessage(@NonNull Component message) { - this.sendMessage(AdventureCompat.asOriginalTextComponent(message)); + this.sendMessage(LegacyText3ComponentSerializer.get().serialize(message)); } } 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 2785d3eee..66bd15a69 100644 --- a/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java @@ -1,9 +1,9 @@ package com.velocitypowered.api.event; import com.google.common.base.Preconditions; -import com.velocitypowered.api.util.AdventureCompat; import java.util.Optional; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; import org.checkerframework.checker.nullness.qual.Nullable; @@ -95,7 +95,7 @@ public interface ResultedEvent { @Deprecated public Optional getReason() { - return Optional.ofNullable(reason).map(AdventureCompat::asOriginalTextComponent); + return Optional.ofNullable(reason).map(LegacyText3ComponentSerializer.get()::serialize); } public Optional getReasonComponent() { @@ -125,7 +125,8 @@ public interface ResultedEvent { @Deprecated public static ComponentResult denied(net.kyori.text.Component reason) { Preconditions.checkNotNull(reason, "reason"); - return new ComponentResult(false, AdventureCompat.asAdventureComponent(reason)); + return new ComponentResult(false, LegacyText3ComponentSerializer.get() + .deserialize(reason)); } } } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/PreLoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/PreLoginEvent.java index aa714bfdb..018e4f2fb 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/PreLoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/PreLoginEvent.java @@ -3,8 +3,8 @@ package com.velocitypowered.api.event.connection; import com.google.common.base.Preconditions; import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.proxy.InboundConnection; -import com.velocitypowered.api.util.AdventureCompat; import java.util.Optional; +import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -86,7 +86,7 @@ public final class PreLoginEvent implements ResultedEvent getReason() { - return Optional.ofNullable(reason).map(AdventureCompat::asOriginalTextComponent); + return Optional.ofNullable(reason).map(LegacyText3ComponentSerializer.get()::serialize); } public Optional getReasonComponent() { @@ -155,8 +155,8 @@ public final class PreLoginEvent implements ResultedEvent getOriginalReason() { - return Optional.ofNullable(originalReason).map(AdventureCompat::asOriginalTextComponent); + return Optional.ofNullable(originalReason).map(LegacyText3ComponentSerializer.get()::serialize); } public Optional getServerKickReason() { @@ -150,7 +150,7 @@ public final class KickedFromServerEvent implements @Deprecated public Component getReason() { - return AdventureCompat.asOriginalTextComponent(component); + return LegacyText3ComponentSerializer.get().serialize(component); } public net.kyori.adventure.text.Component getReasonComponent() { @@ -166,7 +166,7 @@ public final class KickedFromServerEvent implements */ @Deprecated public static DisconnectPlayer create(Component reason) { - return new DisconnectPlayer(AdventureCompat.asAdventureComponent(reason)); + return new DisconnectPlayer(LegacyText3ComponentSerializer.get().deserialize(reason)); } /** @@ -206,7 +206,7 @@ public final class KickedFromServerEvent implements @Deprecated public Component getMessage() { - return AdventureCompat.asOriginalTextComponent(message); + return LegacyText3ComponentSerializer.get().serialize(message); } public net.kyori.adventure.text.Component getMessageComponent() { @@ -225,7 +225,7 @@ public final class KickedFromServerEvent implements if (message == null) { return new RedirectPlayer(server, null); } - return new RedirectPlayer(server, AdventureCompat.asAdventureComponent(message)); + return new RedirectPlayer(server, LegacyText3ComponentSerializer.get().deserialize(message)); } /** @@ -264,7 +264,7 @@ public final class KickedFromServerEvent implements @Deprecated public Component getMessage() { - return AdventureCompat.asOriginalTextComponent(message); + return LegacyText3ComponentSerializer.get().serialize(message); } @Deprecated @@ -281,7 +281,7 @@ public final class KickedFromServerEvent implements */ @Deprecated public static Notify create(Component message) { - return new Notify(AdventureCompat.asAdventureComponent(message)); + return new Notify(LegacyText3ComponentSerializer.get().deserialize(message)); } /** diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java b/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java index 5b0ba7549..0ae4f574f 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java @@ -1,9 +1,9 @@ package com.velocitypowered.api.proxy.player; -import com.velocitypowered.api.util.AdventureCompat; import com.velocitypowered.api.util.GameProfile; import java.util.Optional; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -179,7 +179,7 @@ public interface TabListEntry { */ @Deprecated public Builder displayName(net.kyori.text.Component displayName) { - return displayName(AdventureCompat.asAdventureComponent(displayName)); + return displayName(LegacyText3ComponentSerializer.get().deserialize(displayName)); } /** diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java index f1a7ccd66..f1979d491 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java @@ -3,7 +3,6 @@ package com.velocitypowered.api.proxy.server; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import com.velocitypowered.api.util.AdventureCompat; import com.velocitypowered.api.util.Favicon; import com.velocitypowered.api.util.ModInfo; import java.util.ArrayList; @@ -13,6 +12,7 @@ import java.util.Objects; import java.util.Optional; import java.util.UUID; +import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -29,7 +29,7 @@ public final class ServerPing { @Deprecated public ServerPing(Version version, @Nullable Players players, net.kyori.text.Component description, @Nullable Favicon favicon) { - this(version, players, AdventureCompat.asAdventureComponent(description), favicon, + this(version, players, LegacyText3ComponentSerializer.get().deserialize(description), favicon, ModInfo.DEFAULT); } @@ -51,7 +51,8 @@ public final class ServerPing { public ServerPing(Version version, @Nullable Players players, net.kyori.text.Component description, @Nullable Favicon favicon, @Nullable ModInfo modinfo) { - this(version, players, AdventureCompat.asAdventureComponent(description), favicon, modinfo); + this(version, players, LegacyText3ComponentSerializer.get().deserialize(description), favicon, + modinfo); } /** @@ -83,7 +84,7 @@ public final class ServerPing { @Deprecated public net.kyori.text.Component getDescription() { - return AdventureCompat.asOriginalTextComponent(description); + return LegacyText3ComponentSerializer.get().serialize(description); } public net.kyori.adventure.text.Component getDescriptionComponent() { @@ -246,7 +247,7 @@ public final class ServerPing { @Deprecated public Builder description(net.kyori.text.Component description) { - this.description(AdventureCompat.asAdventureComponent(description)); + this.description(LegacyText3ComponentSerializer.get().deserialize(description)); return this; } @@ -295,7 +296,7 @@ public final class ServerPing { @Deprecated public Optional getDescription() { - return Optional.ofNullable(description).map(AdventureCompat::asOriginalTextComponent); + return Optional.ofNullable(description).map(LegacyText3ComponentSerializer.get()::serialize); } public Optional getDescriptionComponent() { diff --git a/api/src/main/java/com/velocitypowered/api/util/AdventureCompat.java b/api/src/main/java/com/velocitypowered/api/util/AdventureCompat.java deleted file mode 100644 index 85d6d338a..000000000 --- a/api/src/main/java/com/velocitypowered/api/util/AdventureCompat.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.velocitypowered.api.util; - -/** - * Utilities to convert from adventure {@link net.kyori.adventure.text.Component}s to text - * {@link net.kyori.text.Component}s and vice versa. - * - * @deprecated Provided only as a transitional aid, will be removed in Velocity 2.0.0 - */ -@Deprecated -public class AdventureCompat { - private AdventureCompat() { - throw new AssertionError("Do not create instances of this class."); - } - - /** - * Converts an {@link net.kyori.text.Component} component into an adventure - * {@link net.kyori.adventure.text.Component} component. - * @param component the component to translate - * @return the translated component - */ - public static net.kyori.adventure.text.Component asAdventureComponent( - net.kyori.text.Component component) { - String json = net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE - .serialize(component); - return net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson() - .deserialize(json); - } - - /** - * Converts an {@link net.kyori.adventure.text.Component} component into an text - * {@link net.kyori.text.Component} component. - * @param component the component to translate - * @return the translated component - */ - public static net.kyori.text.Component asOriginalTextComponent( - net.kyori.adventure.text.Component component) { - String json = net.kyori.adventure.text.serializer.gson.GsonComponentSerializer - .colorDownsamplingGson().serialize(component); - return net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE.deserialize(json); - } -} 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 076eecb47..32f5ca918 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -7,7 +7,6 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.velocitypowered.api.proxy.config.ProxyConfig; -import com.velocitypowered.api.util.AdventureCompat; import com.velocitypowered.api.util.Favicon; import com.velocitypowered.proxy.util.AddressUtil; import java.io.IOException; @@ -25,6 +24,7 @@ import java.util.Random; import java.util.UUID; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @@ -230,7 +230,7 @@ public class VelocityConfiguration implements ProxyConfig { */ @Override public net.kyori.text.Component getMotdComponent() { - return AdventureCompat.asOriginalTextComponent(this.getMotd()); + return LegacyText3ComponentSerializer.get().serialize(this.getMotd()); } @Override 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 307f97fa7..ce97458db 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 @@ -3,12 +3,12 @@ package com.velocitypowered.proxy.connection.util; import com.velocitypowered.api.proxy.ConnectionRequestBuilder; import com.velocitypowered.api.proxy.ConnectionRequestBuilder.Status; import com.velocitypowered.api.proxy.server.RegisteredServer; -import com.velocitypowered.api.util.AdventureCompat; import com.velocitypowered.proxy.protocol.packet.Disconnect; import java.util.Optional; import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer; public class ConnectionRequestResults { @@ -74,7 +74,7 @@ public class ConnectionRequestResults { @Override public Optional getReason() { - return Optional.ofNullable(component).map(AdventureCompat::asOriginalTextComponent); + return Optional.ofNullable(component).map(LegacyText3ComponentSerializer.get()::serialize); } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java index 86ceddfff..c9208284f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java @@ -2,10 +2,10 @@ package com.velocitypowered.proxy.tablist; import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.api.proxy.player.TabListEntry; -import com.velocitypowered.api.util.AdventureCompat; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.proxy.protocol.packet.PlayerListItem; import java.util.Optional; +import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer; import net.kyori.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; @@ -38,7 +38,7 @@ public class VelocityTabListEntry implements TabListEntry { @Override public Optional getDisplayName() { - return Optional.ofNullable(displayName).map(AdventureCompat::asOriginalTextComponent); + return Optional.ofNullable(displayName).map(LegacyText3ComponentSerializer.get()::serialize); } @Override @@ -48,7 +48,10 @@ public class VelocityTabListEntry implements TabListEntry { @Override public TabListEntry setDisplayName(@Nullable Component displayName) { - return this.setDisplayName(AdventureCompat.asAdventureComponent(displayName)); + if (displayName == null) { + return this.setDisplayName((net.kyori.adventure.text.Component) null); + } + return this.setDisplayName(LegacyText3ComponentSerializer.get().deserialize(displayName)); } @Override