1.16.5 Open book at certain page?

Discussion in 'Spigot Plugin Development' started by TaskID, Dec 4, 2020.

  1. Hello,

    so there's the player.openBook(ItemStack); method. I was wondering if there is any option to open a book for a player at a certain page, so it could be like player.openBook(ItemStack, Page);
    But that method doesn't exist (would be nice tbh).
    Is there another option to do this?
     
  2. The problem is that books are client-side, so there is no way to actually set the page. What you can do is use the BookMeta class to set the page you want as the first page. Something along the lines of
    Code (Text):
    bookMeta.setPage(1,bookMeta.getPage(page1));
     
  3. Maybe abuse the lectern for this? It stores the page it's on anyway.

    I've yoinked a bit of WesJD's AnvilGUI code and modified it to work with lecterns, in case you're interested in that approach.
    LecternGUI.class
    Wrapper_1_16_R3.class
    Usage: new LecternGUI(plugin, player, bookItem, page);

    It's NMS and version dependent. However, if you take a look at how WesJD solved it with wrappers for each version, you should be able to achieve the same if you need multi-version support.
     
    #3 Gadse, Dec 5, 2020
    Last edited: Dec 5, 2020
    • Informative Informative x 1