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

View file

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

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server; 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.MagicValues;
import com.github.steveice10.mc.protocol.data.game.BossBarAction; import com.github.steveice10.mc.protocol.data.game.BossBarAction;
import com.github.steveice10.mc.protocol.data.game.BossBarColor; import com.github.steveice10.mc.protocol.data.game.BossBarColor;
@ -13,7 +14,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException; import java.io.IOException;
import java.util.UUID; import java.util.UUID;
@ -92,7 +92,7 @@ public class ServerBossBarPacket implements Packet {
this.action = MagicValues.key(BossBarAction.class, in.readVarInt()); this.action = MagicValues.key(BossBarAction.class, in.readVarInt());
if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) { 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) { 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)); out.writeVarInt(MagicValues.value(Integer.class, this.action));
if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) { 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) { 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; 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.MagicValues;
import com.github.steveice10.mc.protocol.data.game.MessageType; import com.github.steveice10.mc.protocol.data.game.MessageType;
import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetInput;
@ -12,7 +13,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException; import java.io.IOException;
import java.util.UUID; import java.util.UUID;
@ -27,7 +27,7 @@ public class ServerChatPacket implements Packet {
private @NonNull UUID senderUuid; private @NonNull UUID senderUuid;
public ServerChatPacket(@NonNull String text) { public ServerChatPacket(@NonNull String text) {
this(GsonComponentSerializer.gson().deserialize(text)); this(DefaultComponentSerializer.get().deserialize(text));
} }
public ServerChatPacket(@NonNull Component message) { public ServerChatPacket(@NonNull Component message) {
@ -35,7 +35,7 @@ public class ServerChatPacket implements Packet {
} }
public ServerChatPacket(@NonNull String text, @NonNull MessageType type) { 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) { 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) { 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 @Override
public void read(NetInput in) throws IOException { 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.type = MagicValues.key(MessageType.class, in.readByte());
this.senderUuid = in.readUUID(); this.senderUuid = in.readUUID();
} }
@Override @Override
public void write(NetOutput out) throws IOException { 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.writeByte(MagicValues.value(Integer.class, this.type));
out.writeUUID(this.senderUuid); out.writeUUID(this.senderUuid);
} }

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server; 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.MagicValues;
import com.github.steveice10.mc.protocol.data.game.entity.player.CombatState; import com.github.steveice10.mc.protocol.data.game.entity.player.CombatState;
import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetInput;
@ -10,7 +11,6 @@ import lombok.Data;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException; import java.io.IOException;
@ -52,7 +52,7 @@ public class ServerCombatPacket implements Packet {
} else if(this.combatState == CombatState.ENTITY_DEAD) { } else if(this.combatState == CombatState.ENTITY_DEAD) {
this.playerId = in.readVarInt(); this.playerId = in.readVarInt();
this.entityId = in.readInt(); 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) { } else if(this.combatState == CombatState.ENTITY_DEAD) {
out.writeVarInt(this.playerId); out.writeVarInt(this.playerId);
out.writeInt(this.entityId); 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; 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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -10,7 +11,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException; import java.io.IOException;
@ -22,17 +22,17 @@ public class ServerDisconnectPacket implements Packet {
private @NonNull Component reason; private @NonNull Component reason;
public ServerDisconnectPacket(@NonNull String reason) { public ServerDisconnectPacket(@NonNull String reason) {
this(GsonComponentSerializer.gson().deserialize(reason)); this(DefaultComponentSerializer.get().deserialize(reason));
} }
@Override @Override
public void read(NetInput in) throws IOException { public void read(NetInput in) throws IOException {
this.reason = GsonComponentSerializer.gson().deserialize(in.readString()); this.reason = DefaultComponentSerializer.get().deserialize(in.readString());
} }
@Override @Override
public void write(NetOutput out) throws IOException { public void write(NetOutput out) throws IOException {
out.writeString(GsonComponentSerializer.gson().serialize(this.reason)); out.writeString(DefaultComponentSerializer.get().serialize(this.reason));
} }
@Override @Override

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard; 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.MagicValues;
import com.github.steveice10.mc.protocol.data.UnmappedValueException; import com.github.steveice10.mc.protocol.data.UnmappedValueException;
import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule; import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule;
@ -15,7 +16,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -93,7 +93,7 @@ public class ServerTeamPacket implements Packet {
this.teamName = in.readString(); this.teamName = in.readString();
this.action = MagicValues.key(TeamAction.class, in.readByte()); this.action = MagicValues.key(TeamAction.class, in.readByte());
if(this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) { 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(); byte flags = in.readByte();
this.friendlyFire = (flags & 0x1) != 0; this.friendlyFire = (flags & 0x1) != 0;
this.seeFriendlyInvisibles = (flags & 0x2) != 0; this.seeFriendlyInvisibles = (flags & 0x2) != 0;
@ -106,8 +106,8 @@ public class ServerTeamPacket implements Packet {
this.color = TeamColor.NONE; this.color = TeamColor.NONE;
} }
this.prefix = GsonComponentSerializer.gson().deserialize(in.readString()); this.prefix = DefaultComponentSerializer.get().deserialize(in.readString());
this.suffix = GsonComponentSerializer.gson().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) { 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.writeString(this.teamName);
out.writeByte(MagicValues.value(Integer.class, this.action)); out.writeByte(MagicValues.value(Integer.class, this.action));
if(this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) { 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.writeByte((this.friendlyFire ? 0x1 : 0x0) | (this.seeFriendlyInvisibles ? 0x2 : 0x0));
out.writeString(MagicValues.value(String.class, this.nameTagVisibility)); out.writeString(MagicValues.value(String.class, this.nameTagVisibility));
out.writeString(MagicValues.value(String.class, this.collisionRule)); out.writeString(MagicValues.value(String.class, this.collisionRule));
out.writeVarInt(MagicValues.value(Integer.class, this.color)); out.writeVarInt(MagicValues.value(Integer.class, this.color));
out.writeString(GsonComponentSerializer.gson().serialize(this.prefix)); out.writeString(DefaultComponentSerializer.get().serialize(this.prefix));
out.writeString(GsonComponentSerializer.gson().serialize(this.suffix)); out.writeString(DefaultComponentSerializer.get().serialize(this.suffix));
} }
if(this.action == TeamAction.CREATE || this.action == TeamAction.ADD_PLAYER || this.action == TeamAction.REMOVE_PLAYER) { 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; 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.MagicValues;
import com.github.steveice10.mc.protocol.data.game.world.map.MapData; import com.github.steveice10.mc.protocol.data.game.world.map.MapData;
import com.github.steveice10.mc.protocol.data.game.world.map.MapIcon; import com.github.steveice10.mc.protocol.data.game.world.map.MapIcon;
@ -14,7 +15,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException; import java.io.IOException;
@ -49,7 +49,7 @@ public class ServerMapDataPacket implements Packet {
int rotation = in.readUnsignedByte(); int rotation = in.readUnsignedByte();
Component displayName = null; Component displayName = null;
if(in.readBoolean()) { 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); 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()); out.writeByte(icon.getIconRotation());
if (icon.getDisplayName() != null) { if (icon.getDisplayName() != null) {
out.writeBoolean(false); out.writeBoolean(false);
out.writeString(GsonComponentSerializer.gson().serialize(icon.getDisplayName())); out.writeString(DefaultComponentSerializer.get().serialize(icon.getDisplayName()));
} else { } else {
out.writeBoolean(true); out.writeBoolean(true);
} }

View file

@ -1,5 +1,6 @@
package com.github.steveice10.mc.protocol.packet.login.server; 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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -10,7 +11,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException; import java.io.IOException;
@ -22,17 +22,17 @@ public class LoginDisconnectPacket implements Packet {
private @NonNull Component reason; private @NonNull Component reason;
public LoginDisconnectPacket(String text) { public LoginDisconnectPacket(String text) {
this(GsonComponentSerializer.gson().deserialize(text)); this(DefaultComponentSerializer.get().deserialize(text));
} }
@Override @Override
public void read(NetInput in) throws IOException { public void read(NetInput in) throws IOException {
this.reason = GsonComponentSerializer.gson().deserialize(in.readString()); this.reason = DefaultComponentSerializer.get().deserialize(in.readString());
} }
@Override @Override
public void write(NetOutput out) throws IOException { public void write(NetOutput out) throws IOException {
out.writeString(GsonComponentSerializer.gson().serialize(this.reason)); out.writeString(DefaultComponentSerializer.get().serialize(this.reason));
} }
@Override @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.data.GameProfile;
import com.github.steveice10.mc.auth.util.Base64; 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.PlayerInfo;
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.mc.protocol.data.status.VersionInfo; import com.github.steveice10.mc.protocol.data.status.VersionInfo;
@ -19,7 +20,6 @@ import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; 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); PlayerInfo players = new PlayerInfo(plrs.get("max").getAsInt(), plrs.get("online").getAsInt(), profiles);
JsonElement desc = obj.get("description"); JsonElement desc = obj.get("description");
Component description = GsonComponentSerializer.gson().deserialize(desc.toString()); Component description = DefaultComponentSerializer.get().deserialize(desc.toString());
byte[] icon = null; byte[] icon = null;
if(obj.has("favicon")) { if(obj.has("favicon")) {
icon = this.stringToIcon(obj.get("favicon").getAsString()); icon = this.stringToIcon(obj.get("favicon").getAsString());
@ -83,7 +83,7 @@ public class StatusResponsePacket implements Packet {
obj.add("version", ver); obj.add("version", ver);
obj.add("players", plrs); 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) { if(this.info.getIconPng() != null) {
obj.addProperty("favicon", this.iconToString(this.info.getIconPng())); obj.addProperty("favicon", this.iconToString(this.info.getIconPng()));
} }