Search in sources :

Example 1 with GuiItem

use of net.dzikoysk.funnyguilds.element.gui.GuiItem in project FunnyGuilds by FunnyGuilds.

the class ExcItems method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    Player player = (Player) sender;
    PluginConfig config = Settings.getConfig();
    List<ItemStack> guildItems = config.createItems;
    List<ItemStack> guiItems = config.guiItems;
    String title = config.guiItemsTitle;
    if (!config.useCommonGUI && player.hasPermission("funnyguilds.vip.items")) {
        guildItems = config.createItemsVip;
        guiItems = config.guiItemsVip;
        title = config.guiItemsVipTitle;
    }
    GuiWindow gui = new GuiWindow(title, guiItems.size() / 9 + (guiItems.size() % 9 != 0 ? 1 : 0));
    gui.setCloseEvent(close -> gui.unregister());
    for (ItemStack item : guiItems) {
        item = item.clone();
        if (config.addLoreLines && guildItems.contains(item)) {
            ItemMeta meta = item.getItemMeta();
            List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
            int pinvAmount = ItemUtils.getItemAmount(item, player.getInventory());
            int ecAmount = ItemUtils.getItemAmount(item, player.getEnderChest());
            for (String line : config.guiItemsLore) {
                line = StringUtils.replace(line, "{PINV-AMOUNT}", Integer.toString(pinvAmount));
                line = StringUtils.replace(line, "{PINV-PERCENT}", StringUtils.getPercent(pinvAmount, item.getAmount()));
                line = StringUtils.replace(line, "{EC-AMOUNT}", Integer.toString(ecAmount));
                line = StringUtils.replace(line, "{EC-PERCENT}", StringUtils.getPercent(ecAmount, item.getAmount()));
                line = StringUtils.replace(line, "{ALL-AMOUNT}", Integer.toString(pinvAmount + ecAmount));
                line = StringUtils.replace(line, "{ALL-PERCENT}", StringUtils.getPercent(pinvAmount + ecAmount, item.getAmount()));
                lore.add(line);
            }
            meta.setLore(lore);
            item.setItemMeta(meta);
        }
        gui.setToNextFree(new GuiItem(item));
    }
    gui.open(player);
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) GuiItem(net.dzikoysk.funnyguilds.element.gui.GuiItem) GuiWindow(net.dzikoysk.funnyguilds.element.gui.GuiWindow) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)1 GuiItem (net.dzikoysk.funnyguilds.element.gui.GuiItem)1 GuiWindow (net.dzikoysk.funnyguilds.element.gui.GuiWindow)1 Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1