From 151dedca99e01e830d001784f58907a46476abb8 Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Wed, 1 Jul 2020 00:40:39 +0200 Subject: [PATCH] Fixed SerializableData#clone --- src/main/java/net/minestom/server/chat/Chat.java | 1 + .../java/net/minestom/server/data/SerializableData.java | 7 ++++--- .../network/packet/client/login/LoginStartPacket.java | 5 ++++- .../network/packet/server/play/EntityEquipmentPacket.java | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minestom/server/chat/Chat.java b/src/main/java/net/minestom/server/chat/Chat.java index 864e63aa3..51ff44f21 100644 --- a/src/main/java/net/minestom/server/chat/Chat.java +++ b/src/main/java/net/minestom/server/chat/Chat.java @@ -1,5 +1,6 @@ package net.minestom.server.chat; + import net.kyori.text.Component; import net.kyori.text.serializer.gson.GsonComponentSerializer; import net.kyori.text.serializer.legacy.LegacyComponentSerializer; diff --git a/src/main/java/net/minestom/server/data/SerializableData.java b/src/main/java/net/minestom/server/data/SerializableData.java index c3188e868..eef3450d5 100644 --- a/src/main/java/net/minestom/server/data/SerializableData.java +++ b/src/main/java/net/minestom/server/data/SerializableData.java @@ -28,9 +28,10 @@ public class SerializableData extends Data { @Override public Data clone() { - SerializableData cloned = (SerializableData) super.clone(); - cloned.dataType = new ConcurrentHashMap<>(dataType); - return super.clone(); + SerializableData data = new SerializableData(); + data.data = new ConcurrentHashMap<>(this.data); + data.dataType = new ConcurrentHashMap<>(dataType); + return data; } public byte[] getSerializedData() throws IOException { diff --git a/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java b/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java index 9530e39e3..8d16896bc 100644 --- a/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java @@ -17,13 +17,16 @@ import java.util.UUID; public class LoginStartPacket implements ClientPreplayPacket { + private static final String ALREADY_CONNECTED_JSON = + ColoredText.of(ChatColor.RED, "You are already on this server").toString(); + public String username; @Override public void process(PlayerConnection connection, ConnectionManager connectionManager) { if (MojangAuth.isUsingMojangAuth()) { if (connectionManager.getPlayer(username) != null) { - connection.sendPacket(new LoginDisconnect(ColoredText.of(ChatColor.RED, "You are already on this server").toString())); + connection.sendPacket(new LoginDisconnect(ALREADY_CONNECTED_JSON)); connection.disconnect(); return; } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityEquipmentPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityEquipmentPacket.java index d76bef468..5c11e11bc 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityEquipmentPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityEquipmentPacket.java @@ -15,6 +15,7 @@ public class EntityEquipmentPacket implements ServerPacket { @Override public void write(PacketWriter writer) { writer.writeVarInt(entityId); + // TODO multiple equipments writer.writeByte((byte) slot.ordinal()); writer.writeItemStack(itemStack); }