Search in sources :

Example 1 with InventoryEditor

use of com.henryfabio.minecraft.inventoryapi.editor.InventoryEditor 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)

Aggregations

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 ItemBuilder (com.nextplugins.economy.util.ItemBuilder)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 Collectors (java.util.stream.Collectors)1 lombok.val (lombok.val)1 NotNull (org.jetbrains.annotations.NotNull)1