diff --git a/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java b/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java index 8662d1d5..693f6303 100644 --- a/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java +++ b/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java @@ -77,6 +77,7 @@ public class BukkitCloner implements Cloner { fromWrapper(MinecraftReflection::getIBlockDataClass, WrappedBlockData::fromHandle); fromManual(MinecraftReflection::getNonNullListClass, source -> nonNullListCloner().clone(source)); fromWrapper(MinecraftReflection::getNBTBaseClass, NbtFactory::fromNMS); + fromWrapper(MinecraftReflection::getIChatBaseComponentClass, WrappedChatComponent::fromHandle); } private Function findCloner(Class type) { diff --git a/src/main/java/com/comphenix/protocol/wrappers/WrappedChatComponent.java b/src/main/java/com/comphenix/protocol/wrappers/WrappedChatComponent.java index 172fed34..c7ee9447 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/WrappedChatComponent.java +++ b/src/main/java/com/comphenix/protocol/wrappers/WrappedChatComponent.java @@ -16,7 +16,7 @@ import com.google.common.base.Preconditions; * Represents a chat component added in Minecraft 1.7.2 * @author Kristian */ -public class WrappedChatComponent extends AbstractWrapper { +public class WrappedChatComponent extends AbstractWrapper implements ClonableWrapper { private static final Class SERIALIZER = MinecraftReflection.getChatSerializerClass(); private static final Class COMPONENT = MinecraftReflection.getIChatBaseComponentClass(); private static final Class GSON_CLASS = MinecraftReflection.getMinecraftGsonClass(); diff --git a/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java b/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java index 51b324fc..6fb89397 100644 --- a/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java +++ b/src/test/java/com/comphenix/protocol/events/PacketContainerTest.java @@ -32,6 +32,7 @@ import com.comphenix.protocol.wrappers.nbt.NbtCompound; import com.comphenix.protocol.wrappers.nbt.NbtFactory; import com.google.common.collect.Lists; +import net.md_5.bungee.api.chat.*; import net.minecraft.server.v1_14_R1.*; import net.minecraft.server.v1_14_R1.PacketPlayOutUpdateAttributes.AttributeSnapshot; @@ -70,6 +71,12 @@ public class PacketContainerTest { public static void initializeBukkit() { BukkitInitialization.initializeItemMeta(); BukkitInitialization.initializePackage(); + + TEST_COMPONENT = ComponentConverter.fromBaseComponent( + new ComponentBuilder("Hit or miss?") + .event(new ClickEvent(ClickEvent.Action.OPEN_URL, "http://reddit.com")) + .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[] { new TextComponent("The \"front page\" of the internet") })) + .append("I guess they never miss, huh?").create()); } private void testPrimitive(StructureModifier modifier, int index, T initialValue, T testValue) { @@ -504,6 +511,8 @@ public class PacketContainerTest { PacketType.Play.Server.TAGS ); + private static WrappedChatComponent TEST_COMPONENT; + @Test public void testDeepClone() { // Try constructing all the packets @@ -525,8 +534,12 @@ public class PacketContainerTest { (byte) 1), new WrappedWatchableObject(new WrappedDataWatcherObject(0, Registry.get(String.class)), "String"), - new WrappedWatchableObject(new WrappedDataWatcherObject(0, Registry.get(Float.class)), 1.0F) + new WrappedWatchableObject(new WrappedDataWatcherObject(0, Registry.get(Float.class)), 1.0F), + new WrappedWatchableObject(new WrappedDataWatcherObject(0, Registry.getChatComponentSerializer(true)), + com.google.common.base.Optional.of(TEST_COMPONENT.getHandle())) )); + } else if (type == PacketType.Play.Server.CHAT) { + constructed.getChatComponents().write(0, TEST_COMPONENT); } // Clone the packet