Guest User

Untitled

a guest
Mar 21st, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. public static IntFunction<Inventory> Guide(List<Category> categories, Plugin plugin, int rows) {
  2. final MiniWindow window = new MiniWindow(plugin);
  3. final List<Supplier<Inventory>> pages = new ArrayList<>();
  4. final List<List<Category>> partitions = partition(categories, rows * 9);
  5. pages.addAll(mapWithIndex(partitions.stream(), (categoryList, index) ->
  6. cache(() -> window.page(page -> {
  7. //Title the page.
  8. page.title("Page " + index);
  9.  
  10. //Add items for each category on the page.
  11. categoryList.forEach(category -> {
  12. //Create a new item for the category.
  13. Item item = page.element();
  14.  
  15. //Let the category style it.
  16. category.itemLike().accept(item);
  17.  
  18. //Cache the category's page as well.
  19. Supplier<Inventory> categoryPage = cache(() ->
  20. window.page(category.pageLike())
  21. );
  22.  
  23. //Open the category's page when it's icon is clicked.
  24. item.onClick(player ->
  25. player.openInventory(categoryPage.get())
  26. );
  27. });
  28.  
  29. //Footer time.
  30. for (int i = 0; i < 9; i++) {
  31. Item item = page.element(rows + 1).icon(STAINED_GLASS_PANE);
  32. if (index != 0 && i == 2)
  33. item.data(RED.getDyeData()).onClick(player ->
  34. //Navigate back one page.
  35. player.openInventory(pages.get((int) (index - 1)).get())
  36. );
  37. else if (index != partitions.size() - 1 && i == 6)
  38. item.data(GREEN.getDyeData()).onClick(player ->
  39. //Navigate forward one page.
  40. player.openInventory(pages.get((int) (index + 1)).get())
  41. );
  42. else
  43. item.data(GRAY.getDyeData());
  44. }
  45. }))
  46. ).collect(toList()));
  47.  
  48. return index -> pages.get(index).get();
  49. }
Add Comment
Please, Sign In to add comment