Examples of BookMeta


Examples of org.bukkit.inventory.meta.BookMeta

    if ((e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction()
        .equals(Action.RIGHT_CLICK_BLOCK))
        && e.getPlayer().getItemInHand().getType()
            .equals(Material.WRITTEN_BOOK)) {
      ItemStack inh = e.getPlayer().getItemInHand();
      BookMeta b = (BookMeta) inh.getItemMeta();
      if (b == null)
        return;
      if (!b.hasTitle() || !b.hasAuthor())
        return;
      if (b.getTitle().contains("Identity Tome")
          && findColor(b.getAuthor()).equals(ChatColor.MAGIC)) {
        Player p = e.getPlayer();
        PlayerInventory pi = p.getInventory();
        p.updateInventory();
        Iterator<ItemStack> itis = pi.iterator();
        while (itis.hasNext()) {
View Full Code Here

Examples of org.bukkit.inventory.meta.BookMeta

import org.bukkit.inventory.meta.BookMeta;

public class IdentifyTome extends ItemStack {
  public IdentifyTome() {
    super(Material.WRITTEN_BOOK);
    BookMeta meta = (BookMeta) this.getItemMeta();
    meta.setTitle(ChatColor.DARK_AQUA + "Identity Tome");
    String author = UUID.randomUUID().toString();
    if (author.length() > 16)
      author = author.substring(0, 15);
    meta.setAuthor(ChatColor.MAGIC + author);
    List<String> pages = new ArrayList<String>();
    pages.add(0, ChatColor.MAGIC + author);
    meta.setPages(pages);
    this.setItemMeta(meta);
  }
View Full Code Here

Examples of org.bukkit.inventory.meta.BookMeta

        // we are removing, because we are not relying on
        // Bukkit methods to find matching itemStacks
        int qty = book.getAmount();

        // Store the book's meta information in a variable
        BookMeta bookMeta = (BookMeta) book.getItemMeta();

        for (ItemStack invStack : inventory) {

            if (qty == 0) break;

            if (invStack != null && invStack.getItemMeta() instanceof BookMeta) {

                BookMeta invMeta = (BookMeta) invStack.getItemMeta();

                if (invMeta.getAuthor().equalsIgnoreCase(bookMeta.getAuthor())
                        && invMeta.getTitle().equalsIgnoreCase(bookMeta.getTitle())) {

                    // Make sure we don't remove more books than we
                    // need to
                    if (qty - invStack.getAmount() < 0) {
View Full Code Here

Examples of org.bukkit.inventory.meta.BookMeta

    public String getAttribute(Attribute attribute) {

        if (attribute == null) return "null";

        if (attribute.startsWith("book")) {
            BookMeta bookInfo = (BookMeta) item.getItemStack().getItemMeta();
            attribute = attribute.fulfill(1);

            if (item.getItemStack().getType() == Material.WRITTEN_BOOK) {

                // <--[tag]
                // @attribute <i@item.book.author>
                // @returns Element
                // @mechanism dItem.book
                // @group properties
                // @description
                // Returns the author of the book.
                // -->
                if (attribute.startsWith("author"))
                    return new Element(bookInfo.getAuthor())
                            .getAttribute(attribute.fulfill(1));

                // <--[tag]
                // @attribute <i@item.book.title>
                // @returns Element
                // @mechanism dItem.book
                // @group properties
                // @description
                // Returns the title of the book.
                // -->
                if (attribute.startsWith("title"))
                    return new Element(bookInfo.getTitle())
                            .getAttribute(attribute.fulfill(1));
            }

            // <--[tag]
            // @attribute <i@item.book.page_count>
            // @returns Element(Number)
            // @mechanism dItem.book
            // @group properties
            // @description
            // Returns the number of pages in the book.
            // -->
            if (attribute.startsWith("page_count"))
                return new Element(bookInfo.getPageCount())
                        .getAttribute(attribute.fulfill(1));

            // <--[tag]
            // @attribute <i@item.book.get_page[<#>]>
            // @returns Element
            // @mechanism dItem.book
            // @group properties
            // @description
            // Returns the page specified from the book as an element.
            // -->
            if (attribute.startsWith("get_page") && aH.matchesInteger(attribute.getContext(1)))
                return new Element(bookInfo.getPage(attribute.getIntContext(1)))
                    .getAttribute(attribute.fulfill(1));

            // Deprecated in favor of pages.escape_contents
            if (attribute.startsWith("pages.escaped")) {
                StringBuilder output = new StringBuilder();
                for (String page: bookInfo.getPages()) {
                    output.append(EscapeTags.Escape(page)).append("|");
                }
                return new dList(output.length() > 0 ?
                        output.substring(0, output.length() - 1): output.toString())
                        .getAttribute(attribute.fulfill(2));
            }

            // <--[tag]
            // @attribute <i@item.book.pages>
            // @returns dList
            // @mechanism dItem.book
            // @group properties
            // @description
            // Returns the pages of the book as a dList.
            // -->
            if (attribute.startsWith("pages"))
                return new dList(bookInfo.getPages())
                        .getAttribute(attribute.fulfill(1));

            // <--[tag]
            // @attribute <i@item.book>
            // @returns Element
View Full Code Here

Examples of org.bukkit.inventory.meta.BookMeta


    @Override
    public String getPropertyString() {
        StringBuilder output = new StringBuilder();
        BookMeta bookInfo = (BookMeta) item.getItemStack().getItemMeta();
        if (item.getItemStack().getType().equals(Material.WRITTEN_BOOK)
                && bookInfo.hasAuthor() && bookInfo.hasTitle()) {
            output.append("author|").append(EscapeTags.Escape(bookInfo.getAuthor()))
                    .append("|title|").append(EscapeTags.Escape(bookInfo.getTitle())).append("|");
        }
        output.append("pages|");
        if (bookInfo.hasPages()) {
            for (String page: bookInfo.getPages()) {
                output.append(EscapeTags.Escape(page)).append("|");
            }
        }
        if (output.length() <= 6)
            return null;
View Full Code Here

Examples of org.bukkit.inventory.meta.BookMeta

        // <i@item.book.pages>
        // <i@item.book>
        // -->

        if (mechanism.matches("book")) {
            BookMeta meta = (BookMeta) item.getItemStack().getItemMeta();
            dList data = mechanism.getValue().asType(dList.class);
            if (data.size() < 2) {
                dB.echoError("Invalid book input!");
            }
            else {
                if (data.size() > 4 && data.get(0).equalsIgnoreCase("author")
                        && data.get(2).equalsIgnoreCase("title")) {
                    if (!item.getItemStack().getType().equals(Material.WRITTEN_BOOK)) {
                        dB.echoError("That type of book cannot have title or author!");
                    }
                    else {
                        meta.setAuthor(EscapeTags.unEscape(data.get(1)));
                        meta.setTitle(EscapeTags.unEscape(data.get(3)));
                        for (int i = 0; i < 4; i++)
                            data.remove(0); // No .removeRange?
                    }
                }
                if (!data.get(0).equalsIgnoreCase("pages")) {
                    dB.echoError("Invalid book input!");
                }
                else {
                    ArrayList<String> newPages = new ArrayList<String>();
                    for (int i = 1; i < data.size(); i++) {
                        newPages.add(EscapeTags.unEscape(data.get(i)));
                    }
                    meta.setPages(newPages);
                }
                item.getItemStack().setItemMeta(meta);
            }
        }
    }
View Full Code Here

Examples of org.bukkit.inventory.meta.BookMeta

        return writeBookTo(stack, player, npc);
    }

    public dItem writeBookTo(dItem book, dPlayer player, dNPC npc) {
        // Get current ItemMeta from the book
        BookMeta bookInfo = (BookMeta) book.getItemStack().getItemMeta();

        if (contains("TITLE")) {
            String title = getString("TITLE");
            title = TagManager.tag(player, npc, title, false, null, dB.shouldDebug(this), new dScript(this));
            bookInfo.setTitle(title);
        }

        if (contains("SIGNED")) {
            if (getString("SIGNED").equalsIgnoreCase("false")) {
                book.getItemStack().setType(Material.BOOK_AND_QUILL);
            }
        }

        if (contains("AUTHOR")) {
            String author = getString("AUTHOR");
            author = TagManager.tag(player, npc, author, false);
            bookInfo.setAuthor(author);
        }

        if (contains("TEXT")) {
            List<String> pages = getStringList("TEXT");

            for (String page : pages) {
                page = TagManager.tag(player, npc, page, false, null, dB.shouldDebug(this), new dScript(this));
                bookInfo.addPage(page);
            }
        }

        book.getItemStack().setItemMeta(bookInfo);
        return book;
View Full Code Here

Examples of org.bukkit.inventory.meta.BookMeta

            item = itemStack.getType();
            quantity = itemStack.getAmount();
            durability = itemStack.getDurability();
            enchantments = itemStack.getEnchantments();
            if(itemStack.getItemMeta() instanceof BookMeta) {
                BookMeta meta = (BookMeta) itemStack.getItemMeta();
                // Make sure we don't use this on an empty book!
                if(meta.getPages() != null) {
                    book = new MIBook(meta.getAuthor(), meta.getTitle(), meta.getPages());
                }
            } else if(itemStack.hasItemMeta()) {
                nbttags = getItemMetaSerialized(itemStack.getItemMeta());
            }
            is = itemStack.clone();
View Full Code Here

Examples of org.bukkit.inventory.meta.BookMeta

        ItemStack itemStack = null;
        if(item != Material.AIR && quantity != 0) {
            itemStack = new ItemStack(item, quantity, durability);
            itemStack.addUnsafeEnchantments(enchantments);
            if((item == Material.BOOK_AND_QUILL || item == Material.WRITTEN_BOOK) && book != null) {
                BookMeta bi = (BookMeta) itemStack.getItemMeta();
                bi.setAuthor(book.getAuthor());
                bi.setTitle(book.getTitle());
                bi.setPages(book.getPages());
                itemStack.setItemMeta(bi);
                return itemStack;
            } else if(nbttags != null) {
                return addItemMeta(itemStack, nbttags);
            }
View Full Code Here

Examples of org.bukkit.inventory.meta.BookMeta

                }
                ItemMeta meta = item.getItemMeta();
                if (!(meta instanceof BookMeta)) {
                    return;
                }
                BookMeta book = (BookMeta) meta;
                if (!book.hasPages()) {
                    return;
                }

                // verify item in hand
                ItemStack inHand = session.getPlayer().getItemInHand();
                if (inHand == null || inHand.getType() != Material.BOOK_AND_QUILL) {
                    return;
                }
                ItemMeta handMeta = inHand.getItemMeta();
                if (!(handMeta instanceof BookMeta)) {
                    return;
                }
                BookMeta handBook = (BookMeta) handMeta;

                // apply pages to book
                handBook.setPages(book.getPages());
                inHand.setItemMeta(handBook);
                session.getPlayer().setItemInHand(inHand);
                break;
            }
            case "MC|BSign": {
                // read and verify stack
                ItemStack item = GlowBufUtils.readSlot(buf);
                //GlowServer.logger.info("BookSign [" + session.getPlayer().getName() + "]: " + item);
                if (item == null || item.getType() != Material.WRITTEN_BOOK) {
                    return;
                }
                ItemMeta meta = item.getItemMeta();
                if (!(meta instanceof BookMeta)) {
                    return;
                }
                BookMeta book = (BookMeta) meta;
                if (!book.hasPages() || !book.hasTitle()) {
                    return;
                }

                // verify item in hand
                ItemStack inHand = session.getPlayer().getItemInHand();
                if (inHand == null || inHand.getType() != Material.BOOK_AND_QUILL) {
                    return;
                }
                ItemMeta handMeta = inHand.getItemMeta();
                if (!(handMeta instanceof BookMeta)) {
                    return;
                }
                BookMeta handBook = (BookMeta) handMeta;

                // apply pages, title, and author to book
                handBook.setAuthor(session.getPlayer().getName());
                handBook.setTitle(book.getTitle());
                handBook.setPages(book.getPages());
                inHand.setType(Material.WRITTEN_BOOK);
                inHand.setItemMeta(handBook);
                session.getPlayer().setItemInHand(inHand);
                break;
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.