SPIGOT-3904: Consolidate book handling code

This commit is contained in:
md_5 2018-04-16 19:19:38 +10:00
parent 4509a144db
commit bea5a842bc
2 changed files with 3 additions and 33 deletions

View file

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

View file

@ -1,7 +1,5 @@
package org.bukkit.craftbukkit.inventory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.minecraft.server.NBTTagCompound;
@ -10,14 +8,12 @@ import net.minecraft.server.NBTTagList;
import org.bukkit.Material;
import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.meta.BookMeta;
import com.google.common.collect.ImmutableMap.Builder;
import net.minecraft.server.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.IChatBaseComponent;
import net.minecraft.server.NBTTagString;
import org.bukkit.craftbukkit.util.CraftChatMessage;
@DelegateDeserialization(SerializableMeta.class)
class CraftMetaBookSigned extends CraftMetaBook implements BookMeta {
@ -27,29 +23,7 @@ class CraftMetaBookSigned extends CraftMetaBook implements BookMeta {
}
CraftMetaBookSigned(NBTTagCompound 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 < pages.size(); 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);
}
}
super(tag);
}
CraftMetaBookSigned(Map<String, Object> map) {