From 9fc4341f40755a5649f276537897662d824bc292 Mon Sep 17 00:00:00 2001 From: 4drian3d <68704415+4drian3d@users.noreply.github.com> Date: Thu, 31 Mar 2022 21:09:44 -0500 Subject: [PATCH] Replacement of some deprecated method (#672) - PlainComponentSerializer -> PlainTextComponentSerializer - BinaryTagHolder#of -> BinaryTagHolder#binaryTagHolder --- .../com/velocitypowered/api/event/ResultedEvent.java | 5 +++-- .../com/velocitypowered/proxy/VelocityServer.java | 2 +- .../proxy/connection/client/ConnectedPlayer.java | 12 +++++++++--- .../proxy/protocol/netty/GS4QueryHandler.java | 5 +++-- .../proxy/protocol/packet/LegacyDisconnect.java | 4 ++-- .../util/VelocityLegacyHoverEventSerializer.java | 8 ++++---- 6 files changed, 22 insertions(+), 14 deletions(-) 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 f55296c35..05813dcaf 100644 --- a/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java @@ -10,7 +10,8 @@ package com.velocitypowered.api.event; import com.google.common.base.Preconditions; import java.util.Optional; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; + import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -109,7 +110,7 @@ public interface ResultedEvent { return "allowed"; } if (reason != null) { - return "denied: " + PlainComponentSerializer.plain().serialize(reason); + return "denied: " + PlainTextComponentSerializer.plainText().serialize(reason); } return "denied"; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index bfed890ac..d00af4e91 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -282,7 +282,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { logger.error("Encountered an I/O error whilst loading translations", e); return; } - GlobalTranslator.get().addSource(translationRegistry); + GlobalTranslator.translator().addSource(translationRegistry); } @SuppressFBWarnings("DM_EXIT") 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 3fb828ef4..4d945e1ad 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 @@ -92,11 +92,13 @@ import net.kyori.adventure.platform.facet.FacetPointers; import net.kyori.adventure.platform.facet.FacetPointers.Type; import net.kyori.adventure.pointer.Pointers; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.KeybindComponent; import net.kyori.adventure.text.TranslatableComponent; +import net.kyori.adventure.text.flattener.ComponentFlattener; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.title.Title.Times; import net.kyori.adventure.title.TitlePart; import net.kyori.adventure.translation.GlobalTranslator; @@ -110,8 +112,12 @@ import org.jetbrains.annotations.NotNull; public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { private static final int MAX_PLUGIN_CHANNELS = 1024; - private static final PlainComponentSerializer PASS_THRU_TRANSLATE = new PlainComponentSerializer( - c -> "", TranslatableComponent::key); + private static final PlainTextComponentSerializer PASS_THRU_TRANSLATE = PlainTextComponentSerializer.builder() + .flattener(ComponentFlattener.basic().toBuilder() + .mapper(KeybindComponent.class, c -> "") + .mapper(TranslatableComponent.class, TranslatableComponent::key) + .build()) + .build(); static final PermissionProvider DEFAULT_PERMISSIONS = s -> PermissionFunction.ALWAYS_UNDEFINED; private static final Logger logger = LogManager.getLogger(ConnectedPlayer.class); 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 ff4a63b24..2d92af3f2 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 @@ -45,7 +45,8 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; + import org.apache.logging.log4j.LogManager; public class GS4QueryHandler extends SimpleChannelInboundHandler { @@ -83,7 +84,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler private QueryResponse createInitialResponse() { return QueryResponse.builder() - .hostname(PlainComponentSerializer.plain().serialize(server.getConfiguration().getMotd())) + .hostname(PlainTextComponentSerializer.plainText().serialize(server.getConfiguration().getMotd())) .gameVersion(ProtocolVersion.SUPPORTED_VERSION_STRING) .map(server.getConfiguration().getQueryMap()) .currentPlayers(server.getPlayerCount()) 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 caf6150e6..285918bdd 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 @@ -23,7 +23,7 @@ import com.velocitypowered.api.proxy.server.ServerPing.Players; import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; public class LegacyDisconnect { @@ -54,7 +54,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(PlainComponentSerializer.plain().serialize( + cleanSectionSymbol(getFirstLine(PlainTextComponentSerializer.plainText().serialize( response.getDescriptionComponent()))), Integer.toString(players.getOnline()), Integer.toString(players.getMax()))); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/VelocityLegacyHoverEventSerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/VelocityLegacyHoverEventSerializer.java index 9d706d3d7..07e2dec38 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/VelocityLegacyHoverEventSerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/VelocityLegacyHoverEventSerializer.java @@ -29,7 +29,7 @@ import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.event.HoverEvent.ShowEntity; import net.kyori.adventure.text.event.HoverEvent.ShowItem; import net.kyori.adventure.text.serializer.gson.LegacyHoverEventSerializer; -import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.util.Codec.Decoder; import net.kyori.adventure.util.Codec.Encoder; import org.checkerframework.checker.nullness.qual.NonNull; @@ -54,7 +54,7 @@ public class VelocityLegacyHoverEventSerializer implements LegacyHoverEventSeria @Override public HoverEvent.@NonNull ShowItem deserializeShowItem(@NonNull Component input) throws IOException { - String snbt = PlainComponentSerializer.plain().serialize(input); + String snbt = PlainTextComponentSerializer.plainText().serialize(input); CompoundBinaryTag item = TagStringIO.get().asCompound(snbt); Key key; @@ -66,13 +66,13 @@ public class VelocityLegacyHoverEventSerializer implements LegacyHoverEventSeria } byte count = item.getByte("Count", (byte) 1); - return ShowItem.of(key, count, BinaryTagHolder.of(snbt)); + return ShowItem.of(key, count, BinaryTagHolder.binaryTagHolder(snbt)); } @Override public HoverEvent.@NonNull ShowEntity deserializeShowEntity(@NonNull Component input, Decoder componentDecoder) throws IOException { - String snbt = PlainComponentSerializer.plain().serialize(input); + String snbt = PlainTextComponentSerializer.plainText().serialize(input); CompoundBinaryTag item = TagStringIO.get().asCompound(snbt); Component name;