Class WritableBookBuilder

java.lang.Object
io.github.lucfr1746.llibrary.itemstack.ItemBuilder
io.github.lucfr1746.llibrary.itemstack.WritableBookBuilder
Direct Known Subclasses:
BookBuilder

public class WritableBookBuilder extends ItemBuilder
The WritableBookBuilder class extends ItemBuilder to provide additional functionality for modifying WritableBookMeta of an ItemStack. This class allows adding, setting, and retrieving pages in writable books.
  • Constructor Details

    • WritableBookBuilder

      public WritableBookBuilder()
      Constructs a WritableBookBuilder with a new Material.WRITABLE_BOOK.
    • WritableBookBuilder

      public WritableBookBuilder(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
      Constructs a WritableBookBuilder using an existing ItemStack.
      Parameters:
      itemStack - the item stack to modify
      Throws:
      IllegalArgumentException - if the item's meta is not an instance of WritableBookMeta
  • Method Details

    • addPage

      public WritableBookBuilder addPage(@NotNull @NotNull String... pages)
      Adds new pages to the end of the book.
      Parameters:
      pages - the pages to add
      Returns:
      this WritableBookBuilder instance for method chaining
    • getPage

      public String getPage(int page)
      Gets the specified page in the book.
      Parameters:
      page - the page number (1-based index)
      Returns:
      the content of the specified page
      Throws:
      IndexOutOfBoundsException - if the page number is invalid
    • getPageCount

      public int getPageCount()
      Gets the number of pages in the book.
      Returns:
      the number of pages
    • getPages

      public List<String> getPages()
      Gets all the pages in the book.
      Returns:
      a list of pages
    • hasPages

      public boolean hasPages()
      Checks if the book has any pages.
      Returns:
      true if the book has pages, false otherwise
    • setPage

      public WritableBookBuilder setPage(int page, @NotNull @NotNull String content)
      Sets the content of a specific page.
      Parameters:
      page - the page number (1-based index)
      content - the content to set
      Returns:
      this WritableBookBuilder instance for method chaining
      Throws:
      IndexOutOfBoundsException - if the page number is invalid
    • setPages

      public WritableBookBuilder setPages(@NotNull @NotNull String... pages)
      Sets the pages of the book, replacing any existing pages.
      Parameters:
      pages - the pages to set
      Returns:
      this WritableBookBuilder instance for method chaining
    • setPages

      public WritableBookBuilder setPages(@NotNull @NotNull List<String> pages)
      Sets the pages of the book using a list, replacing any existing pages.
      Parameters:
      pages - the list of pages to set
      Returns:
      this WritableBookBuilder instance for method chaining
    • clearPages

      public WritableBookBuilder clearPages()
      Clears all pages in the book.
      Returns:
      this WritableBookBuilder instance for method chaining