Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static IntFunction<Inventory> Guide(List<Category> categories, Plugin plugin, int rows) {
- final MiniWindow window = new MiniWindow(plugin);
- final List<Supplier<Inventory>> pages = new ArrayList<>();
- final List<List<Category>> partitions = partition(categories, rows * 9);
- pages.addAll(mapWithIndex(partitions.stream(), (categoryList, index) ->
- cache(() -> window.page(page -> {
- //Title the page.
- page.title("Page " + index);
- //Add items for each category on the page.
- categoryList.forEach(category -> {
- //Create a new item for the category.
- Item item = page.element();
- //Let the category style it.
- category.itemLike().accept(item);
- //Cache the category's page as well.
- Supplier<Inventory> categoryPage = cache(() ->
- window.page(category.pageLike())
- );
- //Open the category's page when it's icon is clicked.
- item.onClick(player ->
- player.openInventory(categoryPage.get())
- );
- });
- //Footer time.
- for (int i = 0; i < 9; i++) {
- Item item = page.element(rows + 1).icon(STAINED_GLASS_PANE);
- if (index != 0 && i == 2)
- item.data(RED.getDyeData()).onClick(player ->
- //Navigate back one page.
- player.openInventory(pages.get((int) (index - 1)).get())
- );
- else if (index != partitions.size() - 1 && i == 6)
- item.data(GREEN.getDyeData()).onClick(player ->
- //Navigate forward one page.
- player.openInventory(pages.get((int) (index + 1)).get())
- );
- else
- item.data(GRAY.getDyeData());
- }
- }))
- ).collect(toList()));
- return index -> pages.get(index).get();
- }
Add Comment
Please, Sign In to add comment