Allow specifying a custom GsonComponentSerializer to use.

This commit is contained in:
Steveice10 2020-11-21 13:56:49 -08:00
parent ccbd52dffd
commit 26201a49f0
16 changed files with 78 additions and 60 deletions

View file

@ -0,0 +1,18 @@
package com.github.steveice10.mc.protocol.data;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
public final class DefaultComponentSerializer {
private static GsonComponentSerializer serializer = GsonComponentSerializer.gson();
public static GsonComponentSerializer get() {
return serializer;
}
public static void set(GsonComponentSerializer serializer) {
DefaultComponentSerializer.serializer = serializer;
}
private DefaultComponentSerializer() {
}
}

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.NBT;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
@ -13,7 +14,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
import java.util.ArrayList;
@ -57,7 +57,7 @@ public class EntityMetadata {
// Intentional fall-through
case CHAT:
value = GsonComponentSerializer.gson().deserialize(in.readString());
value = DefaultComponentSerializer.get().deserialize(in.readString());
break;
case ITEM:
value = ItemStack.read(in);
@ -140,7 +140,7 @@ public class EntityMetadata {
// Intentional fall-through
case CHAT:
out.writeString(GsonComponentSerializer.gson().serialize((Component) meta.getValue()));
out.writeString(DefaultComponentSerializer.get().serialize((Component) meta.getValue()));
break;
case ITEM:
ItemStack.write(out, (ItemStack) meta.getValue());

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement;
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement.DisplayData;
@ -15,7 +16,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
import java.util.ArrayList;
@ -60,8 +60,8 @@ public class ServerAdvancementsPacket implements Packet {
String parentId = in.readBoolean() ? in.readString() : null;
DisplayData displayData = null;
if(in.readBoolean()) {
Component title = GsonComponentSerializer.gson().deserialize(in.readString());
Component description = GsonComponentSerializer.gson().deserialize(in.readString());
Component title = DefaultComponentSerializer.get().deserialize(in.readString());
Component description = DefaultComponentSerializer.get().deserialize(in.readString());
ItemStack icon = ItemStack.read(in);
FrameType frameType = MagicValues.key(FrameType.class, in.readVarInt());
@ -137,8 +137,8 @@ public class ServerAdvancementsPacket implements Packet {
DisplayData displayData = advancement.getDisplayData();
if(displayData != null) {
out.writeBoolean(true);
out.writeString(GsonComponentSerializer.gson().serialize(displayData.getTitle()));
out.writeString(GsonComponentSerializer.gson().serialize(displayData.getDescription()));
out.writeString(DefaultComponentSerializer.get().serialize(displayData.getTitle()));
out.writeString(DefaultComponentSerializer.get().serialize(displayData.getDescription()));
ItemStack.write(out, displayData.getIcon());
out.writeVarInt(MagicValues.value(Integer.class, displayData.getFrameType()));
String backgroundTexture = displayData.getBackgroundTexture();

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.BossBarAction;
import com.github.steveice10.mc.protocol.data.game.BossBarColor;
@ -13,7 +14,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
import java.util.UUID;
@ -92,7 +92,7 @@ public class ServerBossBarPacket implements Packet {
this.action = MagicValues.key(BossBarAction.class, in.readVarInt());
if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
this.title = GsonComponentSerializer.gson().deserialize(in.readString());
this.title = DefaultComponentSerializer.get().deserialize(in.readString());
}
if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) {
@ -118,7 +118,7 @@ public class ServerBossBarPacket implements Packet {
out.writeVarInt(MagicValues.value(Integer.class, this.action));
if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
out.writeString(GsonComponentSerializer.gson().serialize(this.title));
out.writeString(DefaultComponentSerializer.get().serialize(this.title));
}
if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) {

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.MessageType;
import com.github.steveice10.packetlib.io.NetInput;
@ -12,7 +13,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
import java.util.UUID;
@ -27,7 +27,7 @@ public class ServerChatPacket implements Packet {
private @NonNull UUID senderUuid;
public ServerChatPacket(@NonNull String text) {
this(GsonComponentSerializer.gson().deserialize(text));
this(DefaultComponentSerializer.get().deserialize(text));
}
public ServerChatPacket(@NonNull Component message) {
@ -35,7 +35,7 @@ public class ServerChatPacket implements Packet {
}
public ServerChatPacket(@NonNull String text, @NonNull MessageType type) {
this(GsonComponentSerializer.gson().deserialize(text), type, new UUID(0, 0));
this(DefaultComponentSerializer.get().deserialize(text), type, new UUID(0, 0));
}
public ServerChatPacket(@NonNull Component message, @NonNull MessageType type) {
@ -43,19 +43,19 @@ public class ServerChatPacket implements Packet {
}
public ServerChatPacket(@NonNull String text, @NonNull MessageType type, @NonNull UUID uuid) {
this(GsonComponentSerializer.gson().deserialize(text), type, uuid);
this(DefaultComponentSerializer.get().deserialize(text), type, uuid);
}
@Override
public void read(NetInput in) throws IOException {
this.message = GsonComponentSerializer.gson().deserialize(in.readString());
this.message = DefaultComponentSerializer.get().deserialize(in.readString());
this.type = MagicValues.key(MessageType.class, in.readByte());
this.senderUuid = in.readUUID();
}
@Override
public void write(NetOutput out) throws IOException {
out.writeString(GsonComponentSerializer.gson().serialize(this.message));
out.writeString(DefaultComponentSerializer.get().serialize(this.message));
out.writeByte(MagicValues.value(Integer.class, this.type));
out.writeUUID(this.senderUuid);
}

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.entity.player.CombatState;
import com.github.steveice10.packetlib.io.NetInput;
@ -10,7 +11,6 @@ import lombok.Data;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
@ -52,7 +52,7 @@ public class ServerCombatPacket implements Packet {
} else if(this.combatState == CombatState.ENTITY_DEAD) {
this.playerId = in.readVarInt();
this.entityId = in.readInt();
this.message = GsonComponentSerializer.gson().deserialize(in.readString());
this.message = DefaultComponentSerializer.get().deserialize(in.readString());
}
}
@ -65,7 +65,7 @@ public class ServerCombatPacket implements Packet {
} else if(this.combatState == CombatState.ENTITY_DEAD) {
out.writeVarInt(this.playerId);
out.writeInt(this.entityId);
out.writeString(GsonComponentSerializer.gson().serialize(this.message));
out.writeString(DefaultComponentSerializer.get().serialize(this.message));
}
}

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
@ -10,7 +11,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
@ -22,17 +22,17 @@ public class ServerDisconnectPacket implements Packet {
private @NonNull Component reason;
public ServerDisconnectPacket(@NonNull String reason) {
this(GsonComponentSerializer.gson().deserialize(reason));
this(DefaultComponentSerializer.get().deserialize(reason));
}
@Override
public void read(NetInput in) throws IOException {
this.reason = GsonComponentSerializer.gson().deserialize(in.readString());
this.reason = DefaultComponentSerializer.get().deserialize(in.readString());
}
@Override
public void write(NetOutput out) throws IOException {
out.writeString(GsonComponentSerializer.gson().serialize(this.reason));
out.writeString(DefaultComponentSerializer.get().serialize(this.reason));
}
@Override

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
@ -10,7 +11,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
@ -24,14 +24,14 @@ public class ServerPlayerListDataPacket implements Packet {
@Override
public void read(NetInput in) throws IOException {
this.header = GsonComponentSerializer.gson().deserialize(in.readString());
this.footer = GsonComponentSerializer.gson().deserialize(in.readString());
this.header = DefaultComponentSerializer.get().deserialize(in.readString());
this.footer = DefaultComponentSerializer.get().deserialize(in.readString());
}
@Override
public void write(NetOutput out) throws IOException {
out.writeString(GsonComponentSerializer.gson().serialize(this.header));
out.writeString(GsonComponentSerializer.gson().serialize(this.footer));
out.writeString(DefaultComponentSerializer.get().serialize(this.header));
out.writeString(DefaultComponentSerializer.get().serialize(this.footer));
}
@Override

View file

@ -1,6 +1,7 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.PlayerListEntry;
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction;
@ -15,7 +16,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
import java.util.ArrayList;
@ -66,7 +66,7 @@ public class ServerPlayerListEntryPacket implements Packet {
int ping = in.readVarInt();
Component displayName = null;
if(in.readBoolean()) {
displayName = GsonComponentSerializer.gson().deserialize(in.readString());
displayName = DefaultComponentSerializer.get().deserialize(in.readString());
}
entry = new PlayerListEntry(profile, gameMode, ping, displayName);
@ -88,7 +88,7 @@ public class ServerPlayerListEntryPacket implements Packet {
case UPDATE_DISPLAY_NAME: {
Component displayName = null;
if(in.readBoolean()) {
displayName = GsonComponentSerializer.gson().deserialize(in.readString());
displayName = DefaultComponentSerializer.get().deserialize(in.readString());
}
entry = new PlayerListEntry(profile, displayName);
@ -126,7 +126,7 @@ public class ServerPlayerListEntryPacket implements Packet {
out.writeVarInt(entry.getPing());
out.writeBoolean(entry.getDisplayName() != null);
if(entry.getDisplayName() != null) {
out.writeString(GsonComponentSerializer.gson().serialize(entry.getDisplayName()));
out.writeString(DefaultComponentSerializer.get().serialize(entry.getDisplayName()));
}
break;
@ -139,7 +139,7 @@ public class ServerPlayerListEntryPacket implements Packet {
case UPDATE_DISPLAY_NAME:
out.writeBoolean(entry.getDisplayName() != null);
if(entry.getDisplayName() != null) {
out.writeString(GsonComponentSerializer.gson().serialize(entry.getDisplayName()));
out.writeString(DefaultComponentSerializer.get().serialize(entry.getDisplayName()));
}
break;

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
@ -9,7 +10,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
import java.util.Arrays;
@ -46,7 +46,7 @@ public class ServerTabCompletePacket implements Packet {
for(int index = 0; index < this.matches.length; index++) {
this.matches[index] = in.readString();
if (in.readBoolean()) {
this.tooltips[index] = GsonComponentSerializer.gson().deserialize(in.readString());
this.tooltips[index] = DefaultComponentSerializer.get().deserialize(in.readString());
}
}
}
@ -62,7 +62,7 @@ public class ServerTabCompletePacket implements Packet {
Component tooltip = this.tooltips[index];
if (tooltip != null) {
out.writeBoolean(true);
out.writeString(GsonComponentSerializer.gson().serialize(tooltip));
out.writeString(DefaultComponentSerializer.get().serialize(tooltip));
} else {
out.writeBoolean(false);
}

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.TitleAction;
import com.github.steveice10.packetlib.io.NetInput;
@ -11,7 +12,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
@ -59,7 +59,7 @@ public class ServerTitlePacket implements Packet {
case TITLE:
case SUBTITLE:
case ACTION_BAR:
this.title = GsonComponentSerializer.gson().deserialize(in.readString());
this.title = DefaultComponentSerializer.get().deserialize(in.readString());
break;
case TIMES:
this.fadeIn = in.readInt();
@ -79,7 +79,7 @@ public class ServerTitlePacket implements Packet {
case TITLE:
case SUBTITLE:
case ACTION_BAR:
out.writeString(GsonComponentSerializer.gson().serialize(this.title));
out.writeString(DefaultComponentSerializer.get().serialize(this.title));
break;
case TIMES:
out.writeInt(this.fadeIn);

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.scoreboard.ObjectiveAction;
import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreType;
@ -12,7 +13,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
@ -47,7 +47,7 @@ public class ServerScoreboardObjectivePacket implements Packet {
this.name = in.readString();
this.action = MagicValues.key(ObjectiveAction.class, in.readByte());
if(this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) {
this.displayName = GsonComponentSerializer.gson().deserialize(in.readString());
this.displayName = DefaultComponentSerializer.get().deserialize(in.readString());
this.type = MagicValues.key(ScoreType.class, in.readVarInt());
}
}
@ -57,7 +57,7 @@ public class ServerScoreboardObjectivePacket implements Packet {
out.writeString(this.name);
out.writeByte(MagicValues.value(Integer.class, this.action));
if(this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) {
out.writeString(GsonComponentSerializer.gson().serialize(this.displayName));
out.writeString(DefaultComponentSerializer.get().serialize(this.displayName));
out.writeVarInt(MagicValues.value(Integer.class, this.type));
}
}

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.UnmappedValueException;
import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule;
@ -15,7 +16,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
import java.util.Arrays;
@ -93,7 +93,7 @@ public class ServerTeamPacket implements Packet {
this.teamName = in.readString();
this.action = MagicValues.key(TeamAction.class, in.readByte());
if(this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) {
this.displayName = GsonComponentSerializer.gson().deserialize(in.readString());
this.displayName = DefaultComponentSerializer.get().deserialize(in.readString());
byte flags = in.readByte();
this.friendlyFire = (flags & 0x1) != 0;
this.seeFriendlyInvisibles = (flags & 0x2) != 0;
@ -106,8 +106,8 @@ public class ServerTeamPacket implements Packet {
this.color = TeamColor.NONE;
}
this.prefix = GsonComponentSerializer.gson().deserialize(in.readString());
this.suffix = GsonComponentSerializer.gson().deserialize(in.readString());
this.prefix = DefaultComponentSerializer.get().deserialize(in.readString());
this.suffix = DefaultComponentSerializer.get().deserialize(in.readString());
}
if(this.action == TeamAction.CREATE || this.action == TeamAction.ADD_PLAYER || this.action == TeamAction.REMOVE_PLAYER) {
@ -123,13 +123,13 @@ public class ServerTeamPacket implements Packet {
out.writeString(this.teamName);
out.writeByte(MagicValues.value(Integer.class, this.action));
if(this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) {
out.writeString(GsonComponentSerializer.gson().serialize(this.displayName));
out.writeString(DefaultComponentSerializer.get().serialize(this.displayName));
out.writeByte((this.friendlyFire ? 0x1 : 0x0) | (this.seeFriendlyInvisibles ? 0x2 : 0x0));
out.writeString(MagicValues.value(String.class, this.nameTagVisibility));
out.writeString(MagicValues.value(String.class, this.collisionRule));
out.writeVarInt(MagicValues.value(Integer.class, this.color));
out.writeString(GsonComponentSerializer.gson().serialize(this.prefix));
out.writeString(GsonComponentSerializer.gson().serialize(this.suffix));
out.writeString(DefaultComponentSerializer.get().serialize(this.prefix));
out.writeString(DefaultComponentSerializer.get().serialize(this.suffix));
}
if(this.action == TeamAction.CREATE || this.action == TeamAction.ADD_PLAYER || this.action == TeamAction.REMOVE_PLAYER) {

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server.world;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.world.map.MapData;
import com.github.steveice10.mc.protocol.data.game.world.map.MapIcon;
@ -14,7 +15,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
@ -49,7 +49,7 @@ public class ServerMapDataPacket implements Packet {
int rotation = in.readUnsignedByte();
Component displayName = null;
if(in.readBoolean()) {
displayName = GsonComponentSerializer.gson().deserialize(in.readString());
displayName = DefaultComponentSerializer.get().deserialize(in.readString());
}
this.icons[index] = new MapIcon(x, z, MagicValues.key(MapIconType.class, type), rotation, displayName);
@ -82,7 +82,7 @@ public class ServerMapDataPacket implements Packet {
out.writeByte(icon.getIconRotation());
if (icon.getDisplayName() != null) {
out.writeBoolean(false);
out.writeString(GsonComponentSerializer.gson().serialize(icon.getDisplayName()));
out.writeString(DefaultComponentSerializer.get().serialize(icon.getDisplayName()));
} else {
out.writeBoolean(true);
}

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.login.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
@ -10,7 +11,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
@ -22,17 +22,17 @@ public class LoginDisconnectPacket implements Packet {
private @NonNull Component reason;
public LoginDisconnectPacket(String text) {
this(GsonComponentSerializer.gson().deserialize(text));
this(DefaultComponentSerializer.get().deserialize(text));
}
@Override
public void read(NetInput in) throws IOException {
this.reason = GsonComponentSerializer.gson().deserialize(in.readString());
this.reason = DefaultComponentSerializer.get().deserialize(in.readString());
}
@Override
public void write(NetOutput out) throws IOException {
out.writeString(GsonComponentSerializer.gson().serialize(this.reason));
out.writeString(DefaultComponentSerializer.get().serialize(this.reason));
}
@Override

View file

@ -2,6 +2,7 @@ package com.github.steveice10.mc.protocol.packet.status.server;
import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.auth.util.Base64;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.status.PlayerInfo;
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.mc.protocol.data.status.VersionInfo;
@ -19,7 +20,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@ -51,7 +51,7 @@ public class StatusResponsePacket implements Packet {
PlayerInfo players = new PlayerInfo(plrs.get("max").getAsInt(), plrs.get("online").getAsInt(), profiles);
JsonElement desc = obj.get("description");
Component description = GsonComponentSerializer.gson().deserialize(desc.toString());
Component description = DefaultComponentSerializer.get().deserialize(desc.toString());
byte[] icon = null;
if(obj.has("favicon")) {
icon = this.stringToIcon(obj.get("favicon").getAsString());
@ -83,7 +83,7 @@ public class StatusResponsePacket implements Packet {
obj.add("version", ver);
obj.add("players", plrs);
obj.add("description", new Gson().fromJson(GsonComponentSerializer.gson().serialize(this.info.getDescription()), JsonElement.class));
obj.add("description", new Gson().fromJson(DefaultComponentSerializer.get().serialize(this.info.getDescription()), JsonElement.class));
if(this.info.getIconPng() != null) {
obj.addProperty("favicon", this.iconToString(this.info.getIconPng()));
}