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