SPIGOT-4736: Serialized ItemStack Lore Doesn't Deserialize

This commit is contained in:
md_5 2019-04-25 10:06:40 +10:00
parent c124606439
commit 58c5c617d8
2 changed files with 13 additions and 2 deletions

View file

@ -1191,7 +1191,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
} }
if (hasLore()) { if (hasLore()) {
builder.put(LORE.BUKKIT, ImmutableList.copyOf(lore)); builder.put(LORE.BUKKIT, ImmutableList.copyOf(Lists.transform(lore, CraftChatMessage::fromComponent)));
} }
if (hasCustomModelData()) { if (hasCustomModelData()) {

View file

@ -3,12 +3,15 @@ package org.bukkit.craftbukkit.inventory;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.Test; import org.junit.Test;
@ -43,6 +46,14 @@ public class CompositeSerialization extends AbstractTestingBase {
item8.addUnsafeEnchantment(Enchantment.OXYGEN, 4); item8.addUnsafeEnchantment(Enchantment.OXYGEN, 4);
stacks.add(item8); 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); out.set("composite-list.abc.def", stacks);
String yaml = out.saveToString(); String yaml = out.saveToString();
@ -52,7 +63,7 @@ public class CompositeSerialization extends AbstractTestingBase {
assertThat(stacks, hasSize(raw.size())); 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))); assertThat(String.valueOf(i), (Object) stacks.get(i), is((Object) raw.get(i)));
} }
} }