Search in sources :

Example 1 with ItemBuilder

use of com.nextplugins.economy.util.ItemBuilder in project NextEconomy by NextPlugins.

the class BankView method configureInventory.

@Override
protected void configureInventory(Viewer viewer, @NotNull InventoryEditor editor) {
    val player = viewer.getPlayer();
    val account = accountStorage.findAccount(player);
    val instance = PurseAPI.getInstance();
    val receiveType = ColorUtil.colored(account.isReceiveCoins() ? MessageValue.get(MessageValue::receiveCoinsOn) : MessageValue.get(MessageValue::receiveCoinsOff));
    val discordName = ColorUtil.colored(account.getDiscordName() == null ? "&cNão vinculado" : account.getDiscordName());
    val purse = instance != null ? instance.getPurseFormated() : "";
    val isHigh = instance != null ? instance.getHighMessage() : "";
    val nextUpdate = instance != null ? TimeUtils.format(instance.getNextUpdate() - System.currentTimeMillis()) : "";
    val transactionName = account.getTransactionsQuantity() == 1 ? MessageValue.get(MessageValue::singularTransaction) : MessageValue.get(MessageValue::pluralTransaction);
    val transactionsMessage = account.getTransactionsQuantity() + " " + transactionName;
    for (val value : BUTTONS.values()) {
        val inventorySlot = value.getInventorySlot();
        if (inventorySlot == -1 || (value.getButtonType() == ButtonType.PURSE && instance == null))
            continue;
        val valueItem = new ItemBuilder(value.getItemStack(player.getName())).setLore(value.getLore().stream().map(line -> line.replace("$money", account.getBalanceFormated()).replace("$transactions", transactionsMessage).replace("$movimentedMoney", NumberUtils.format(account.getMovimentedBalance())).replace("$toggleMessage", receiveType).replace("$discord", discordName).replace("$value", purse).replace("$status", isHigh).replace("$time", nextUpdate)).collect(Collectors.toList())).wrap();
        editor.setItem(inventorySlot, InventoryItem.of(valueItem).defaultCallback(value.getButtonType().getAction()));
    }
}
Also used : lombok.val(lombok.val) InventoryEditor(com.henryfabio.minecraft.inventoryapi.editor.InventoryEditor) PurseAPI(com.nextplugins.economy.api.PurseAPI) SimpleInventory(com.henryfabio.minecraft.inventoryapi.inventory.impl.simple.SimpleInventory) Viewer(com.henryfabio.minecraft.inventoryapi.viewer.Viewer) TimeUtils(com.nextplugins.economy.util.TimeUtils) lombok.val(lombok.val) ItemBuilder(com.nextplugins.economy.util.ItemBuilder) NumberUtils(com.nextplugins.economy.util.NumberUtils) Collectors(java.util.stream.Collectors) InventoryButtonRegistry(com.nextplugins.economy.views.button.registry.InventoryButtonRegistry) ColorUtil(com.nextplugins.economy.util.ColorUtil) ButtonType(com.nextplugins.economy.views.button.model.ButtonType) InventoryValue(com.nextplugins.economy.configuration.InventoryValue) InventoryItem(com.henryfabio.minecraft.inventoryapi.item.InventoryItem) AccountStorage(com.nextplugins.economy.model.account.storage.AccountStorage) NotNull(org.jetbrains.annotations.NotNull) MessageValue(com.nextplugins.economy.configuration.MessageValue) MessageValue(com.nextplugins.economy.configuration.MessageValue) ItemBuilder(com.nextplugins.economy.util.ItemBuilder)

Example 2 with ItemBuilder

use of com.nextplugins.economy.util.ItemBuilder in project NextEconomy by NextPlugins.

the class ArmorStandRunnable method run.

@Override
public void run() {
    STANDS.forEach(ArmorStand::remove);
    if (holographicDisplays)
        HologramsAPI.getHolograms(plugin).forEach(Hologram::delete);
    else {
        for (val entry : HOLOGRAMS) {
            val cmiHologram = CMI.getInstance().getHologramManager().getHolograms().get(entry);
            if (cmiHologram == null)
                continue;
            CMI.getInstance().getHologramManager().removeHolo(cmiHologram);
        }
    }
    HOLOGRAMS.clear();
    STANDS.clear();
    if (locationManager.getLocationMap().isEmpty())
        return;
    ArrayList<SimpleAccount> accounts = new ArrayList<>(rankingStorage.getRankByCoin().values());
    val small = RankingValue.get(RankingValue::hologramFormat).equalsIgnoreCase("SMALL");
    val height = small ? 2.15 : 3;
    val hologramLines = RankingValue.get(RankingValue::hologramArmorStandLines);
    val nobodyLines = RankingValue.get(RankingValue::nobodyHologramLines);
    for (val entry : locationManager.getLocationMap().entrySet()) {
        val position = entry.getKey();
        val location = entry.getValue();
        if (location == null || location.getWorld() == null)
            continue;
        val chunk = location.getChunk();
        if (!chunk.isLoaded())
            chunk.load(true);
        SimpleAccount account = position - 1 < accounts.size() ? accounts.get(position - 1) : null;
        if (account == null) {
            if (!nobodyLines.isEmpty()) {
                val hologramLocation = location.clone().add(0, height, 0);
                if (holographicDisplays) {
                    val hologram = HologramsAPI.createHologram(plugin, hologramLocation);
                    for (val nobodyLine : nobodyLines) {
                        hologram.appendTextLine(nobodyLine.replace("$position", String.valueOf(position)));
                    }
                } else {
                    val cmiHologram = new CMIHologram("NextEconomy" + position, hologramLocation);
                    for (val nobodyLine : nobodyLines) {
                        cmiHologram.addLine(nobodyLine.replace("$position", String.valueOf(position)));
                    }
                    CMI.getInstance().getHologramManager().addHologram(cmiHologram);
                    cmiHologram.update();
                    HOLOGRAMS.add("NextEconomy" + position);
                }
            }
        } else {
            if (!hologramLines.isEmpty()) {
                val group = plugin.getGroupWrapperManager().getGroup(account.getUsername());
                val format = account.getBalanceFormated();
                val hologramLocation = location.clone().add(0, height, 0);
                if (holographicDisplays) {
                    val hologram = HologramsAPI.createHologram(plugin, hologramLocation);
                    for (val hologramLine : hologramLines) {
                        hologram.appendTextLine(hologramLine.replace("$position", String.valueOf(position)).replace("$player", account.getUsername()).replace("$prefix", group.getPrefix()).replace("$suffix", group.getSuffix()).replace("$amount", format));
                    }
                } else {
                    val cmiHologram = new CMIHologram("NextEconomy" + position, hologramLocation);
                    for (val hologramLine : hologramLines) {
                        cmiHologram.addLine(hologramLine.replace("$position", String.valueOf(position)).replace("$player", account.getUsername()).replace("$prefix", group.getPrefix()).replace("$suffix", group.getSuffix()).replace("$amount", format));
                    }
                    CMI.getInstance().getHologramManager().addHologram(cmiHologram);
                    cmiHologram.update();
                    HOLOGRAMS.add("NextEconomy" + position);
                }
            }
        }
        val stand = location.getWorld().spawn(location, ArmorStand.class);
        // show only after configuration
        stand.setVisible(false);
        stand.setMetadata("nexteconomy", new FixedMetadataValue(plugin, true));
        stand.setSmall(small);
        stand.setCustomNameVisible(false);
        stand.setGravity(false);
        stand.setArms(true);
        val swordNumber = Math.min(SWORDS.length, position);
        val sword = SWORDS[swordNumber - 1];
        stand.setItemInHand(new ItemStack(sword));
        val skinName = account == null ? "Yuhtin" : account.getUsername();
        stand.setHelmet(new ItemBuilder(skinName).wrap());
        stand.setChestplate(new ItemBuilder(Material.LEATHER_CHESTPLATE, ColorUtil.getBukkitColorByHex(RankingValue.get(RankingValue::chestplateRGB))).wrap());
        stand.setLeggings(new ItemBuilder(Material.LEATHER_LEGGINGS, ColorUtil.getBukkitColorByHex(RankingValue.get(RankingValue::leggingsRGB))).wrap());
        stand.setBoots(new ItemBuilder(Material.LEATHER_BOOTS, ColorUtil.getBukkitColorByHex(RankingValue.get(RankingValue::bootsRGB))).wrap());
        // configuration finished, show stand
        stand.setVisible(true);
        STANDS.add(stand);
    }
}
Also used : lombok.val(lombok.val) SimpleAccount(com.nextplugins.economy.model.account.SimpleAccount) ItemBuilder(com.nextplugins.economy.util.ItemBuilder) ArmorStand(org.bukkit.entity.ArmorStand) CMIHologram(com.Zrips.CMI.Modules.Holograms.CMIHologram) RankingValue(com.nextplugins.economy.configuration.RankingValue) ArrayList(java.util.ArrayList) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with ItemBuilder

use of com.nextplugins.economy.util.ItemBuilder in project NextEconomy by NextPlugins.

the class RankingView method sortRankingItem.

private InventoryItem sortRankingItem(Viewer viewer) {
    AtomicInteger currentFilter = new AtomicInteger(rankingSorterType.getOrDefault(viewer.getName(), -1));
    return InventoryItem.of(new ItemBuilder(Material.HOPPER).name("&bOrdenar ranking").setLore("&7Ordene o ranking da maneira deseja", "", getColorByFilter(currentFilter.get(), -1) + " Saldo", getColorByFilter(currentFilter.get(), 0) + " Dinheiro movimentado", "", "&aClique para mudar o tipo de ordenação.").wrap()).defaultCallback(event -> {
        rankingSorterType.put(viewer.getName(), currentFilter.incrementAndGet() > 0 ? -1 : currentFilter.get());
        event.updateInventory();
    });
}
Also used : ItemBuilder(com.nextplugins.economy.util.ItemBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 4 with ItemBuilder

use of com.nextplugins.economy.util.ItemBuilder in project NextEconomy by NextPlugins.

the class RankingView method createPageItems.

@Override
protected List<InventoryItemSupplier> createPageItems(PagedViewer viewer) {
    val items = new ArrayList<InventoryItemSupplier>();
    val headLore = RankingValue.get(RankingValue::inventoryModelHeadLore);
    val tycoonTag = RankingValue.get(RankingValue::tycoonTagValue);
    int position = 1;
    val sorter = rankingSorterType.getOrDefault(viewer.getName(), -1);
    Collection<SimpleAccount> rankingAccounts = sorter == -1 ? rankingStorage.getRankByCoin().values() : rankingStorage.getRankByMovimentation();
    for (val account : rankingAccounts) {
        int finalPosition = position;
        items.add(() -> {
            val name = account.getUsername();
            val group = groupWrapperManager.getGroup(name);
            val replacedDisplayName = (finalPosition == 1 ? RankingValue.get(RankingValue::inventoryModelHeadDisplayNameTop) : RankingValue.get(RankingValue::inventoryModelHeadDisplayName)).replace("$tycoon", tycoonTag).replace("$position", String.valueOf(finalPosition)).replace("$player", name).replace("$prefix", group.getPrefix()).replace("$suffix", group.getSuffix());
            List<String> replacedLore = Lists.newArrayList();
            val transactionName = account.getTransactionsQuantity() == 1 ? MessageValue.get(MessageValue::singularTransaction) : MessageValue.get(MessageValue::pluralTransaction);
            for (val lore : headLore) {
                replacedLore.add(lore.replace("$amount", account.getBalanceFormated()).replace("$transactions", account.getTransactionsQuantity() + " " + transactionName).replace("$movimentation", account.getMovimentedBalanceFormated()).replace("$position", String.valueOf(finalPosition)));
            }
            return InventoryItem.of(new ItemBuilder(account.getUsername()).name(replacedDisplayName).setLore(replacedLore).wrap());
        });
        position++;
    }
    return items;
}
Also used : lombok.val(lombok.val) SimpleAccount(com.nextplugins.economy.model.account.SimpleAccount) ItemBuilder(com.nextplugins.economy.util.ItemBuilder) RankingValue(com.nextplugins.economy.configuration.RankingValue)

Aggregations

ItemBuilder (com.nextplugins.economy.util.ItemBuilder)4 lombok.val (lombok.val)3 RankingValue (com.nextplugins.economy.configuration.RankingValue)2 SimpleAccount (com.nextplugins.economy.model.account.SimpleAccount)2 CMIHologram (com.Zrips.CMI.Modules.Holograms.CMIHologram)1 InventoryEditor (com.henryfabio.minecraft.inventoryapi.editor.InventoryEditor)1 SimpleInventory (com.henryfabio.minecraft.inventoryapi.inventory.impl.simple.SimpleInventory)1 InventoryItem (com.henryfabio.minecraft.inventoryapi.item.InventoryItem)1 Viewer (com.henryfabio.minecraft.inventoryapi.viewer.Viewer)1 PurseAPI (com.nextplugins.economy.api.PurseAPI)1 InventoryValue (com.nextplugins.economy.configuration.InventoryValue)1 MessageValue (com.nextplugins.economy.configuration.MessageValue)1 AccountStorage (com.nextplugins.economy.model.account.storage.AccountStorage)1 ColorUtil (com.nextplugins.economy.util.ColorUtil)1 NumberUtils (com.nextplugins.economy.util.NumberUtils)1 TimeUtils (com.nextplugins.economy.util.TimeUtils)1 ButtonType (com.nextplugins.economy.views.button.model.ButtonType)1 InventoryButtonRegistry (com.nextplugins.economy.views.button.registry.InventoryButtonRegistry)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1