summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2018-04-19 08:03:39 +1000
committermd_5 <git@md-5.net>2018-04-19 08:03:39 +1000
commit21d5f75d6c7b2f13faf8815b20ba877681a0f47f (patch)
treedbc6cdb2ef49d558ca7e3879ccd07b499c7674ab
parentbea5a842bc51229c58db6ee9a0ce8768935543ea (diff)
downloadcraftbukkit-21d5f75d6c7b2f13faf8815b20ba877681a0f47f.tar
craftbukkit-21d5f75d6c7b2f13faf8815b20ba877681a0f47f.tar.gz
craftbukkit-21d5f75d6c7b2f13faf8815b20ba877681a0f47f.tar.lz
craftbukkit-21d5f75d6c7b2f13faf8815b20ba877681a0f47f.tar.xz
craftbukkit-21d5f75d6c7b2f13faf8815b20ba877681a0f47f.zip
SPIGOT-3908: Fix signed books incorrect defaulting to unresolved
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java6
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java25
2 files changed, 29 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
index 0b5078e5..9c9ef295 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
@@ -52,6 +52,10 @@ 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)) {
@@ -71,7 +75,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
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);
for (int i = 0; i < Math.min(pages.size(), MAX_PAGES); i++) {
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
index ef8bedd6..bffbe901 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
@@ -8,6 +8,7 @@ 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;
@@ -23,7 +24,29 @@ class CraftMetaBookSigned extends CraftMetaBook implements BookMeta {
}
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) {