diff options
author | Thinkofdeath <thinkofdeath@spigotmc.org> | 2014-11-30 15:06:14 +0000 |
---|---|---|
committer | Thinkofdeath <thinkofdeath@spigotmc.org> | 2014-11-30 15:06:14 +0000 |
commit | 22df29225833bd65bb9137829a57e490258ed045 (patch) | |
tree | 2fac888fd888ce1d512dd38b6ff57f0d195fc577 /src/main/java/org/bukkit | |
parent | 6eb0c79271c6e50fc36972913250dfc5ad19d04f (diff) | |
download | craftbukkit-22df29225833bd65bb9137829a57e490258ed045.tar craftbukkit-22df29225833bd65bb9137829a57e490258ed045.tar.gz craftbukkit-22df29225833bd65bb9137829a57e490258ed045.tar.lz craftbukkit-22df29225833bd65bb9137829a57e490258ed045.tar.xz craftbukkit-22df29225833bd65bb9137829a57e490258ed045.zip |
Add a somewhat hacky fix for plugins converting between book types
Diffstat (limited to 'src/main/java/org/bukkit')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index b49c2dca..59be14b7 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -20,6 +20,10 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import com.google.common.collect.ImmutableMap; +import net.minecraft.server.ChatSerializer; +import net.minecraft.server.Items; +import net.minecraft.server.NBTTagString; +import org.bukkit.craftbukkit.util.CraftChatMessage; @DelegateDeserialization(ItemStack.class) public final class CraftItemStack extends ItemStack { @@ -374,6 +378,42 @@ public final class CraftItemStack extends ItemStack { item.setTag(tag); ((CraftMetaItem) itemMeta).applyToItem(tag); + + // Hacky fix for books + // TODO: Not use a hacky fix for books + if (tag.getBoolean(CraftMetaBook.RESOLVED.NBT) && item.getItem() == Items.WRITABLE_BOOK) { + if (tag.hasKey(CraftMetaBook.BOOK_PAGES.NBT)) { + NBTTagList pages = tag.getList(CraftMetaBook.BOOK_PAGES.NBT, 8); + + for (int i = 0; i < pages.size(); i++) { + String page = pages.getString(i); + page = CraftChatMessage.fromComponent(ChatSerializer.a(page)); + pages.a(i, new NBTTagString(page)); + } + tag.set(CraftMetaBook.BOOK_PAGES.NBT, pages); + } + tag.setBoolean(CraftMetaBook.RESOLVED.NBT, false); + } else if (!tag.getBoolean(CraftMetaBook.RESOLVED.NBT) && item.getItem() == Items.WRITTEN_BOOK) { + if (tag.hasKey(CraftMetaBook.BOOK_PAGES.NBT)) { + NBTTagList pages = tag.getList(CraftMetaBook.BOOK_PAGES.NBT, 8); + + for (int i = 0; i < pages.size(); i++) { + String page = pages.getString(i); + page = ChatSerializer.a(CraftChatMessage.fromString(page, true)[0]); + pages.a(i, new NBTTagString(page)); + } + tag.set(CraftMetaBook.BOOK_PAGES.NBT, pages); + } + + tag.setBoolean(CraftMetaBook.RESOLVED.NBT, true); + if (!tag.hasKey(CraftMetaBook.BOOK_TITLE.NBT)) { + tag.setString(CraftMetaBook.BOOK_TITLE.NBT, ""); + } + if (!tag.hasKey(CraftMetaBook.BOOK_AUTHOR.NBT)) { + tag.setString(CraftMetaBook.BOOK_AUTHOR.NBT, ""); + } + } + return true; } |