Solved Give player random item via sign

Discussion in 'Spigot Plugin Development' started by Creepermanthe3rd, May 31, 2016.

  1. 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!
  2. First you need to create a book:
    Code (Text):
    ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1);

    BookMeta bookMeta = (BookMeta) book.getItemMeta();

    bookMeta.addPage("Line 1\n" + "Line 2\n");

    Then you add the books to an ArrayList
    Code (Text):
    List<ItemStack> books = new ArrayList<ItemStack>();
    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);
  3. Pretty sure he was talking about enchantment books
    • Agree Agree x 1
  4. I was actually just talking about a BOOK with a name & Lore but thx <3
  5. Then you can just change the ItemMeta exactly how you would with any other item.