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);
}
Aggregations