Java 类org.bukkit.inventory.meta.BookMeta 实例源码

项目:CraftBukkit    文件:CraftEventFactory.java   
public static void handleEditBookEvent(EntityPlayer player, ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.itemInHandIndex;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.itemInHandIndex, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getItemInHand()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == Items.WRITTEN_BOOK);
    player.world.getServer().getPluginManager().callEvent(editBookEvent);
    ItemStack itemInHand = player.inventory.getItem(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == Items.BOOK_AND_QUILL) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.setItem(Items.WRITTEN_BOOK);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        Slot slot = player.activeContainer.getSlot(player.inventory, itemInHandIndex);
        player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.activeContainer.windowId, slot.rawSlotIndex, itemInHand));
    }
}
项目:NexusInventory    文件:BookSerialization.java   
/**
 * Gets a JSONObject representation of a BookMeta. Book and Quills books will have a pages key, while
 * finished, written, books will also have an author and title key.
 *
 * @param meta The BookMeta to serialize
 * @return A JSON Representation of the give BookMeta
 */
public static JSONObject serializeBookMeta(BookMeta meta) {
    try {
        JSONObject root = new JSONObject();
        if (meta.hasTitle())
            root.put("title", meta.getTitle());
        if (meta.hasAuthor())
            root.put("author", meta.getAuthor());
        if (meta.hasPages()) {
            String[] pages = meta.getPages().toArray(new String[]{});
            root.put("pages", pages);
        }
        return root;
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
}
项目:Uranium    文件:CraftEventFactory.java   
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
项目:MystiCraft    文件:SpellTome.java   
public static ItemStack getSpellTome(String label, Player crafter) {
    ItemStack i = new ItemStack(MATERIAL);
    Spell spell = MystiCraft.getSpellManager().getSpell(label);
    BookMeta meta = (BookMeta)i.getItemMeta();
    meta.setDisplayName(DISPLAY_NAME + StringUtils.capitalize(label));
    if (crafter != null)
        meta.setAuthor(crafter.getName());
    else
        meta.setAuthor("unknown");
    meta.setGeneration(Generation.TATTERED);
    meta.setLore(Arrays.asList(new String[]{ChatColor.GRAY + spell.getDescription(), ChatColor.GRAY + "Mana Cost: " + spell.getManaCost()}));
    // TODO Add description
    meta.addPage("-------------------=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
    i.setItemMeta(meta);
    return i;
}
项目:FactionsXL    文件:FBull.java   
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    Location location = player.getLocation();
    ItemStack item = event.getItem();
    if (isBull(item) && event.getAction() == Action.RIGHT_CLICK_AIR | event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (!FactionsXL.getInstance().getBoard().isAnnexable(location)) {
            ParsingUtil.sendMessage(player, FMessage.ERROR_LAND_NOT_FOR_SALE.getMessage());
            return;
        }
        FactionCache factions = FactionsXL.getInstance().getFactionCache();
        BookMeta meta = ((BookMeta) item.getItemMeta());
        String title = meta.getTitle().replace(" ", "-");
        if (factions.getByName(title) != null) {
            title += NumberUtil.generateRandomInt(0, 100);
        }
        FireworkUtil.spawnRandom(location);
        FactionsXL.getInstance().getFactionCache().create(player, title);
        player.getInventory().remove(item);
    }
}
项目:Kineticraft    文件:ItemBook.java   
@Override
public void updateItem() {

    if (getTitle() != null)
        getMeta().setTitle(getTitle());
    if (getAuthor() != null)
        getMeta().setAuthor(getAuthor());

    getMeta().setPages(new ArrayList<>()); // A book needs its page tag, so we'll default to an empty one.
    if (isWriteLines())// Save the book pages to the item.
        getMeta().pages.addAll(getPages().stream().map(TextBuilder::create)
                .map(TextUtils::toNMSComponent).collect(Collectors.toList()));

    if (getMeta().pages.isEmpty()) // Allow the book to be opened / editted.
        getMeta().addPage("");

    getMeta().setGeneration(BookMeta.Generation.TATTERED);
    this.page = 0; // Reset writer.
}
项目:PA    文件:ItemUtil.java   
public static ItemStack createBook(String name, List<String> lore, String... pages) {
    ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta meta = (BookMeta) book.getItemMeta();
    ItemMeta bookMeta = book.getItemMeta();

    bookMeta.setDisplayName(Utils.colorize(name));
    ArrayList<String> colorLore = new ArrayList<>();
    if (lore != null) lore.forEach(str -> colorLore.add(Utils.colorize(str)));
    bookMeta.setLore(colorLore);

    meta.addPage(pages);
    meta.setAuthor(Utils.colorize("&6ProjectAlpha"));

    book.setItemMeta(bookMeta);

    return book;
}
项目:ThermosRebased    文件:CraftEventFactory.java   
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
项目:Arcade2    文件:XMLItemMeta.java   
public static ItemMeta parse(Element xml, ItemMeta source) {
    if (source instanceof BannerMeta) {
        return parseBanner(xml, (BannerMeta) source);
    } else if (source instanceof BookMeta) {
        return parseBook(xml, (BookMeta) source);
    } else if (source instanceof EnchantmentStorageMeta) {
        return parseEnchantmentStorage(xml, (EnchantmentStorageMeta) source);
    } else if (source instanceof FireworkMeta) {
        return parseFirework(xml, (FireworkMeta) source);
    } else if (source instanceof FireworkEffectMeta) {
        return parseFireworkEffect(xml, (FireworkEffectMeta) source);
    } else if (source instanceof LeatherArmorMeta) {
        return parseLeatherArmor(xml, (LeatherArmorMeta) source);
    } else if (source instanceof MapMeta) {
        return parseMap(xml, (MapMeta) source);
    } else if (source instanceof PotionMeta) {
        return parsePotion(xml, (PotionMeta) source);
    } else if (source instanceof SkullMeta) {
        return parseSkull(xml, (SkullMeta) source);
    } else if (source instanceof SpawnEggMeta) {
        return parseSpawnEgg(xml, (SpawnEggMeta) source);
    }

    return source;
}
项目:Arcade2    文件:XMLItemMeta.java   
public static BookMeta parseBook(Element xml, BookMeta source) {
    Element book = xml.getChild("book");
    if (book != null) {
        Attribute author = book.getAttribute("author");
        if (author != null) {
            source.setAuthor(parseMessage(author.getValue()));
        }

        Attribute title = book.getAttribute("title");
        if (title != null) {
            source.setTitle(parseMessage(title.getValue()));
        }

        for (Element page : book.getChildren("page")) {
            source.addPage(parseMessage(page.getTextNormalize()));
        }
    }

    return source;
}
项目:Breakpoint    文件:FileManager.java   
public static BookMeta loadWikiBook(BookMeta im)
{
    String path = "plugins/Breakpoint/wikiBook/";
    List<String> contents = new ArrayList<String>();
    int page = 0;
    File file = new File(path + page + ".txt");
    while (file.exists())
    {
        String pageContent = getString(file);
        contents.add(pageContent);
        page++;
        file = new File(path + page + ".txt");
    }
    im.setPages(contents);

    return im;
}
项目:Breakpoint    文件:FileManager.java   
public static void saveWikiBook()
{
    String path = "plugins/Breakpoint/wikiBook/";
    BookMeta im = (BookMeta) InventoryMenuManager.wikiBook.getItemMeta();
    List<String> contents = im.getPages();
    for (int page = 0; page < contents.size(); page++)
    {
        File file = new File(path + page + ".txt");
        File pathFile = new File(path);
        pathFile.mkdirs();
        try
        {
            if (!file.exists())
                file.createNewFile();
            setString(file, contents.get(page));
        }
        catch (IOException e)
        {
            Breakpoint.warn("Wiki book did not save properly.");
            e.printStackTrace();
        }
    }
}
项目:CS-CoreLib    文件:CustomBookOverlay.java   
public CustomBookOverlay(String title, String author, TellRawMessage... pages) {
    this.book = new ItemStack(Material.WRITTEN_BOOK);

    BookMeta meta = (BookMeta) this.book.getItemMeta();
    meta.setTitle(title);
    meta.setAuthor(author);

    for (TellRawMessage page: pages) {
        try {
            addPage(meta, page);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    this.book.setItemMeta(meta);
}
项目:QuestManager    文件:QuestManager.java   
@EventHandler
public void onItemPickup(PlayerPickupItemEvent e) {

    if (e.isCancelled()) {
        return;
    }

    ItemStack item = e.getItem().getItemStack();

    if (item.getType().equals(Material.WRITTEN_BOOK)) {
        BookMeta meta = (BookMeta) item.getItemMeta();

        if (meta.getTitle().equals("Quest Log")) {
            e.getItem().remove();
            e.setCancelled(true);

            QuestManagerPlugin.questManagerPlugin.getPlayerManager().getPlayer(
                    e.getPlayer().getUniqueId()).addQuestBook();

        }
    }

}
项目:NyaaUtils    文件:CommandHandler.java   
@SubCommand(value = "setbookauthor", permission = "nu.setbook")
public void setbookauthor(CommandSender sender, Arguments args) {
    if (!(args.length() > 1)) {
        msg(sender, "manual.setbookauthor.usage");
        return;
    }
    String author = args.next();
    Player p = asPlayer(sender);
    author = ChatColor.translateAlternateColorCodes('&', author);
    ItemStack item = p.getInventory().getItemInMainHand();
    if (item == null || !item.getType().equals(Material.WRITTEN_BOOK)) {
        msg(sender, "user.setbook.no_book");
        return;
    }
    BookMeta meta = (BookMeta) item.getItemMeta();
    meta.setAuthor(author);
    item.setItemMeta(meta);
    msg(sender, "user.setbook.success");
}
项目:NyaaUtils    文件:CommandHandler.java   
@SubCommand(value = "setbooktitle", permission = "nu.setbook")
public void setbooktitle(CommandSender sender, Arguments args) {
    if (!(args.length() > 1)) {
        msg(sender, "manual.setbooktitle.usage");
        return;
    }
    String title = args.next();
    Player p = asPlayer(sender);
    title = ChatColor.translateAlternateColorCodes('&', title);

    ItemStack item = p.getInventory().getItemInMainHand();
    if (item == null || !item.getType().equals(Material.WRITTEN_BOOK)) {
        msg(sender, "user.setbook.no_book");
        return;
    }
    BookMeta meta = (BookMeta) item.getItemMeta();
    meta.setTitle(title);
    item.setItemMeta(meta);
    msg(sender, "user.setbook.success");
}
项目:NyaaUtils    文件:CommandHandler.java   
@SubCommand(value = "setbookunsigned", permission = "nu.setbook")
public void setbookunsigned(CommandSender sender, Arguments args) {
    Player p = asPlayer(sender);
    ItemStack item = p.getInventory().getItemInMainHand();
    if (item == null || !item.getType().equals(Material.WRITTEN_BOOK)) {
        msg(sender, "user.setbook.no_book");
        return;
    }
    BookMeta meta = (BookMeta) item.getItemMeta();
    ItemStack newbook = new ItemStack(Material.BOOK_AND_QUILL, 1);
    BookMeta newbookMeta = (BookMeta) newbook.getItemMeta();
    newbookMeta.setPages(meta.getPages());
    newbook.setItemMeta(newbookMeta);
    p.getInventory().setItemInMainHand(newbook);
    msg(sender, "user.setbook.success");
}
项目:Skellett    文件:CondHasTitle.java   
public boolean check(Event e) {
    BookMeta book = (BookMeta) item.getSingle(e).getItemMeta();
    if (book.hasTitle()) {
        if (boo == true) {
            return true;
        } else {
            return false;
        }
    } else {
        if (boo == false) {
            return true;
        } else {
            return false;
        }
    }
}
项目:Skellett    文件:CondHasAuthor.java   
public boolean check(Event e) {
    BookMeta book = (BookMeta) item.getSingle(e).getItemMeta();
    if (book.hasAuthor()) {
        if (boo == true) {
            return true;
        } else {
            return false;
        }
    } else {
        if (boo == false) {
            return true;
        } else {
            return false;
        }
    }
}
项目:Skellett    文件:CondHasGeneration.java   
public boolean check(Event e) {
    BookMeta book = (BookMeta) item.getSingle(e).getItemMeta();
    if (book.hasGeneration()) {
        if (boo == true) {
            return true;
        } else {
            return false;
        }
    } else {
        if (boo == false) {
            return true;
        } else {
            return false;
        }
    }
}
项目:RpgPlus    文件:ItemMatcher.java   
private boolean bookPropertiesMatch(ItemStack itemStack) {
    ItemMeta meta = itemStack.getItemMeta();

    if (meta instanceof BookMeta) {
        BookMeta book = (BookMeta) meta;
        if (bookTitle != null && !bookTitle.equals(book.getTitle())) {
            return false;
        }
        if (bookAuthor != null && !bookAuthor.equals(book.getAuthor())) {
            return false;
        }
        if (bookPages != null && !bookPages.equals(book.getPages())) {
            return false;
        }
    }

    return true;
}
项目:Thermos    文件:CraftEventFactory.java   
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
项目:KCauldron    文件:CraftEventFactory.java   
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
项目:CauldronGit    文件:CraftEventFactory.java   
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
项目:Cauldron-Old    文件:CraftEventFactory.java   
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
项目:Cauldron-Reloaded    文件:CraftEventFactory.java   
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
项目:Zephyr    文件:SpellTome.java   
public static ItemStack getSpellTome(Spell spell, User user) {
    ItemStack stack = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta meta = (BookMeta) stack.getItemMeta();

    StringBuilder page = new StringBuilder();

    page.append("Spell: " + spell.getName() + "\n");
    page.append(spell.getDescription() + "\n");
    page.append("Mana Cost: " + spell.getManaCost());
    page.append("\n\n");
    page.append("Cast this spell with /cast " + WordUtils.capitalize(spell.getName()) + "\n\n");
    page.append("Learn this spell by left clicking the book");

    meta.setPages(page.toString());
    meta.setAuthor(user.<Player> getPlayer().getName());
    meta.setDisplayName(ChatColor.GOLD + "Spell Tome" + ChatColor.GRAY + SEPERATOR
            + WordUtils.capitalize(spell.getName()));
    meta.setLore(Lists.newArrayList(ChatColor.GRAY + "Learn by left clicking"));
    stack.setItemMeta(meta);
    return stack;
}
项目:AdvancedAchievements    文件:BookCommand.java   
/**
 * Adds pages to the BookMeta. A Spigot commit in the late days of Minecraft 1.11.2 started enforcing extremely low
 * limits (why? If it's not broken, don't fix it.), with books limited in page size and total number of pages, as
 * well as title length. This function bypasses such limits and restores the original CraftBukkit behaviour. See
 * https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/commits/4acd0f49e07e0912096e79494472535baf0db2ab
 * for more information.
 *
 * @param bookPages
 * @param bookMeta
 */
@SuppressWarnings("unchecked")
private void setBookPages(List<String> bookPages, BookMeta bookMeta) {
    if (plugin.getServerVersion() >= 11) {
        try {
            // Code we're trying to execute: this.pages.add(CraftChatMessage.fromString(page, true)[0]); in
            // CraftMetaBook.java.
            Class<?> craftMetaBookClass = PackageType.CRAFTBUKKIT
                    .getClass(PACKAGE_INVENTORY + "." + CLASS_CRAFT_META_BOOK);
            List<Object> pages = (List<Object>) craftMetaBookClass.getField(FIELD_PAGES)
                    .get(craftMetaBookClass.cast(bookMeta));
            Method fromStringMethod = PackageType.CRAFTBUKKIT
                    .getClass(PACKAGE_UTIL + "." + CLASS_CRAFT_CHAT_MESSAGE)
                    .getMethod(METHOD_FROM_STRING, String.class, boolean.class);
            for (String bookPage : bookPages) {
                pages.add(((Object[]) fromStringMethod.invoke(null, bookPage, true))[0]);
            }
        } catch (Exception e) {
            plugin.getLogger().warning(
                    "Error while creating book pages. Your achievements book may be trimmed down to 50 pages.");
            bookMeta.setPages(bookPages);
        }
    } else {
        bookMeta.setPages(bookPages);
    }
}
项目:FFoKC    文件:CraftEventFactory.java   
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.func_150996_a(net.minecraft.init.Items.written_book);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
项目:SupaCommons    文件:ItemBuilder.java   
/**
 * Sets this book's pages, assuming it is a book.
 * <p />
 * <b>Note: This is a clear and write operation, for appending, see {@link
 * #bookAdd(String...)}</b>
 * <p />
 * <b>UNSAFE</b>
 *
 * @param pages pages to set
 *
 * @return this item builder instance, for chaining
 */
public ItemBuilder bookSet(@Nonnull String... pages) {
  if (pages == null) {
    if (!this.failSilently) {
      throw new IllegalArgumentException("pages cannot be null.");
    }
    return this;
  }
  if (isBookMeta()) {
    try {
      ((BookMeta) this.itemMeta).setPages(pages);
    } catch (Exception e) {
      if (!this.failSilently) {
        e.printStackTrace();
      }
    }
  }
  return this;
}
项目:SupaCommons    文件:ItemBuilder.java   
/**
 * Adds pages to this book, assuming it is a book.
 * <p />
 * <b>UNSAFE</b>
 *
 * @param pages pages to add
 *
 * @return this item builder instance, for chaining
 */
public ItemBuilder bookAdd(@Nonnull String... pages) {
  if (pages == null) {
    if (!this.failSilently) {
      throw new IllegalArgumentException("pages cannot be null.");
    }
    return this;
  }
  if (isBookMeta()) {
    try {
      ((BookMeta) this.itemMeta).addPage(pages);
    } catch (Exception e) {
      if (!this.failSilently) {
        e.printStackTrace();
      }
    }
  }
  return this;
}
项目:Breakpoint    文件:FileManager.java   
public static BookMeta loadWikiBook(BookMeta im)
{
    String path = "plugins/Breakpoint/wikiBook/";
    List<String> contents = new ArrayList<String>();
    int page = 0;
    File file = new File(path + page + ".txt");
    while (file.exists())
    {
        String pageContent = getString(file);
        contents.add(pageContent);
        page++;
        file = new File(path + page + ".txt");
    }
    im.setPages(contents);

    return im;
}
项目:Breakpoint    文件:FileManager.java   
public static void saveWikiBook()
{
    String path = "plugins/Breakpoint/wikiBook/";
    BookMeta im = (BookMeta) InventoryMenuManager.wikiBook.getItemMeta();
    List<String> contents = im.getPages();
    for (int page = 0; page < contents.size(); page++)
    {
        File file = new File(path + page + ".txt");
        File pathFile = new File(path);
        pathFile.mkdirs();
        try
        {
            if (!file.exists())
                file.createNewFile();
            setString(file, contents.get(page));
        }
        catch (IOException e)
        {
            Breakpoint.warn("Wiki book did not save properly.");
            e.printStackTrace();
        }
    }
}
项目:Craftbukkit    文件:CraftEventFactory.java   
public static void handleEditBookEvent(EntityPlayer player, ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.itemInHandIndex;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.itemInHandIndex, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getItemInHand()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == Items.WRITTEN_BOOK);
    player.world.getServer().getPluginManager().callEvent(editBookEvent);
    ItemStack itemInHand = player.inventory.getItem(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == Items.WRITABLE_BOOK) {
        if (!editBookEvent.isCancelled()) {
            if (editBookEvent.isSigning()) {
                itemInHand.setItem(Items.WRITTEN_BOOK);
            }
            CraftMetaBook meta = (CraftMetaBook) editBookEvent.getNewBookMeta();
            List<IChatBaseComponent> pages = meta.pages;
            for (int i = 0; i < pages.size(); i++) {
                pages.set(i, stripEvents(pages.get(i)));
            }
            CraftItemStack.setItemMeta(itemInHand, meta);
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        Slot slot = player.activeContainer.getSlot(player.inventory, itemInHandIndex);
        player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.activeContainer.windowId, slot.rawSlotIndex, itemInHand));
    }
}
项目:kosmos    文件:DebugCommand.java   
private void sendBook( CommandSender sender, String title, List<String> pages ) {

        if ( !(sender instanceof Player) ) {
            sender.sendMessage( ChatColor.YELLOW + "We are unable to give you a debug book. :(" );
            return;
        }

        pages = pages.stream().map( page -> ChatColor.translateAlternateColorCodes( '&', page ) ).collect( Collectors.toList() );

        ItemStack is = new ItemStack( Material.WRITTEN_BOOK, 1 );
        BookMeta bookMeta = ((BookMeta) is.getItemMeta());

        bookMeta.setAuthor( ChatColor.GREEN.toString() + ChatColor.BOLD + "Minecraftly" );
        bookMeta.setTitle( ChatColor.GOLD.toString() + ChatColor.BOLD + "Debugging Book || " + title );
        bookMeta.setGeneration( BookMeta.Generation.ORIGINAL );
        bookMeta.setPages( pages );

        is.setItemMeta( bookMeta );

        Player player = ((Player) sender);
        player.getWorld().dropItem( player.getLocation().add( 0, 1, 0 ), is );
        player.playSound( player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1, 1 );

    }
项目:civcraft    文件:BookUtil.java   
public static void paginate(BookMeta meta, String longString) { 
    /* Break page into lines and pass into longString. */
    int count = 0;

    ArrayList<String> lines = new ArrayList<String>();

    String line = "";
    for (char c : longString.toCharArray()) {
        count++;
        if (c == '\n' || count > CHARS_PER_LINE) {
            lines.add(line);
            line = "";
            count = 0;
        }
        if (c != '\n') {
            line += c;
        }
    }

    linePageinate(meta, lines);
}
项目:civcraft    文件:BookUtil.java   
public static void linePageinate(BookMeta meta, ArrayList<String> lines) {
    /*
     * 13 writeable lines per page, iterate through each line
     * and place into the page, when the line count equals 14
     * set it back to 0 and add page.
     */

    int count = 0;
    String page = "";
    for (String line : lines) {
        count++;
        if (count > LINES_PER_PAGE) {
            meta.addPage(page);
            count = 0;
            page = "";
        }
        page += line+"\n";          
    }

    meta.addPage(page);
}
项目:Almura-Server    文件:CraftEventFactory.java   
public static void handleEditBookEvent(EntityPlayer player, ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.itemInHandIndex;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.itemInHandIndex, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getItemInHand()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.id == Item.WRITTEN_BOOK.id);
    player.world.getServer().getPluginManager().callEvent(editBookEvent);
    ItemStack itemInHand = player.inventory.getItem(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand.id == Item.BOOK_AND_QUILL.id) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.id = Item.WRITTEN_BOOK.id;
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        Slot slot = player.activeContainer.a((IInventory) player.inventory, itemInHandIndex);
        player.playerConnection.sendPacket(new Packet103SetSlot(player.activeContainer.windowId, slot.g, itemInHand));
    }
}
项目:TosoGame3    文件:BookAPI.java   
/**
 * 「逃走中」というタイトルの本に対してページを追加できます。<br>
 * 汎用性をあげるために、権限による分別はしていません。(この本を持っている人のみが対象。逃走者以外でも可)
 *     
 * @param msg ミッション告知用の本「逃走中」に追加するページ内容
 */
public void writeBook(String msg) {
    for (Player player : Bukkit.getServer().getOnlinePlayers()) {
        for (ItemStack item : player.getInventory().getContents()) {
            if (item != null) {
                if (item.getType().equals(Material.WRITTEN_BOOK)) {
                    BookMeta meta = (BookMeta) item.getItemMeta();
                    if (meta.getTitle().equals("逃走中")) {
                        meta.addPage(msg);
                        item.setItemMeta(meta);
                    }
                }
            }
        }
    }
}
项目:TosoGame3    文件:BookAPI.java   
/**
 * ミッション告知用の本の内容をすべて削除します。
 */
public void clearBook() {
    for (Player player : Bukkit.getServer().getOnlinePlayers()) {
        for (ItemStack item : player.getInventory().getContents()) {
            if (item == null) {
                return;
            }
            if (item.getType().equals(Material.WRITTEN_BOOK)) {
                BookMeta meta = (BookMeta) item.getItemMeta();
                if (meta.getTitle().equals("逃走中")) {
                    List<String> list = new ArrayList<String>();
                    meta.setPages(list);
                    item.setItemMeta(meta);
                }
            }
        }
    }
}