From 9310a0203e63b368061b1c636ff476e49dfe75fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Sun, 18 Aug 2019 17:42:30 +0800 Subject: [PATCH] update --- .../taboolib/util/book/BookFormatter.java | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/scala/io/izzel/taboolib/util/book/BookFormatter.java b/src/main/scala/io/izzel/taboolib/util/book/BookFormatter.java index 832fe00..2fe12a1 100644 --- a/src/main/scala/io/izzel/taboolib/util/book/BookFormatter.java +++ b/src/main/scala/io/izzel/taboolib/util/book/BookFormatter.java @@ -2,24 +2,19 @@ package io.izzel.taboolib.util.book; import io.izzel.taboolib.module.nms.NMS; import io.izzel.taboolib.util.book.builder.BookBuilder; +import io.izzel.taboolib.util.book.builder.PageBuilder; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.List; + /** * @author unknown * @recode 2019-8-18 16:40:16 */ public class BookFormatter { - public static BookBuilder writtenBook() { - return new BookBuilder(new ItemStack(Material.WRITTEN_BOOK)); - } - - public static BookBuilder writtenBook(String title, String author) { - return new BookBuilder(new ItemStack(Material.WRITTEN_BOOK), title, author); - } - public static void forceOpen(Player player, ItemStack book) { ItemStack hand = player.getItemInHand(); player.setItemInHand(book); @@ -30,4 +25,33 @@ public class BookFormatter { } player.setItemInHand(hand); } + + public static BookBuilder writtenBook() { + return new BookBuilder(new ItemStack(Material.WRITTEN_BOOK)); + } + + public static BookBuilder writtenBook(String title, String author) { + return new BookBuilder(new ItemStack(Material.WRITTEN_BOOK), title, author); + } + + public static ItemStack writeToBook(List lines) { + BookBuilder bookBuilder = BookFormatter.writtenBook(); + PageBuilder builder = null; + int index = 0; + for (String line : lines) { + if (builder == null) { + builder = new PageBuilder(); + } + builder.add(line).newLine(); + if (index++ == 13) { + bookBuilder.addPages(builder.build()); + builder = null; + index = 0; + } + } + if (builder != null) { + bookBuilder.addPages(builder.build()); + } + return bookBuilder.build(); + } }