1.16.5 how do I open a lectern to a player when he presses a sign?

Discussion in 'Spigot Plugin Development' started by FlameFOxYT, Jun 16, 2021.

  1. I don't know how to make a custom lectern inventory,
    if there is a formal way of making a lectern inventory like GUI, i would love if you can help me.
    I know how to detect when a player presses a sign, but not how to remotely open a lectern.
  2. You can create a custom lectern inventory using Bukkit#createInventory(InventoryHolder owner, InventoryType type), where owner = null and type = LECTERN.
    Then, simply open the inventory for the player using Player#openInventory(Inventory inventory).

    Code (Java):
    final Inventory inv = Bukkit.createInventory(null, InventoryType.LECTERN);
  3. Thanks, it works but I don't know how to edit the book inside it,
    Question, is it possible to change the book contents, as well as change the page the player is in with code?
    if so then how do i do that
  4. If you're just looking to open a book for a player, you can use https://hub.spigotmc.org/javadocs/b...html#openBook(org.bukkit.inventory.ItemStack)
    As for turning the pages, I'm not sure. It might be easier to open a new book with the desired information (since you just need an itemstack for the method).
  5. Also, if you want to use the lectern inventory approach, to edit the book inside it, you need to create a book itemstack, then set title and author, and then add pages. Then you need to put the book itemstack in the lectern inventory. Code below:
    Code (Java):
    Inventory inv = Bukkit.createInventory(null, InventoryType.LECTERN);
    ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta bookMeta = (BookMeta) book.getItemMeta();
    bookMeta.addPage("Example Page Text");
    bookMeta.setTitle("Example Title");
    inv.setItem(0, book);
  6. Im trying to do an animation that adds a letter every tick, until it shows the entire text,
    hmm, ill try thanks