From 58c5c617d8024aaae99751c966bf36fb4f43f95b Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 25 Apr 2019 10:06:40 +1000 Subject: [PATCH] SPIGOT-4736: Serialized ItemStack Lore Doesn't Deserialize --- .../bukkit/craftbukkit/inventory/CraftMetaItem.java | 2 +- .../inventory/CompositeSerialization.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index c1b34377ee..1dc988f695 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -1191,7 +1191,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { } if (hasLore()) { - builder.put(LORE.BUKKIT, ImmutableList.copyOf(lore)); + builder.put(LORE.BUKKIT, ImmutableList.copyOf(Lists.transform(lore, CraftChatMessage::fromComponent))); } if (hasCustomModelData()) { diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java b/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java index fe62feb088..4a85b083b4 100644 --- a/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java +++ b/src/test/java/org/bukkit/craftbukkit/inventory/CompositeSerialization.java @@ -3,12 +3,15 @@ package org.bukkit.craftbukkit.inventory; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.support.AbstractTestingBase; import org.junit.Test; @@ -43,6 +46,14 @@ public class CompositeSerialization extends AbstractTestingBase { item8.addUnsafeEnchantment(Enchantment.OXYGEN, 4); stacks.add(item8); + ItemStack item9 = new ItemStack(Material.APPLE); + ItemMeta meta9 = item9.getItemMeta(); + meta9.setDisplayName(ChatColor.RED + "DisplayName"); + meta9.setLocalizedName(ChatColor.AQUA + "LocalizedName"); + meta9.setLore(Arrays.asList(ChatColor.BLUE + "Lore1", ChatColor.DARK_AQUA + "Lore2")); + item9.setItemMeta(meta9); + stacks.add(item9); + out.set("composite-list.abc.def", stacks); String yaml = out.saveToString(); @@ -52,7 +63,7 @@ public class CompositeSerialization extends AbstractTestingBase { assertThat(stacks, hasSize(raw.size())); - for (int i = 0; i < 9; i++) { + for (int i = 0; i < raw.size(); i++) { assertThat(String.valueOf(i), (Object) stacks.get(i), is((Object) raw.get(i))); } }