Search in sources :

Example 1 with GuiItem

use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project oraxen by oraxen.

the class ItemsView method createSubGUI.

private ChestGui createSubGUI(final String fileName, final List<ItemBuilder> items) {
    final int rows = Math.min((items.size() - 1) / 9 + 2, 6);
    final ChestGui gui = new ChestGui(6, getMenuTexture(settings.getString(String.format("gui_inventory.%s.color", Utils.removeExtension(fileName)))));
    final PaginatedPane pane = new PaginatedPane(9, rows);
    for (int i = 0; i < (items.size() - 1) / 45 + 1; i++) {
        final List<ItemStack> itemStackList = extractPageItems(items, i);
        final StaticPane staticPane = new StaticPane(9, Math.min((itemStackList.size() - 1) / 9 + 1, 5));
        for (int itemIndex = 0; itemIndex < itemStackList.size(); itemIndex++) {
            final ItemStack oraxenItem = itemStackList.get(itemIndex);
            staticPane.addItem(new GuiItem(oraxenItem, event -> event.getWhoClicked().getInventory().addItem(oraxenItem)), itemIndex % 9, itemIndex / 9);
        }
        pane.addPane(i, staticPane);
    }
    // page selection
    final StaticPane back = new StaticPane(2, 5, 1, 1);
    final StaticPane forward = new StaticPane(6, 5, 1, 1);
    final StaticPane exit = new StaticPane(4, 5, 9, 1);
    back.addItem(new GuiItem((OraxenItems.getItemById("arrow_previous_icon") == null ? new ItemBuilder(Material.ARROW) : OraxenItems.getItemById("arrow_previous_icon")).build(), event -> {
        pane.setPage(pane.getPage() - 1);
        if (pane.getPage() == 0)
            back.setVisible(false);
        forward.setVisible(true);
        gui.update();
    }), 0, 0);
    back.setVisible(false);
    forward.addItem(new GuiItem((OraxenItems.getItemById("arrow_next_icon") == null ? new ItemBuilder(Material.ARROW) : OraxenItems.getItemById("arrow_next_icon")).build(), event -> {
        pane.setPage(pane.getPage() + 1);
        if (pane.getPage() == pane.getPages() - 1)
            forward.setVisible(false);
        back.setVisible(true);
        gui.update();
    }), 0, 0);
    if (pane.getPages() <= 1)
        forward.setVisible(false);
    exit.addItem(new GuiItem((OraxenItems.getItemById("exit_icon") == null ? new ItemBuilder(Material.BARRIER) : OraxenItems.getItemById("exit_icon")).build(), event -> mainGui.show(event.getWhoClicked())), 0, 0);
    gui.addPane(back);
    gui.addPane(forward);
    gui.addPane(exit);
    gui.addPane(pane);
    gui.setOnGlobalClick(event -> event.setCancelled(true));
    return gui;
}
Also used : ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) ResourcesManager(io.th0rgal.oraxen.config.ResourcesManager) Utils(io.th0rgal.oraxen.utils.Utils) ItemFlag(org.bukkit.inventory.ItemFlag) OraxenPlugin(io.th0rgal.oraxen.OraxenPlugin) OraxenItems(io.th0rgal.oraxen.items.OraxenItems) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) ItemBuilder(io.th0rgal.oraxen.items.ItemBuilder) MiniMessage(net.kyori.adventure.text.minimessage.MiniMessage) HashMap(java.util.HashMap) File(java.io.File) StaticPane(com.github.stefvanschie.inventoryframework.pane.StaticPane) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) List(java.util.List) FontManager(io.th0rgal.oraxen.font.FontManager) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Map(java.util.Map) ChatColor(org.bukkit.ChatColor) Material(org.bukkit.Material) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ItemBuilder(io.th0rgal.oraxen.items.ItemBuilder) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) StaticPane(com.github.stefvanschie.inventoryframework.pane.StaticPane) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with GuiItem

use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project oraxen by oraxen.

the class ItemsView method create.

public ChestGui create() {
    final Map<File, ChestGui> files = new HashMap<>();
    for (final File file : OraxenItems.getMap().keySet()) {
        final List<ItemBuilder> unexcludedItems = OraxenItems.getUnexcludedItems(file);
        if (unexcludedItems.size() > 0)
            files.put(file, createSubGUI(file.getName(), unexcludedItems));
    }
    final int rows = (files.size() - 1) / 9 + 1;
    mainGui = new ChestGui(6, getMenuTexture("<#84CBFF>"));
    final StaticPane filesPane = new StaticPane(0, 0, 9, rows);
    int i = 0;
    for (final var entry : files.entrySet()) {
        final GuiItem item = new GuiItem(getItemStack(entry.getKey()), event -> entry.getValue().show(event.getWhoClicked()));
        filesPane.addItem(item, i % 9, i / 9);
        i++;
    }
    mainGui.addPane(filesPane);
    mainGui.setOnTopClick(event -> event.setCancelled(true));
    return mainGui;
}
Also used : ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) ItemBuilder(io.th0rgal.oraxen.items.ItemBuilder) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) HashMap(java.util.HashMap) StaticPane(com.github.stefvanschie.inventoryframework.pane.StaticPane) File(java.io.File)

Example 3 with GuiItem

use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project CommandPrompter by CyR1en.

the class ControlPane method addItem.

private void addItem(String name, ItemStack itemStack, int x, Consumer<InventoryClickEvent> consumer) {
    var itemMeta = itemStack.getItemMeta();
    Objects.requireNonNull(itemMeta).setDisplayName(Util.color(name));
    itemStack.setItemMeta(itemMeta);
    addItem(new GuiItem(itemStack, consumer), x, 0);
}
Also used : GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem)

Example 4 with GuiItem

use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project Nodewar by Rosstail.

the class PlayerAdminEmpireGUIs method initPane.

private static StaticPane initPane(Player player, fr.rosstail.nodewar.Nodewar plugin, ChestGui gui, ChestGui previousGui, PaginatedPane paginatedPane, Player target, int page) {
    StaticPane staticPane = new StaticPane(0, 0, 9, 6);
    ArrayList<Empire> empires = new ArrayList<>(EmpireManager.getEmpireManager().getEmpires().values());
    int index = 45 * page;
    int posY = 0;
    int posX = 0;
    staticPane.addItem(new GuiItem(GUIs.createGuiItem(player, plugin, null, Material.BARRIER, "&9Previous Menu", null, GUIs.adaptLore(player, null)), event -> {
        previousGui.show(player);
    }), 4, 5);
    if (page > 0) {
        staticPane.addItem(new GuiItem(GUIs.createGuiItem(player, plugin, null, Material.ARROW, "&9Previous page", null, GUIs.adaptLore(player, null)), event -> {
            paginatedPane.setPage(page - 1);
            gui.setTitle(AdaptMessage.playerMessage(target, target.getName() + "'s Empire - Page " + (page)));
            gui.update();
        }), 0, 5);
    }
    while (posY != 5) {
        while (posX != 9) {
            if (empires.size() - 1 < index) {
                return staticPane;
            }
            Empire empire = empires.get(index);
            staticPane.addItem(new GuiItem(GUIs.createGuiItem(player, plugin, null, Material.RED_BANNER, empire.getDisplay(), null, GUIs.adaptLore(player, null)), event -> {
                PlayerInfo targetInfo = PlayerInfoManager.getPlayerInfoManager().getPlayerInfoMap().get(target);
                targetInfo.leaveEmpire();
                targetInfo.setEmpire(empire);
                player.sendMessage(AdaptMessage.playerMessage(target, LangManager.getMessage(LangMessage.EMPIRE_PLAYER_SET)));
                previousGui.show(player);
            }), posX, posY);
            posX++;
            index++;
        }
        posX = 0;
        posY++;
    }
    if (empires.size() > index) {
        staticPane.addItem(new GuiItem(GUIs.createGuiItem(player, plugin, null, Material.SPECTRAL_ARROW, "&Next page", null, GUIs.adaptLore(player, null)), event -> {
            paginatedPane.setPage(page + 1);
            gui.setTitle(AdaptMessage.playerMessage(player, target.getName() + "'s Empire - Page " + (page + 1)));
            gui.update();
        }), 8, 5);
    }
    return staticPane;
}
Also used : PlayerInfoManager(fr.rosstail.nodewar.datahandlers.PlayerInfoManager) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) EmpireManager(fr.rosstail.nodewar.empires.EmpireManager) AdaptMessage(fr.rosstail.nodewar.lang.AdaptMessage) Player(org.bukkit.entity.Player) StaticPane(com.github.stefvanschie.inventoryframework.pane.StaticPane) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) LangMessage(fr.rosstail.nodewar.lang.LangMessage) PlayerInfo(fr.rosstail.nodewar.datahandlers.PlayerInfo) LangManager(fr.rosstail.nodewar.lang.LangManager) GUIs(fr.rosstail.nodewar.guis.GUIs) Empire(fr.rosstail.nodewar.empires.Empire) Pane(com.github.stefvanschie.inventoryframework.pane.Pane) Material(org.bukkit.Material) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) Empire(fr.rosstail.nodewar.empires.Empire) PlayerInfo(fr.rosstail.nodewar.datahandlers.PlayerInfo) ArrayList(java.util.ArrayList) StaticPane(com.github.stefvanschie.inventoryframework.pane.StaticPane)

Example 5 with GuiItem

use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project Nodewar by Rosstail.

the class EmpiresListGUI method initGUI.

public static void initGUI(Player player, fr.rosstail.nodewar.Nodewar plugin) {
    FileConfiguration customConfig = new YamlConfiguration();
    String path = "gui/empireListGUI.yml";
    File file = new File(plugin.getDataFolder(), path);
    try {
        customConfig.load(file);
        ChestGui gui = new ChestGui(customConfig.getInt("gui.size"), AdaptMessage.playerMessage(player, customConfig.getString("gui.display")));
        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);
        StaticPane itemSlot = new StaticPane(customConfig.getInt("gui.item-slot.x"), customConfig.getInt("gui.item-slot.y"), 9, gui.getRows(), Pane.Priority.HIGHEST);
        initPane(player, plugin, customConfig, itemSlot, gui);
        gui.setOnGlobalClick(event -> {
            event.setCancelled(true);
            initPane(player, plugin, customConfig, itemSlot, gui);
            gui.update();
        });
        gui.addPane(itemSlot);
        gui.show(player);
    } catch (IOException | InvalidConfigurationException e) {
        AdaptMessage.print("[" + Nodewar.getDimName() + "] Error while reading " + path + " file", AdaptMessage.prints.ERROR);
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) StaticPane(com.github.stefvanschie.inventoryframework.pane.StaticPane) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ItemStack(org.bukkit.inventory.ItemStack) File(java.io.File) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Aggregations

GuiItem (com.github.stefvanschie.inventoryframework.gui.GuiItem)46 ItemStack (org.bukkit.inventory.ItemStack)34 ChestGui (com.github.stefvanschie.inventoryframework.gui.type.ChestGui)28 OutlinePane (com.github.stefvanschie.inventoryframework.pane.OutlinePane)25 StaticPane (com.github.stefvanschie.inventoryframework.pane.StaticPane)21 Player (org.bukkit.entity.Player)20 Material (org.bukkit.Material)18 PaginatedPane (com.github.stefvanschie.inventoryframework.pane.PaginatedPane)15 Pane (com.github.stefvanschie.inventoryframework.pane.Pane)11 ItemBuilder (dte.employme.utils.items.ItemBuilder)11 GUIs (fr.rosstail.nodewar.guis.GUIs)9 AdaptMessage (fr.rosstail.nodewar.lang.AdaptMessage)9 Nodewar (fr.rosstail.nodewar.Nodewar)7 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)7 HumanEntity (org.bukkit.entity.HumanEntity)7 ArrayList (java.util.ArrayList)6 List (java.util.List)5 ChatColor (org.bukkit.ChatColor)5 NotNull (org.jetbrains.annotations.NotNull)5 Main (com.gmail.stefvanschiedev.buildinggame.Main)4