From 247dafd9de22d903fd57f62e93a9899a4f113b9c Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 27 Jul 2018 15:01:00 -0400 Subject: [PATCH] Upgrade text to 1.12-1.6.0-SNAPSHOT for plain text serializer --- build.gradle | 5 ++- .../connection/client/ConnectedPlayer.java | 11 ++++--- .../proxy/util/ComponentUtils.java | 29 ----------------- .../proxy/util/ComponentUtilsTest.java | 31 ------------------- 4 files changed, 11 insertions(+), 65 deletions(-) delete mode 100644 src/main/java/com/velocitypowered/proxy/util/ComponentUtils.java delete mode 100644 src/test/java/com/velocitypowered/proxy/util/ComponentUtilsTest.java diff --git a/build.gradle b/build.gradle index 9f05623cf..3e111d240 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,9 @@ targetCompatibility = 1.8 repositories { mavenLocal() mavenCentral() + maven { + url 'https://oss.sonatype.org/content/groups/public/' + } } dependencies { @@ -24,7 +27,7 @@ dependencies { compile "io.netty:netty-handler:${nettyVersion}" compile "io.netty:netty-transport-native-epoll:${nettyVersion}" compile "io.netty:netty-transport-native-epoll:${nettyVersion}:linux-x86_64" - compile 'net.kyori:text:1.12-1.5.0' + compile 'net.kyori:text:1.12-1.6.0-SNAPSHOT' compile 'org.apache.logging.log4j:log4j-api:2.11.0' compile 'org.apache.logging.log4j:log4j-core:2.11.0' compile 'com.moandjiezana.toml:toml4j:0.7.2' diff --git a/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 642625744..4a6df0651 100644 --- a/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -5,14 +5,15 @@ import com.velocitypowered.proxy.data.GameProfile; import com.velocitypowered.proxy.protocol.packets.Chat; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.backend.ServerConnection; -import com.velocitypowered.proxy.util.ComponentUtils; import com.velocitypowered.proxy.util.ThrowableUtils; import com.velocitypowered.proxy.data.ServerInfo; import com.velocitypowered.proxy.protocol.packets.Disconnect; 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 org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -20,6 +21,8 @@ import java.net.InetSocketAddress; import java.util.UUID; public class ConnectedPlayer implements MinecraftConnectionAssociation { + private static final PlainComponentSerializer PASS_THRU_TRANSLATE = new PlainComponentSerializer((c) -> "", TranslatableComponent::key); + private static final Logger logger = LogManager.getLogger(ConnectedPlayer.class); private final GameProfile profile; @@ -74,11 +77,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation { public void handleConnectionException(ServerInfo info, Disconnect disconnect) { Component disconnectReason = ComponentSerializers.JSON.deserialize(disconnect.getReason()); - String reason = ComponentUtils.asPlainText(disconnectReason); + String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason); if (connectedServer != null && connectedServer.getServerInfo().equals(info)) { - logger.error("{}: kicked from server {}: {}", this, info.getName(), reason); + logger.error("{}: kicked from server {}: {}", this, info.getName(), plainTextReason); } else { - logger.error("{}: disconnected while connecting to {}: {}", this, info.getName(), reason); + logger.error("{}: disconnected while connecting to {}: {}", this, info.getName(), plainTextReason); } handleConnectionException(info, disconnectReason); } diff --git a/src/main/java/com/velocitypowered/proxy/util/ComponentUtils.java b/src/main/java/com/velocitypowered/proxy/util/ComponentUtils.java deleted file mode 100644 index 09351cea1..000000000 --- a/src/main/java/com/velocitypowered/proxy/util/ComponentUtils.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.velocitypowered.proxy.util; - -import com.google.common.base.Preconditions; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; - -public enum ComponentUtils { - ; - - public static String asPlainText(Component component) { - Preconditions.checkNotNull(component, "component"); - StringBuilder builder = new StringBuilder(); - appendPlainText(component, builder); - return builder.toString(); - } - - private static void appendPlainText(Component component, StringBuilder builder) { - if (component instanceof TextComponent) { - builder.append(((TextComponent) component).content()); - } - if (component instanceof TranslatableComponent) { - builder.append(((TranslatableComponent) component).key()); - } - for (Component child : component.children()) { - appendPlainText(child, builder); - } - } -} diff --git a/src/test/java/com/velocitypowered/proxy/util/ComponentUtilsTest.java b/src/test/java/com/velocitypowered/proxy/util/ComponentUtilsTest.java deleted file mode 100644 index 1c314025c..000000000 --- a/src/test/java/com/velocitypowered/proxy/util/ComponentUtilsTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.velocitypowered.proxy.util; - -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; -import net.kyori.text.format.TextDecoration; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class ComponentUtilsTest { - - private static final String SIMPLE_COMPONENT_TEXT = "hello"; - private static final TextComponent SIMPLE_COMPONENT = TextComponent.of(SIMPLE_COMPONENT_TEXT, TextColor.RED); - private static final String COMPLEX_COMPONENT_TEXT = "Hello world! Welcome to Velocity, the Minecraft server proxy built for mass scale."; - private static final TextComponent COMPLEX_COMPONENT = TextComponent.builder("Hello world! ") - .decoration(TextDecoration.BOLD, true) - .append(TextComponent.of("Welcome to ")) - .decoration(TextDecoration.BOLD, false) - .color(TextColor.GREEN) - .append(TextComponent.of("Velocity")) - .color(TextColor.DARK_AQUA) - .append(TextComponent.of(", the Minecraft server proxy built for mass scale.")) - .resetStyle() - .build(); - - @Test - void asPlainText() { - assertEquals(SIMPLE_COMPONENT_TEXT, ComponentUtils.asPlainText(SIMPLE_COMPONENT)); - assertEquals(COMPLEX_COMPONENT_TEXT, ComponentUtils.asPlainText(COMPLEX_COMPONENT)); - } -} \ No newline at end of file