Maploop / DnumFramework

Just a simple framework containing useful and nice libraries!
Apache License 2.0
4 stars 2 forks source link

Added Book Support and Fixed Tablist #5

Closed Swofty-Developments closed 3 years ago

Swofty-Developments commented 3 years ago

` public static void openBook(ItemStack book, Player p) { int slot = p.getInventory().getHeldItemSlot(); ItemStack old = p.getInventory().getItem(slot); p.getInventory().setItemInMainHand(book);

    ByteBuf buf = Unpooled.buffer(256);
    buf.setByte(0, slot);
    buf.writerIndex(1);
    PacketPlayOutOpenBook packet = new PacketPlayOutOpenBook(EnumHand.MAIN_HAND);
    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
    System.out.println("sent");
    p.getInventory().setItem(slot, old);
}

@SneakyThrows
public static ItemStack makeBook(String title, String author, String[] text) {
    ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta meta = (BookMeta) book.getItemMeta();

    for (String page : text) {
        meta.addPage(page);
    }

    meta.setTitle("Example");
    meta.setAuthor("Server");
    book.setItemMeta(meta);

    return book;
}`

makeBook method is pog, fixed tablist aswell.