From eabff2020fa50e1972dca22b24ba18cca4e9e007 Mon Sep 17 00:00:00 2001 From: Aaron <71191102+RealBauHD@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:10:30 +0100 Subject: [PATCH] fix legacy console disconnect messages (#1197) --- .../proxy/connection/client/ConnectedPlayer.java | 8 +++----- .../connection/client/InitialInboundConnection.java | 10 ++++------ 2 files changed, 7 insertions(+), 11 deletions(-) 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 e531c2101..9cbc9ac37 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 @@ -103,13 +103,12 @@ 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.format.NamedTextColor; +import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; 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; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -126,7 +125,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, PlainTextComponentSerializer.builder().flattener(TranslatableMapper.FLATTENER).build(); static final PermissionProvider DEFAULT_PERMISSIONS = s -> PermissionFunction.ALWAYS_UNDEFINED; - private static final Logger logger = LogManager.getLogger(ConnectedPlayer.class); + private static final ComponentLogger logger = ComponentLogger.logger(ConnectedPlayer.class); private final Identity identity = new IdentityImpl(); /** @@ -577,8 +576,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, Component translated = this.translateMessage(reason); if (server.getConfiguration().isLogPlayerConnections()) { - logger.info("{} has disconnected: {}", this, - LegacyComponentSerializer.legacySection().serialize(translated)); + logger.info(Component.text(this + " has disconnected: ").append(translated)); } connection.closeWith(Disconnect.create(translated, this.getProtocolVersion(), duringLogin)); } 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 5a67dab30..d0fde45b3 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 @@ -29,10 +29,8 @@ import java.net.InetSocketAddress; import java.util.Locale; import java.util.Optional; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import net.kyori.adventure.translation.GlobalTranslator; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; /** * Implements {@link InboundConnection} for a newly-established connection. @@ -40,7 +38,8 @@ import org.apache.logging.log4j.Logger; public final class InitialInboundConnection implements VelocityInboundConnection, MinecraftConnectionAssociation { - private static final Logger logger = LogManager.getLogger(InitialInboundConnection.class); + private static final ComponentLogger logger = ComponentLogger + .logger(InitialInboundConnection.class); private final MinecraftConnection connection; private final String cleanedAddress; @@ -97,8 +96,7 @@ public final class InitialInboundConnection implements VelocityInboundConnection Component translated = GlobalTranslator.render(reason, ClosestLocaleMatcher.INSTANCE .lookupClosest(Locale.getDefault())); if (connection.server.getConfiguration().isLogPlayerConnections()) { - logger.info("{} has disconnected: {}", this, - LegacyComponentSerializer.legacySection().serialize(translated)); + logger.info(Component.text(this + " has disconnected: ").append(translated)); } connection.closeWith(Disconnect.create(translated, getProtocolVersion(), true)); }