Search in sources :

Example 6 with ChestGui

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

the class WorldsGUIs method initGUI.

public static void initGUI(Player player, Nodewar plugin) {
    int invSize = 6;
    String display = "Worlds - 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, paginatedPane, 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 ChestGui

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

the class PlayerAdminGUI method initGUI.

public static void initGUI(Player player, Nodewar plugin, Player target, ChestGui previousGui) {
    int invSize = 1;
    ChestGui gui = new ChestGui(invSize, AdaptMessage.playerMessage(target, target.getName()));
    StaticPane staticPane = initPane(player, plugin, gui, previousGui, target);
    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);
    gui.setOnGlobalClick(event -> {
        event.setCancelled(true);
    });
    gui.addPane(staticPane);
    gui.show(player);
}
Also used : 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) ItemStack(org.bukkit.inventory.ItemStack)

Example 8 with ChestGui

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

the class PlayerInfoGUI method initGUI.

public static void initGUI(Player player, fr.rosstail.nodewar.Nodewar plugin) {
    FileConfiguration customConfig = new YamlConfiguration();
    String path = "gui/playerInfoGUI.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.setOnGlobalClick(event -> {
            event.setCancelled(true);
            initPane(player, plugin, customConfig, itemSlot);
            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)

Example 9 with ChestGui

use of com.github.stefvanschie.inventoryframework.gui.type.ChestGui 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 10 with ChestGui

use of com.github.stefvanschie.inventoryframework.gui.type.ChestGui 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)

Aggregations

GuiItem (com.github.stefvanschie.inventoryframework.gui.GuiItem)24 ChestGui (com.github.stefvanschie.inventoryframework.gui.type.ChestGui)24 ItemStack (org.bukkit.inventory.ItemStack)23 OutlinePane (com.github.stefvanschie.inventoryframework.pane.OutlinePane)21 StaticPane (com.github.stefvanschie.inventoryframework.pane.StaticPane)21 PaginatedPane (com.github.stefvanschie.inventoryframework.pane.PaginatedPane)14 Material (org.bukkit.Material)13 Player (org.bukkit.entity.Player)12 Pane (com.github.stefvanschie.inventoryframework.pane.Pane)9 GUIs (fr.rosstail.nodewar.guis.GUIs)9 AdaptMessage (fr.rosstail.nodewar.lang.AdaptMessage)9 Nodewar (fr.rosstail.nodewar.Nodewar)8 ArrayList (java.util.ArrayList)6 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)6 LangManager (fr.rosstail.nodewar.lang.LangManager)5 LangMessage (fr.rosstail.nodewar.lang.LangMessage)5 Territory (fr.rosstail.nodewar.territory.zonehandlers.Territory)5 File (java.io.File)4 IOException (java.io.IOException)4 ChatColor (org.bukkit.ChatColor)4