summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2018-04-16 19:19:38 +1000
committermd_5 <git@md-5.net>2018-04-16 19:19:38 +1000
commitbea5a842bc51229c58db6ee9a0ce8768935543ea (patch)
tree2b96b021b3e19b706186a325cfeba6e96862870a /src
parent4509a144db68e6d0b7a6ead1f2095c32cba7f26d (diff)
downloadcraftbukkit-bea5a842bc51229c58db6ee9a0ce8768935543ea.tar
craftbukkit-bea5a842bc51229c58db6ee9a0ce8768935543ea.tar.gz
craftbukkit-bea5a842bc51229c58db6ee9a0ce8768935543ea.tar.lz
craftbukkit-bea5a842bc51229c58db6ee9a0ce8768935543ea.tar.xz
craftbukkit-bea5a842bc51229c58db6ee9a0ce8768935543ea.zip
SPIGOT-3904: Consolidate book handling code
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java8
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java28
2 files changed, 3 insertions, 33 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
index 441632bb..0b5078e5 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
@@ -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 {
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
index 05c13d30..ef8bedd6 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
@@ -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) {