java类org.bukkit.inventory.meta.BookMeta的实例源码

ItemBuilder.java 文件源码 项目:SupaCommons 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
FileManager.java 文件源码 项目:Breakpoint 阅读 27 收藏 0 点赞 0 评论 0
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;
}
FileManager.java 文件源码 项目:Breakpoint 阅读 23 收藏 0 点赞 0 评论 0
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();
        }
    }
}
CraftEventFactory.java 文件源码 项目:Craftbukkit 阅读 24 收藏 0 点赞 0 评论 0
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));
    }
}
DebugCommand.java 文件源码 项目:kosmos 阅读 21 收藏 0 点赞 0 评论 0
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 );

    }
BookUtil.java 文件源码 项目:civcraft 阅读 20 收藏 0 点赞 0 评论 0
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);
}
BookUtil.java 文件源码 项目:civcraft 阅读 17 收藏 0 点赞 0 评论 0
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);
}
CraftEventFactory.java 文件源码 项目:Almura-Server 阅读 26 收藏 0 点赞 0 评论 0
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));
    }
}
BookAPI.java 文件源码 项目:TosoGame3 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 「逃走中」というタイトルの本に対してページを追加できます。<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);
                    }
                }
            }
        }
    }
}
BookAPI.java 文件源码 项目:TosoGame3 阅读 20 收藏 0 点赞 0 评论 0
/**
 * ミッション告知用の本の内容をすべて削除します。
 */
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);
                }
            }
        }
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号