SPIGOT-3908: Fix signed books incorrect defaulting to unresolved

This commit is contained in:
md_5 2018-04-19 08:03:39 +10:00
parent bea5a842bc
commit 21d5f75d6c
2 changed files with 29 additions and 2 deletions

View File

@ -52,6 +52,10 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
} }
CraftMetaBook(NBTTagCompound tag) { CraftMetaBook(NBTTagCompound tag) {
this(tag, true);
}
CraftMetaBook(NBTTagCompound tag, boolean handlePages) {
super(tag); super(tag);
if (tag.hasKey(BOOK_TITLE.NBT)) { if (tag.hasKey(BOOK_TITLE.NBT)) {
@ -71,7 +75,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
generation = tag.getInt(GENERATION.NBT); generation = tag.getInt(GENERATION.NBT);
} }
if (tag.hasKey(BOOK_PAGES.NBT)) { if (tag.hasKey(BOOK_PAGES.NBT) && handlePages) {
NBTTagList pages = tag.getList(BOOK_PAGES.NBT, CraftMagicNumbers.NBT.TAG_STRING); NBTTagList pages = tag.getList(BOOK_PAGES.NBT, CraftMagicNumbers.NBT.TAG_STRING);
for (int i = 0; i < Math.min(pages.size(), MAX_PAGES); i++) { for (int i = 0; i < Math.min(pages.size(), MAX_PAGES); i++) {

View File

@ -8,6 +8,7 @@ import net.minecraft.server.NBTTagList;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableMap.Builder;
@ -23,7 +24,29 @@ class CraftMetaBookSigned extends CraftMetaBook implements BookMeta {
} }
CraftMetaBookSigned(NBTTagCompound tag) { CraftMetaBookSigned(NBTTagCompound tag) {
super(tag); super(tag, false);
boolean resolved = true;
if (tag.hasKey(RESOLVED.NBT)) {
resolved = tag.getBoolean(RESOLVED.NBT);
}
if (tag.hasKey(BOOK_PAGES.NBT)) {
NBTTagList pages = tag.getList(BOOK_PAGES.NBT, CraftMagicNumbers.NBT.TAG_STRING);
for (int i = 0; i < Math.min(pages.size(), MAX_PAGES); i++) {
String page = pages.getString(i);
if (resolved) {
try {
this.pages.add(ChatSerializer.a(page));
continue;
} catch (Exception e) {
// Ignore and treat as an old book
}
}
addPage(page);
}
}
} }
CraftMetaBookSigned(Map<String, Object> map) { CraftMetaBookSigned(Map<String, Object> map) {