Hello, I was wondering if anyone could help me out with what code. So Ive setup signs so if you right-click a certain sing it does nothing atm but I am wondering how I could make it give the player a random book whinch will have a lore on it. Some example books : DoubleXP I, Gears I, Springs I. BTW The I is because the sign has 3 tiers, tier I,II,III. If anyone could help that would be great!
First you need to create a book: Code (Text): ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1); BookMeta bookMeta = (BookMeta) book.getItemMeta(); bookMeta.setTitle("TITLE"); bookMeta.setAuthor("AUTHOR"); bookMeta.addPage("Line 1\n" + "Line 2\n"); book.setItemMeta(bookMeta); Then you add the books to an ArrayList Code (Text): List<ItemStack> books = new ArrayList<ItemStack>(); books.add(book1); books.add(book2); Then you pick random in them and give that to the player Code (Text): int random = new Random().nextInt(books.size()); ItemStack book = books.get(random); player.getInventory().addItem(book);