Search in sources :

Example 6 with PaginatedPane

use of com.github.stefvanschie.inventoryframework.pane.PaginatedPane in project Nodewar by Rosstail.

the class WorldTerritoriesGUIs method initGUI.

public static void initGUI(Player player, Nodewar plugin, World world, ChestGui previousGui) {
    int invSize = 6;
    String display = world.getName() + "'s Territories - Page 1";
    ChestGui gui = new ChestGui(invSize, AdaptMessage.playerMessage(player, display));
    PaginatedPane paginatedPane = new PaginatedPane(0, 0, 9, invSize);
    OutlinePane background = new OutlinePane(0, 0, 9, gui.getRows(), Pane.Priority.LOWEST);
    background.addItem(new GuiItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE)));
    background.setRepeat(true);
    gui.addPane(background);
    int page = 0;
    while (true) {
        StaticPane staticPane = initPane(player, plugin, gui, previousGui, paginatedPane, world, page);
        paginatedPane.addPane(page, staticPane);
        if (staticPane.getItems().size() < 47) {
            // 9 * 5 lines + 2 buttons
            break;
        }
        page++;
    }
    gui.setOnGlobalClick(event -> {
        event.setCancelled(true);
    });
    gui.addPane(paginatedPane);
    gui.show(player);
}
Also used : ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) StaticPane(com.github.stefvanschie.inventoryframework.pane.StaticPane) ItemStack(org.bukkit.inventory.ItemStack)

Example 7 with PaginatedPane

use of com.github.stefvanschie.inventoryframework.pane.PaginatedPane in project buildinggame by stefvanschie.

the class SubjectMenu method initializePages.

/**
 * Initializes the pages for this gui
 *
 * @param gui the gui for which to initialize pages
 * @param paginatedPane the paginated pane
 * @since 5.6.0
 */
private void initializePages(@NotNull ChestGui gui, @NotNull PaginatedPane paginatedPane) {
    paginatedPane.clear();
    for (var page = 0; page < Math.ceil((float) subjects.size() / (paginatedPane.getHeight() * paginatedPane.getLength())); page++) {
        var pane = new OutlinePane(0, 0, paginatedPane.getLength(), paginatedPane.getHeight());
        pane.setOrientation(Orientable.Orientation.valueOf(CONFIG.getString("subject-gui.vote-items.orientation").toUpperCase(Locale.getDefault())));
        for (var index = 0; index < paginatedPane.getLength() * paginatedPane.getHeight(); index++) {
            if (subjects.size() - 1 < index + (page * paginatedPane.getLength() * paginatedPane.getHeight()))
                break;
            final String subject = ChatColor.stripColor(subjects.get(index + (page * paginatedPane.getLength() * paginatedPane.getHeight())));
            if (getSubjectVote(subject) == null)
                votes.add(new SubjectVote(subject, 0));
            Material material = SettingsManager.getInstance().getMaterial("subject-gui.vote-items.item.id", Material.BARRIER);
            var item = new ItemStack(material);
            var meta = item.getItemMeta();
            meta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.subject.name").replace("%subject%", subject)));
            var lores = new ArrayList<String>();
            MESSAGES.getStringList("subject-gui.subject.lores").forEach(lore -> lores.add(MessageManager.translate(lore.replace("%votes%", getSubjectVote(subject).getVotes() + ""))));
            meta.setLore(lores);
            item.setItemMeta(meta);
            pane.addItem(new GuiItem(item, event -> {
                addVote((Player) event.getWhoClicked(), subject);
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        initializePages(gui, paginatedPane);
                        update();
                    }
                }.runTaskLater(Main.getInstance(), 1L);
                event.setCancelled(true);
            }));
            if (CONFIG.getBoolean("subject-gui.percentage-bars.enable")) {
                int x;
                int y;
                if (pane.getOrientation() == Orientable.Orientation.HORIZONTAL) {
                    x = index % pane.getLength();
                    y = (int) Math.floor((double) index / pane.getLength());
                } else if (pane.getOrientation() == Orientable.Orientation.VERTICAL) {
                    x = (int) Math.floor((double) index / pane.getHeight());
                    y = index % pane.getHeight();
                } else {
                    throw new UnsupportedOperationException("Unknown orientation found");
                }
                int xOffset = CONFIG.getInt("subject-gui.percentage-bars.offset.x");
                int yOffset = CONFIG.getInt("subject-gui.percentage-bars.offset.y");
                int totalVotes = votes.stream().mapToInt(SubjectVote::getVotes).sum();
                int userVotes = getSubjectVote(subject).getVotes();
                var percentageBar = new PercentageBar(x + xOffset, y + yOffset, 7, 1);
                percentageBar.setPercentage(totalVotes == 0 ? 0 : (float) userVotes / totalVotes);
                gui.addPane(percentageBar);
            }
        }
        paginatedPane.addPane(page, pane);
    }
}
Also used : SubjectVote(com.gmail.stefvanschiedev.buildinggame.utils.SubjectVote) HumanEntity(org.bukkit.entity.HumanEntity) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) java.util(java.util) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) Orientable(com.github.stefvanschie.inventoryframework.pane.Orientable) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Player(org.bukkit.entity.Player) SubjectVote(com.gmail.stefvanschiedev.buildinggame.utils.SubjectVote) ItemStack(org.bukkit.inventory.ItemStack) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) Main(com.gmail.stefvanschiedev.buildinggame.Main) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) PercentageBar(com.github.stefvanschie.inventoryframework.pane.component.PercentageBar) ChatColor(org.bukkit.ChatColor) NotNull(org.jetbrains.annotations.NotNull) Material(org.bukkit.Material) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) Player(org.bukkit.entity.Player) PercentageBar(com.github.stefvanschie.inventoryframework.pane.component.PercentageBar) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Material(org.bukkit.Material) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) ItemStack(org.bukkit.inventory.ItemStack)

Example 8 with PaginatedPane

use of com.github.stefvanschie.inventoryframework.pane.PaginatedPane in project EmployMe by DavidTheExplorer.

the class ItemPaletteGUI method createItemsPane.

private Pane createItemsPane() {
    Deque<GuiItem> remainingItems = ALL_ITEMS.stream().map(this::toRedirectItem).collect(toCollection(LinkedList::new));
    PaginatedPane pane = new PaginatedPane(0, 0, 9, 6, Priority.LOWEST);
    for (int i = 0; i < PAGES_AMOUNT; i++) pane.addPane(i, createPage(remainingItems));
    pane.setPage(0);
    this.itemsPane = pane;
    return pane;
}
Also used : GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane)

Example 9 with PaginatedPane

use of com.github.stefvanschie.inventoryframework.pane.PaginatedPane in project buildinggame by stefvanschie.

the class ReportMenu method playerReportsGui.

/**
 * Creates a reports gui where the reports are for the specified player.
 *
 * @param player the reportee of the reports gui
 * @return the gui created
 * @since 6.5.0
 */
@NotNull
@Contract(pure = true)
private ChestGui playerReportsGui(@NotNull OfflinePlayer player) {
    ChestGui gui = new ChestGui(6, ChatColor.GREEN + player.getName() + "'s reports");
    var paginatedPane = new PaginatedPane(0, 0, 9, 5);
    int paginatedPaneArea = paginatedPane.getLength() * paginatedPane.getHeight();
    for (int page = 0; page < Math.min(1, Math.ceil((double) Report.getReports(player).size() / paginatedPaneArea)); page++) {
        var outlinePane = new OutlinePane(0, 0, 9, 5);
        for (int i = 0; i < paginatedPaneArea; i++) {
            var index = i + (page * paginatedPaneArea);
            if (index >= Report.getReports(player).size()) {
                break;
            }
            var report = Report.getReports(player).get(index);
            var reportItem = new ItemStack(Material.PAPER);
            var reportMeta = reportItem.getItemMeta();
            reportMeta.setDisplayName(ChatColor.GOLD + "Report #" + (index + 1));
            reportMeta.setLore(Arrays.asList(ChatColor.AQUA + "By: " + report.getReporter().getName(), ChatColor.AQUA + "At: " + report.getDate().format(DateTimeFormatter.RFC_1123_DATE_TIME)));
            reportItem.setItemMeta(reportMeta);
            outlinePane.addItem(new GuiItem(reportItem, event -> {
                HumanEntity clicker = event.getWhoClicked();
                if (event.isLeftClick()) {
                    new BukkitRunnable() {

                        @Override
                        public void run() {
                            try {
                                var clipboard = report.loadSchematic();
                                new BukkitRunnable() {

                                    @Override
                                    public void run() {
                                        WorldEditPlugin plugin = WorldEditPlugin.getPlugin(WorldEditPlugin.class);
                                        LocalSession session = plugin.getSession((Player) clicker);
                                        session.setClipboard(new ClipboardHolder(clipboard));
                                        clicker.closeInventory();
                                        MessageManager.getInstance().send(clicker, ChatColor.GREEN + "The schematic has been copied to your clipboard.");
                                    }
                                }.runTask(Main.getInstance());
                            } catch (IOException exception) {
                                exception.printStackTrace();
                            }
                        }
                    }.runTaskAsynchronously(Main.getInstance());
                } else if (event.isRightClick()) {
                    new ConfirmationMenu(ChatColor.GREEN + "Are you sure you want to delete this report?", click -> new BukkitRunnable() {

                        @Override
                        public void run() {
                            if (click == ConfirmationMenu.Response.ACCEPT) {
                                Report.delete(report);
                                playerReportsGui((OfflinePlayer) clicker).show(clicker);
                            } else if (click == ConfirmationMenu.Response.DENY) {
                                gui.show(clicker);
                            } else {
                                throw new IllegalStateException("Unknown confirmation click type");
                            }
                        }
                    }.runTaskLater(Main.getInstance(), 1L)).show(clicker);
                }
                event.setCancelled(true);
            }));
        }
        paginatedPane.addPane(page, outlinePane);
    }
    gui.addPane(paginatedPane);
    var backItemPane = new OutlinePane(4, 5, 1, 1);
    var backItem = new ItemStack(Material.BOOK);
    var backMeta = backItem.getItemMeta();
    backMeta.setDisplayName(ChatColor.GREEN + "Go back");
    backItem.setItemMeta(backMeta);
    backItemPane.addItem(new GuiItem(backItem, event -> show(event.getWhoClicked())));
    gui.addPane(backItemPane);
    if (paginatedPane.getPages() > 1) {
        var previousPageItemPane = new OutlinePane(2, 5, 1, 1);
        var nextPageItemPane = new OutlinePane(6, 5, 1, 1);
        var previousPageItem = new ItemStack(Material.SUGAR_CANE);
        var previousPageMeta = previousPageItem.getItemMeta();
        previousPageMeta.setDisplayName(ChatColor.GREEN + "Previous page");
        previousPageItem.setItemMeta(previousPageMeta);
        previousPageItemPane.addItem(new GuiItem(previousPageItem, event -> {
            paginatedPane.setPage(paginatedPane.getPage() - 1);
            if (paginatedPane.getPage() == 0) {
                previousPageItemPane.setVisible(false);
            }
            nextPageItemPane.setVisible(true);
            update();
            event.setCancelled(true);
        }));
        var nextPageItem = new ItemStack(Material.SUGAR_CANE);
        var nextPageMeta = nextPageItem.getItemMeta();
        nextPageMeta.setDisplayName(ChatColor.GREEN + "Next page");
        nextPageItem.setItemMeta(nextPageMeta);
        nextPageItemPane.addItem(new GuiItem(nextPageItem, event -> {
            paginatedPane.setPage(paginatedPane.getPage() + 1);
            if (paginatedPane.getPage() == paginatedPane.getPages() - 1) {
                nextPageItemPane.setVisible(false);
            }
            previousPageItemPane.setVisible(true);
            update();
            event.setCancelled(true);
        }));
        gui.addPane(previousPageItemPane);
        gui.addPane(nextPageItemPane);
    }
    return gui;
}
Also used : ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) Arrays(java.util.Arrays) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) Player(org.bukkit.entity.Player) SkullMeta(org.bukkit.inventory.meta.SkullMeta) Main(com.gmail.stefvanschiedev.buildinggame.Main) Material(org.bukkit.Material) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) HumanEntity(org.bukkit.entity.HumanEntity) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) OfflinePlayer(org.bukkit.OfflinePlayer) ItemStack(org.bukkit.inventory.ItemStack) WorldEditPlugin(com.sk89q.worldedit.bukkit.WorldEditPlugin) Contract(org.jetbrains.annotations.Contract) List(java.util.List) DateTimeFormatter(java.time.format.DateTimeFormatter) ChatColor(org.bukkit.ChatColor) LocalSession(com.sk89q.worldedit.LocalSession) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Collections(java.util.Collections) Report(com.gmail.stefvanschiedev.buildinggame.utils.Report) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) LocalSession(com.sk89q.worldedit.LocalSession) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) IOException(java.io.IOException) WorldEditPlugin(com.sk89q.worldedit.bukkit.WorldEditPlugin) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) NotNull(org.jetbrains.annotations.NotNull) Contract(org.jetbrains.annotations.Contract)

Example 10 with PaginatedPane

use of com.github.stefvanschie.inventoryframework.pane.PaginatedPane in project buildinggame by stefvanschie.

the class SubjectMenu method show.

/**
 * Opens this gui for the specified human entity
 *
 * @param humanEntity the human entity to open the gui for
 * @since 9.0.3
 */
public void show(@NotNull HumanEntity humanEntity) {
    ChestGui gui = new ChestGui(CONFIG.getInt("subject-gui.rows"), MessageManager.translate(MESSAGES.getString("subject-gui.title")));
    int rows = gui.getRows();
    var paginatedPane = new PaginatedPane(0, 0, 9, rows - 1);
    initializePages(gui, paginatedPane);
    if (paginatedPane.getPages() == 1 && !CONFIG.getBoolean("subject-gui.close-item.enable")) {
        paginatedPane.setHeight(gui.getRows());
        initializePages(gui, paginatedPane);
    }
    gui.addPane(paginatedPane);
    if (paginatedPane.getPages() != 1) {
        var previousPane = new OutlinePane(2, rows - 1, 1, 1);
        var nextPane = new OutlinePane(6, rows - 1, 1, 1);
        // previous page
        var prevItem = new ItemStack(Material.SUGAR_CANE);
        var prevMeta = prevItem.getItemMeta();
        prevMeta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.previous-page.name")));
        prevMeta.setLore(MessageManager.translate(MESSAGES.getStringList("subject-gui.previous-page.lores")));
        prevItem.setItemMeta(prevMeta);
        previousPane.addItem(new GuiItem(prevItem, event -> {
            paginatedPane.setPage(paginatedPane.getPage() - 1);
            if (paginatedPane.getPage() == 0)
                previousPane.setVisible(false);
            nextPane.setVisible(true);
            update();
            event.setCancelled(true);
        }));
        previousPane.setVisible(false);
        gui.addPane(previousPane);
        // next page
        var nextItem = new ItemStack(Material.SUGAR_CANE);
        var nextMeta = nextItem.getItemMeta();
        nextMeta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.next-page.name")));
        nextMeta.setLore(MessageManager.translate(MESSAGES.getStringList("subject-gui.next-page.lores")));
        nextItem.setItemMeta(nextMeta);
        nextPane.addItem(new GuiItem(nextItem, event -> {
            paginatedPane.setPage(paginatedPane.getPage() + 1);
            if (paginatedPane.getPage() == paginatedPane.getPages() - 1)
                nextPane.setVisible(false);
            previousPane.setVisible(true);
            update();
            event.setCancelled(true);
        }));
        gui.addPane(nextPane);
    }
    if (CONFIG.getBoolean("subject-gui.close-item.enable")) {
        var closePane = new OutlinePane(4, rows - 1, 1, 1);
        var closeItem = new ItemStack(Material.BOOK);
        var closeMeta = closeItem.getItemMeta();
        closeMeta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.close-menu.name")));
        closeMeta.setLore(MessageManager.translate(MESSAGES.getStringList("subject-gui.close-menu.lores")));
        closeItem.setItemMeta(closeMeta);
        closePane.addItem(new GuiItem(closeItem, event -> {
            event.getWhoClicked().closeInventory();
            event.setCancelled(true);
        }));
        gui.addPane(closePane);
    }
    // additional items
    CONFIG.getConfigurationSection("subject-gui.additional-items").getKeys(false).forEach(section -> {
        String baseNode = "subject-gui.additional-items." + section;
        int x = CONFIG.getInt(baseNode + ".x") - 1;
        int y = CONFIG.getInt(baseNode + ".y") - 1;
        var pane = new OutlinePane(x, y, 1, 1);
        Material material = SettingsManager.getInstance().getMaterial(baseNode + ".id", Material.BARRIER);
        var item = new ItemStack(material);
        var itemMeta = item.getItemMeta();
        var name = MESSAGES.getString(baseNode + ".name");
        if (name == null) {
            var baseName = item.getType().name().substring(1).replace('_', ' ');
            var lowerCaseName = baseName.toLowerCase(Locale.getDefault());
            var prettyName = Character.toUpperCase(item.getType().name().charAt(0)) + lowerCaseName;
            MESSAGES.set(baseNode + ".name", prettyName);
            name = MESSAGES.getString(baseNode + ".name");
        }
        itemMeta.setDisplayName(MessageManager.translate(name));
        var lore = MESSAGES.getStringList(baseNode + ".lore");
        if (lore == null) {
            MESSAGES.set(baseNode + ".name", new ArrayList<String>());
            lore = new ArrayList<>();
        }
        itemMeta.setLore(MessageManager.translate(lore));
        item.setItemMeta(itemMeta);
        pane.addItem(new GuiItem(item, event -> event.setCancelled(true)));
        gui.addPane(pane);
    });
    gui.setOnClose(event -> openGuis.remove(gui));
    gui.show(humanEntity);
    openGuis.put(gui, paginatedPane);
}
Also used : ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) HumanEntity(org.bukkit.entity.HumanEntity) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) java.util(java.util) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) Orientable(com.github.stefvanschie.inventoryframework.pane.Orientable) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Player(org.bukkit.entity.Player) SubjectVote(com.gmail.stefvanschiedev.buildinggame.utils.SubjectVote) ItemStack(org.bukkit.inventory.ItemStack) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) Main(com.gmail.stefvanschiedev.buildinggame.Main) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) PercentageBar(com.github.stefvanschie.inventoryframework.pane.component.PercentageBar) ChatColor(org.bukkit.ChatColor) NotNull(org.jetbrains.annotations.NotNull) Material(org.bukkit.Material) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

PaginatedPane (com.github.stefvanschie.inventoryframework.pane.PaginatedPane)16 GuiItem (com.github.stefvanschie.inventoryframework.gui.GuiItem)15 ChestGui (com.github.stefvanschie.inventoryframework.gui.type.ChestGui)14 ItemStack (org.bukkit.inventory.ItemStack)14 OutlinePane (com.github.stefvanschie.inventoryframework.pane.OutlinePane)13 StaticPane (com.github.stefvanschie.inventoryframework.pane.StaticPane)11 Material (org.bukkit.Material)9 Player (org.bukkit.entity.Player)9 ArrayList (java.util.ArrayList)6 Pane (com.github.stefvanschie.inventoryframework.pane.Pane)5 GUIs (fr.rosstail.nodewar.guis.GUIs)5 AdaptMessage (fr.rosstail.nodewar.lang.AdaptMessage)5 Nodewar (fr.rosstail.nodewar.Nodewar)4 ChatColor (org.bukkit.ChatColor)4 Main (com.gmail.stefvanschiedev.buildinggame.Main)3 MessageManager (com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager)3 Territory (fr.rosstail.nodewar.territory.zonehandlers.Territory)3 List (java.util.List)3 Orientable (com.github.stefvanschie.inventoryframework.pane.Orientable)2 PercentageBar (com.github.stefvanschie.inventoryframework.pane.component.PercentageBar)2