13
0
geforkt von Mirrors/Velocity

Upgrade text to 1.12-1.6.0-SNAPSHOT for plain text serializer

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-07-27 15:01:00 -04:00
Ursprung 44f9687cfa
Commit 247dafd9de
4 geänderte Dateien mit 11 neuen und 65 gelöschten Zeilen

Datei anzeigen

@ -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'

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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);
}
}
}

Datei anzeigen

@ -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));
}
}