From 26201a49f082e49b55ee592b2a52fecc6da79ebe Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Sat, 21 Nov 2020 13:56:49 -0800 Subject: [PATCH] Allow specifying a custom GsonComponentSerializer to use. --- .../data/DefaultComponentSerializer.java | 18 ++++++++++++++++++ .../game/entity/metadata/EntityMetadata.java | 6 +++--- .../server/ServerAdvancementsPacket.java | 10 +++++----- .../ingame/server/ServerBossBarPacket.java | 6 +++--- .../packet/ingame/server/ServerChatPacket.java | 12 ++++++------ .../ingame/server/ServerCombatPacket.java | 6 +++--- .../ingame/server/ServerDisconnectPacket.java | 8 ++++---- .../server/ServerPlayerListDataPacket.java | 10 +++++----- .../server/ServerPlayerListEntryPacket.java | 10 +++++----- .../ingame/server/ServerTabCompletePacket.java | 6 +++--- .../ingame/server/ServerTitlePacket.java | 6 +++--- .../ServerScoreboardObjectivePacket.java | 6 +++--- .../server/scoreboard/ServerTeamPacket.java | 14 +++++++------- .../server/world/ServerMapDataPacket.java | 6 +++--- .../login/server/LoginDisconnectPacket.java | 8 ++++---- .../status/server/StatusResponsePacket.java | 6 +++--- 16 files changed, 78 insertions(+), 60 deletions(-) create mode 100644 src/main/java/com/github/steveice10/mc/protocol/data/DefaultComponentSerializer.java diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/DefaultComponentSerializer.java b/src/main/java/com/github/steveice10/mc/protocol/data/DefaultComponentSerializer.java new file mode 100644 index 00000000..86c66654 --- /dev/null +++ b/src/main/java/com/github/steveice10/mc/protocol/data/DefaultComponentSerializer.java @@ -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() { + } +} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/EntityMetadata.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/EntityMetadata.java index 8638e631..9aa69827 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/EntityMetadata.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/EntityMetadata.java @@ -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()); diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerAdvancementsPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerAdvancementsPacket.java index e9389aef..cf4a35fd 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerAdvancementsPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerAdvancementsPacket.java @@ -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(); diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerBossBarPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerBossBarPacket.java index a70ec526..5be241a0 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerBossBarPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerBossBarPacket.java @@ -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) { diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerChatPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerChatPacket.java index 57f988d4..5c469028 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerChatPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerChatPacket.java @@ -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); } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerCombatPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerCombatPacket.java index b1e50ef7..ee9b85f4 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerCombatPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerCombatPacket.java @@ -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)); } } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDisconnectPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDisconnectPacket.java index d22e52f8..42b58bb8 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDisconnectPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDisconnectPacket.java @@ -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 diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListDataPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListDataPacket.java index 39a72332..f42f8eb4 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListDataPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListDataPacket.java @@ -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 diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListEntryPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListEntryPacket.java index 5608876a..4114d4e9 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListEntryPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListEntryPacket.java @@ -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; diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTabCompletePacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTabCompletePacket.java index b9ce06e6..32fdf97b 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTabCompletePacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTabCompletePacket.java @@ -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); } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTitlePacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTitlePacket.java index 06517457..dde2b7cf 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTitlePacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTitlePacket.java @@ -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); diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerScoreboardObjectivePacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerScoreboardObjectivePacket.java index 06026b04..a50ee719 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerScoreboardObjectivePacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerScoreboardObjectivePacket.java @@ -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)); } } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerTeamPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerTeamPacket.java index 87f3ea18..20d495bc 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerTeamPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerTeamPacket.java @@ -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) { diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerMapDataPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerMapDataPacket.java index d7ccba9d..83bdfef1 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerMapDataPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerMapDataPacket.java @@ -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); } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacket.java index d4ada071..175b7878 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacket.java @@ -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 diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacket.java index 8184bdb8..02e0b0e3 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacket.java @@ -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())); }