13
0
geforkt von Mirrors/Velocity

Bump text to 3.0.0

Dieser Commit ist enthalten in:
kashike 2019-05-06 18:44:55 -07:00
Ursprung 472f45df08
Commit 3800610f66
18 geänderte Dateien mit 63 neuen und 58 gelöschten Zeilen

Datei anzeigen

@ -18,7 +18,10 @@ sourceSets {
dependencies { dependencies {
compile 'com.google.code.gson:gson:2.8.5' compile 'com.google.code.gson:gson:2.8.5'
compile "com.google.guava:guava:${guavaVersion}" compile "com.google.guava:guava:${guavaVersion}"
compile 'net.kyori:text:1.12-1.6.5' compile "net.kyori:text-api:${textVersion}"
compile "net.kyori:text-serializer-gson:${textVersion}"
compile "net.kyori:text-serializer-legacy:${textVersion}"
compile "net.kyori:text-serializer-plain:${textVersion}"
compile 'com.moandjiezana.toml:toml4j:0.7.2' compile 'com.moandjiezana.toml:toml4j:0.7.2'
compile "org.slf4j:slf4j-api:${slf4jVersion}" compile "org.slf4j:slf4j-api:${slf4jVersion}"
compile 'com.google.inject:guice:4.2.0' compile 'com.google.inject:guice:4.2.0'

Datei anzeigen

@ -3,7 +3,7 @@ package com.velocitypowered.api.event;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import java.util.Optional; import java.util.Optional;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.plain.PlainComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
@ -102,7 +102,7 @@ public interface ResultedEvent<R extends ResultedEvent.Result> {
return "allowed"; return "allowed";
} }
if (reason != null) { if (reason != null) {
return "denied: " + ComponentSerializers.PLAIN.serialize(reason); return "denied: " + PlainComponentSerializer.INSTANCE.serialize(reason);
} }
return "denied"; return "denied";
} }

Datei anzeigen

@ -20,6 +20,7 @@ allprojects {
ext { ext {
// dependency versions // dependency versions
textVersion = '3.0.0'
junitVersion = '5.3.0-M1' junitVersion = '5.3.0-M1'
slf4jVersion = '1.7.25' slf4jVersion = '1.7.25'
log4jVersion = '2.11.2' log4jVersion = '2.11.2'

Datei anzeigen

@ -60,7 +60,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.TextComponent; import net.kyori.text.TextComponent;
import net.kyori.text.serializer.GsonComponentSerializer; import net.kyori.text.serializer.gson.GsonComponentSerializer;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull; import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
@ -70,8 +70,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
public class VelocityServer implements ProxyServer { public class VelocityServer implements ProxyServer {
private static final Logger logger = LogManager.getLogger(VelocityServer.class); private static final Logger logger = LogManager.getLogger(VelocityServer.class);
public static final Gson GSON = new GsonBuilder() public static final Gson GSON = GsonComponentSerializer.populate(new GsonBuilder())
.registerTypeHierarchyAdapter(Component.class, new GsonComponentSerializer())
.registerTypeHierarchyAdapter(Favicon.class, new FaviconSerializer()) .registerTypeHierarchyAdapter(Favicon.class, new FaviconSerializer())
.registerTypeHierarchyAdapter(GameProfile.class, new GameProfileSerializer()) .registerTypeHierarchyAdapter(GameProfile.class, new GameProfileSerializer())
.create(); .create();

Datei anzeigen

@ -62,13 +62,13 @@ public class ServerCommand implements Command {
String playersText = rs.getPlayersConnected().size() + " player(s) online"; String playersText = rs.getPlayersConnected().size() + " player(s) online";
if (rs.getServerInfo().getName().equals(currentServer)) { if (rs.getServerInfo().getName().equals(currentServer)) {
infoComponent = infoComponent.color(TextColor.GREEN) infoComponent = infoComponent.color(TextColor.GREEN)
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, .hoverEvent(HoverEvent.showText(
TextComponent.of("Currently connected to this server\n" + playersText))); TextComponent.of("Currently connected to this server\n" + playersText)));
} else { } else {
infoComponent = infoComponent.color(TextColor.GRAY) infoComponent = infoComponent.color(TextColor.GRAY)
.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, .clickEvent(ClickEvent.runCommand(
"/server " + rs.getServerInfo().getName())) "/server " + rs.getServerInfo().getName()))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, .hoverEvent(HoverEvent.showText(
TextComponent.of("Click to connect to this server\n" + playersText))); TextComponent.of("Click to connect to this server\n" + playersText)));
} }
serverListBuilder.append(infoComponent); serverListBuilder.append(infoComponent);

Datei anzeigen

@ -17,7 +17,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.kyori.text.Components;
import net.kyori.text.TextComponent; import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent; import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent; import net.kyori.text.event.HoverEvent;
@ -175,12 +174,12 @@ public class VelocityCommand implements Command {
.append(TextComponent.builder("Velocity website") .append(TextComponent.builder("Velocity website")
.color(TextColor.GREEN) .color(TextColor.GREEN)
.clickEvent( .clickEvent(
new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.velocitypowered.com")) ClickEvent.openUrl("https://www.velocitypowered.com"))
.build()) .build())
.append(TextComponent.of(" or the ").resetStyle()) .append(TextComponent.of(" or the "))
.append(TextComponent.builder("Velocity GitHub") .append(TextComponent.builder("Velocity GitHub")
.color(TextColor.GREEN) .color(TextColor.GREEN)
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, .clickEvent(ClickEvent.openUrl(
"https://github.com/VelocityPowered/Velocity")) "https://github.com/VelocityPowered/Velocity"))
.build()) .build())
.build(); .build();
@ -237,11 +236,11 @@ public class VelocityCommand implements Command {
TextComponent.Builder hoverText = TextComponent.builder(pluginInfo); TextComponent.Builder hoverText = TextComponent.builder(pluginInfo);
description.getUrl().ifPresent(url -> { description.getUrl().ifPresent(url -> {
hoverText.append(Components.newline()); hoverText.append(TextComponent.newline());
hoverText.append(TextComponent.of("Website: " + url)); hoverText.append(TextComponent.of("Website: " + url));
}); });
if (!description.getAuthors().isEmpty()) { if (!description.getAuthors().isEmpty()) {
hoverText.append(Components.newline()); hoverText.append(TextComponent.newline());
if (description.getAuthors().size() == 1) { if (description.getAuthors().size() == 1) {
hoverText.append(TextComponent.of("Author: " + description.getAuthors().get(0))); hoverText.append(TextComponent.of("Author: " + description.getAuthors().get(0)));
} else { } else {
@ -250,13 +249,13 @@ public class VelocityCommand implements Command {
} }
} }
description.getDescription().ifPresent(pdesc -> { description.getDescription().ifPresent(pdesc -> {
hoverText.append(Components.newline()); hoverText.append(TextComponent.newline());
hoverText.append(Components.newline()); hoverText.append(TextComponent.newline());
hoverText.append(TextComponent.of(pdesc)); hoverText.append(TextComponent.of(pdesc));
}); });
return TextComponent.of(description.getId(), TextColor.GRAY) return TextComponent.of(description.getId(), TextColor.GRAY)
.hoverEvent(new HoverEvent(Action.SHOW_TEXT, hoverText.build())); .hoverEvent(HoverEvent.showText(hoverText.build()));
} }
@Override @Override

Datei anzeigen

@ -22,7 +22,8 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Random; import java.util.Random;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.gson.GsonComponentSerializer;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -278,9 +279,9 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
public Component getMotdComponent() { public Component getMotdComponent() {
if (motdAsComponent == null) { if (motdAsComponent == null) {
if (motd.startsWith("{")) { if (motd.startsWith("{")) {
motdAsComponent = ComponentSerializers.JSON.deserialize(motd); motdAsComponent = GsonComponentSerializer.INSTANCE.deserialize(motd);
} else { } else {
motdAsComponent = ComponentSerializers.LEGACY.deserialize(motd, '&'); motdAsComponent = LegacyComponentSerializer.INSTANCE.deserialize(motd, '&');
} }
} }
return motdAsComponent; return motdAsComponent;

Datei anzeigen

@ -58,8 +58,9 @@ import net.kyori.text.Component;
import net.kyori.text.TextComponent; import net.kyori.text.TextComponent;
import net.kyori.text.TranslatableComponent; import net.kyori.text.TranslatableComponent;
import net.kyori.text.format.TextColor; import net.kyori.text.format.TextColor;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.gson.GsonComponentSerializer;
import net.kyori.text.serializer.PlainComponentSerializer; import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.text.serializer.plain.PlainComponentSerializer;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@ -190,18 +191,18 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
// We can use the title packet instead. // We can use the title packet instead.
TitlePacket pkt = new TitlePacket(); TitlePacket pkt = new TitlePacket();
pkt.setAction(TitlePacket.SET_ACTION_BAR); pkt.setAction(TitlePacket.SET_ACTION_BAR);
pkt.setComponent(ComponentSerializers.JSON.serialize(component)); pkt.setComponent(GsonComponentSerializer.INSTANCE.serialize(component));
minecraftConnection.write(pkt); minecraftConnection.write(pkt);
return; return;
} else { } else {
// Due to issues with action bar packets, we'll need to convert the text message into a // Due to issues with action bar packets, we'll need to convert the text message into a
// legacy message and then inject the legacy text into a component... yuck! // legacy message and then inject the legacy text into a component... yuck!
JsonObject object = new JsonObject(); JsonObject object = new JsonObject();
object.addProperty("text", ComponentSerializers.LEGACY.serialize(component)); object.addProperty("text", LegacyComponentSerializer.INSTANCE.serialize(component));
json = object.toString(); json = object.toString();
} }
} else { } else {
json = ComponentSerializers.JSON.serialize(component); json = GsonComponentSerializer.INSTANCE.serialize(component);
} }
Chat chat = new Chat(); Chat chat = new Chat();
@ -242,7 +243,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
@Override @Override
public void disconnect(Component reason) { public void disconnect(Component reason) {
logger.info("{} has disconnected: {}", this, ComponentSerializers.LEGACY.serialize(reason)); logger.info("{} has disconnected: {}", this,
LegacyComponentSerializer.INSTANCE.serialize(reason));
minecraftConnection.closeWith(Disconnect.create(reason)); minecraftConnection.closeWith(Disconnect.create(reason));
} }
@ -266,7 +268,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
if (titleText.isPresent()) { if (titleText.isPresent()) {
TitlePacket titlePkt = new TitlePacket(); TitlePacket titlePkt = new TitlePacket();
titlePkt.setAction(TitlePacket.SET_TITLE); titlePkt.setAction(TitlePacket.SET_TITLE);
titlePkt.setComponent(ComponentSerializers.JSON.serialize(titleText.get())); titlePkt.setComponent(GsonComponentSerializer.INSTANCE.serialize(titleText.get()));
minecraftConnection.delayedWrite(titlePkt); minecraftConnection.delayedWrite(titlePkt);
} }
@ -274,7 +276,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
if (subtitleText.isPresent()) { if (subtitleText.isPresent()) {
TitlePacket titlePkt = new TitlePacket(); TitlePacket titlePkt = new TitlePacket();
titlePkt.setAction(TitlePacket.SET_SUBTITLE); titlePkt.setAction(TitlePacket.SET_SUBTITLE);
titlePkt.setComponent(ComponentSerializers.JSON.serialize(subtitleText.get())); titlePkt.setComponent(GsonComponentSerializer.INSTANCE.serialize(subtitleText.get()));
minecraftConnection.delayedWrite(titlePkt); minecraftConnection.delayedWrite(titlePkt);
} }
@ -354,7 +356,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return; return;
} }
Component disconnectReason = ComponentSerializers.JSON.deserialize(disconnect.getReason()); Component disconnectReason = GsonComponentSerializer.INSTANCE.deserialize(
disconnect.getReason());
String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason); String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason);
if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) { if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) {
logger.error("{}: kicked from server {}: {}", this, server.getServerInfo().getName(), logger.error("{}: kicked from server {}: {}", this, server.getServerInfo().getName(),

Datei anzeigen

@ -9,7 +9,7 @@ import com.velocitypowered.proxy.protocol.packet.Handshake;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Optional; import java.util.Optional;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -54,7 +54,8 @@ class InitialInboundConnection implements InboundConnection, MinecraftConnection
} }
public void disconnect(Component reason) { public void disconnect(Component reason) {
logger.info("{} has disconnected: {}", this, ComponentSerializers.LEGACY.serialize(reason)); logger.info("{} has disconnected: {}", this,
LegacyComponentSerializer.INSTANCE.serialize(reason));
connection.closeWith(Disconnect.create(reason)); connection.closeWith(Disconnect.create(reason));
} }
} }

Datei anzeigen

@ -8,7 +8,7 @@ import com.velocitypowered.proxy.protocol.packet.Disconnect;
import java.util.Optional; import java.util.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.gson.GsonComponentSerializer;
public class ConnectionRequestResults { public class ConnectionRequestResults {
@ -43,12 +43,12 @@ public class ConnectionRequestResults {
} }
public static Impl forDisconnect(Disconnect disconnect, RegisteredServer server) { public static Impl forDisconnect(Disconnect disconnect, RegisteredServer server) {
Component deserialized = ComponentSerializers.JSON.deserialize(disconnect.getReason()); Component deserialized = GsonComponentSerializer.INSTANCE.deserialize(disconnect.getReason());
return forDisconnect(deserialized, server); return forDisconnect(deserialized, server);
} }
public static Impl forUnsafeDisconnect(Disconnect disconnect, RegisteredServer server) { public static Impl forUnsafeDisconnect(Disconnect disconnect, RegisteredServer server) {
Component deserialized = ComponentSerializers.JSON.deserialize(disconnect.getReason()); Component deserialized = GsonComponentSerializer.INSTANCE.deserialize(disconnect.getReason());
return new Impl(Status.SERVER_DISCONNECTED, deserialized, server, false); return new Impl(Status.SERVER_DISCONNECTED, deserialized, server, false);
} }

Datei anzeigen

@ -11,7 +11,7 @@ import java.util.List;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.TextComponent; import net.kyori.text.TextComponent;
import net.kyori.text.format.TextColor; import net.kyori.text.format.TextColor;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.minecrell.terminalconsole.SimpleTerminalConsole; import net.minecrell.terminalconsole.SimpleTerminalConsole;
import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -35,7 +35,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
@Override @Override
public void sendMessage(Component component) { public void sendMessage(Component component) {
logger.info(ComponentSerializers.LEGACY.serialize(component)); logger.info(LegacyComponentSerializer.INSTANCE.serialize(component));
} }
@Override @Override

Datei anzeigen

@ -27,7 +27,7 @@ import java.util.Set;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.plain.PlainComponentSerializer;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@ -71,7 +71,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
private QueryResponse createInitialResponse() { private QueryResponse createInitialResponse() {
return QueryResponse.builder() return QueryResponse.builder()
.hostname(ComponentSerializers.PLAIN .hostname(PlainComponentSerializer.INSTANCE
.serialize(server.getConfiguration().getMotdComponent())) .serialize(server.getConfiguration().getMotdComponent()))
.gameVersion(ProtocolVersion.SUPPORTED_VERSION_STRING) .gameVersion(ProtocolVersion.SUPPORTED_VERSION_STRING)
.map(server.getConfiguration().getQueryMap()) .map(server.getConfiguration().getQueryMap())

Datei anzeigen

@ -7,7 +7,7 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.gson.GsonComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class Chat implements MinecraftPacket { public class Chat implements MinecraftPacket {
@ -83,7 +83,7 @@ public class Chat implements MinecraftPacket {
public static Chat createClientbound(Component component, byte type) { public static Chat createClientbound(Component component, byte type) {
Preconditions.checkNotNull(component, "component"); Preconditions.checkNotNull(component, "component");
return new Chat(ComponentSerializers.JSON.serialize(component), type); return new Chat(GsonComponentSerializer.INSTANCE.serialize(component), type);
} }
public static Chat createServerbound(String message) { public static Chat createServerbound(String message) {

Datei anzeigen

@ -7,7 +7,7 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.gson.GsonComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class Disconnect implements MinecraftPacket { public class Disconnect implements MinecraftPacket {
@ -59,6 +59,6 @@ public class Disconnect implements MinecraftPacket {
public static Disconnect create(Component component) { public static Disconnect create(Component component) {
Preconditions.checkNotNull(component, "component"); Preconditions.checkNotNull(component, "component");
return new Disconnect(ComponentSerializers.JSON.serialize(component)); return new Disconnect(GsonComponentSerializer.INSTANCE.serialize(component));
} }
} }

Datei anzeigen

@ -10,7 +10,7 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializer; import net.kyori.text.serializer.ComponentSerializer;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.gson.GsonComponentSerializer;
public class HeaderAndFooter implements MinecraftPacket { public class HeaderAndFooter implements MinecraftPacket {
@ -54,7 +54,7 @@ public class HeaderAndFooter implements MinecraftPacket {
} }
public static HeaderAndFooter create(Component header, Component footer) { public static HeaderAndFooter create(Component header, Component footer) {
ComponentSerializer<Component, Component, String> json = ComponentSerializers.JSON; ComponentSerializer<Component, Component, String> json = GsonComponentSerializer.INSTANCE;
return new HeaderAndFooter(json.serialize(header), json.serialize(footer)); return new HeaderAndFooter(json.serialize(header), json.serialize(footer));
} }

Datei anzeigen

@ -1,14 +1,12 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet;
import static net.kyori.text.serializer.ComponentSerializers.LEGACY;
import static net.kyori.text.serializer.ComponentSerializers.PLAIN;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing;
import com.velocitypowered.api.proxy.server.ServerPing.Players; import com.velocitypowered.api.proxy.server.ServerPing.Players;
import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion; import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion;
import net.kyori.text.TextComponent; import net.kyori.text.TextComponent;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.text.serializer.plain.PlainComponentSerializer;
public class LegacyDisconnect { public class LegacyDisconnect {
@ -39,7 +37,7 @@ public class LegacyDisconnect {
// remove all section symbols, along with fetching just the first line of an (unformatted) // remove all section symbols, along with fetching just the first line of an (unformatted)
// MOTD. // MOTD.
return new LegacyDisconnect(String.join(LEGACY_COLOR_CODE, return new LegacyDisconnect(String.join(LEGACY_COLOR_CODE,
cleanSectionSymbol(getFirstLine(PLAIN.serialize(response.getDescription()))), cleanSectionSymbol(getFirstLine(PlainComponentSerializer.INSTANCE.serialize(response.getDescription()))),
Integer.toString(players.getOnline()), Integer.toString(players.getOnline()),
Integer.toString(players.getMax()))); Integer.toString(players.getMax())));
case MINECRAFT_1_4: case MINECRAFT_1_4:
@ -49,7 +47,7 @@ public class LegacyDisconnect {
LEGACY_COLOR_CODE + "1", LEGACY_COLOR_CODE + "1",
Integer.toString(response.getVersion().getProtocol()), Integer.toString(response.getVersion().getProtocol()),
response.getVersion().getName(), response.getVersion().getName(),
getFirstLine(LEGACY.serialize(response.getDescription())), getFirstLine(LegacyComponentSerializer.INSTANCE.serialize(response.getDescription())),
Integer.toString(players.getOnline()), Integer.toString(players.getOnline()),
Integer.toString(players.getMax()) Integer.toString(players.getMax())
)); ));
@ -75,7 +73,7 @@ public class LegacyDisconnect {
public static LegacyDisconnect from(TextComponent component) { public static LegacyDisconnect from(TextComponent component) {
// We intentionally use the legacy serializers, because the old clients can't understand JSON. // We intentionally use the legacy serializers, because the old clients can't understand JSON.
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
String serialized = ComponentSerializers.LEGACY.serialize(component); String serialized = LegacyComponentSerializer.INSTANCE.serialize(component);
return new LegacyDisconnect(serialized); return new LegacyDisconnect(serialized);
} }

Datei anzeigen

@ -12,7 +12,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.gson.GsonComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class PlayerListItem implements MinecraftPacket { public class PlayerListItem implements MinecraftPacket {
@ -77,7 +77,7 @@ public class PlayerListItem implements MinecraftPacket {
private static @Nullable Component readOptionalComponent(ByteBuf buf) { private static @Nullable Component readOptionalComponent(ByteBuf buf) {
if (buf.readBoolean()) { if (buf.readBoolean()) {
return ComponentSerializers.JSON.deserialize(ProtocolUtils.readString(buf)); return GsonComponentSerializer.INSTANCE.deserialize(ProtocolUtils.readString(buf));
} }
return null; return null;
} }
@ -123,7 +123,7 @@ public class PlayerListItem implements MinecraftPacket {
private void writeDisplayName(ByteBuf buf, @Nullable Component displayName) { private void writeDisplayName(ByteBuf buf, @Nullable Component displayName) {
buf.writeBoolean(displayName != null); buf.writeBoolean(displayName != null);
if (displayName != null) { if (displayName != null) {
ProtocolUtils.writeString(buf, ComponentSerializers.JSON.serialize(displayName)); ProtocolUtils.writeString(buf, GsonComponentSerializer.INSTANCE.serialize(displayName));
} }
} }

Datei anzeigen

@ -11,7 +11,7 @@ import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.gson.GsonComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class TabCompleteResponse implements MinecraftPacket { public class TabCompleteResponse implements MinecraftPacket {
@ -68,7 +68,7 @@ public class TabCompleteResponse implements MinecraftPacket {
int offersAvailable = ProtocolUtils.readVarInt(buf); int offersAvailable = ProtocolUtils.readVarInt(buf);
for (int i = 0; i < offersAvailable; i++) { for (int i = 0; i < offersAvailable; i++) {
String offer = ProtocolUtils.readString(buf); String offer = ProtocolUtils.readString(buf);
Component tooltip = buf.readBoolean() ? ComponentSerializers.JSON.deserialize( Component tooltip = buf.readBoolean() ? GsonComponentSerializer.INSTANCE.deserialize(
ProtocolUtils.readString(buf)) : null; ProtocolUtils.readString(buf)) : null;
offers.add(new Offer(offer, tooltip)); offers.add(new Offer(offer, tooltip));
} }
@ -91,7 +91,7 @@ public class TabCompleteResponse implements MinecraftPacket {
ProtocolUtils.writeString(buf, offer.text); ProtocolUtils.writeString(buf, offer.text);
buf.writeBoolean(offer.tooltip != null); buf.writeBoolean(offer.tooltip != null);
if (offer.tooltip != null) { if (offer.tooltip != null) {
ProtocolUtils.writeString(buf, ComponentSerializers.JSON.serialize(offer.tooltip)); ProtocolUtils.writeString(buf, GsonComponentSerializer.INSTANCE.serialize(offer.tooltip));
} }
} }
} else { } else {