Search in sources :

Example 1 with SimpleAccount

use of com.nextplugins.economy.model.account.SimpleAccount 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 2 with SimpleAccount

use of com.nextplugins.economy.model.account.SimpleAccount in project NextEconomy by NextPlugins.

the class NPCRunnable method run.

@Override
public void run() {
    clearPositions();
    if (locationManager.getLocationMap().isEmpty())
        return;
    ArrayList<SimpleAccount> accounts = new ArrayList<>(rankingStorage.getRankByCoin().values());
    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, 3, 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, 3, 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 skinName = account == null ? "Yuhtin" : account.getUsername();
        val profile = new Profile(skinName);
        profile.complete();
        profile.setName("");
        profile.setUniqueId(new UUID(RANDOM.nextLong(), 0));
        val npc = NPC.builder().profile(profile).location(location).imitatePlayer(false).lookAtPlayer(false).build(npcPool);
        if (animation) {
            val spawnAnimationRaw = AnimationValue.get(AnimationValue::spawnEmote);
            executeAnimation(npc, spawnAnimationRaw);
        }
    }
}
Also used : SimpleAccount(com.nextplugins.economy.model.account.SimpleAccount) lombok.val(lombok.val) AnimationValue(com.nextplugins.economy.configuration.AnimationValue) CMIHologram(com.Zrips.CMI.Modules.Holograms.CMIHologram) RankingValue(com.nextplugins.economy.configuration.RankingValue) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Profile(com.github.juliarn.npc.profile.Profile)

Example 3 with SimpleAccount

use of com.nextplugins.economy.model.account.SimpleAccount 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)

Example 4 with SimpleAccount

use of com.nextplugins.economy.model.account.SimpleAccount in project NextEconomy by NextPlugins.

the class RankingListener method onRankingUpdate.

@EventHandler(priority = EventPriority.MONITOR)
public void onRankingUpdate(AsyncRankingUpdateEvent event) {
    if (event.isCancelled())
        return;
    Bukkit.getScheduler().runTaskAsynchronously(NextEconomy.getInstance(), () -> {
        val pluginInstance = NextEconomy.getInstance();
        val pluginManager = Bukkit.getPluginManager();
        SimpleAccount lastAccount = null;
        if (!rankingStorage.getRankByCoin().isEmpty()) {
            lastAccount = rankingStorage.getTopPlayer(false);
        }
        NextEconomy.getInstance().getAccountStorage().flushData();
        rankingStorage.getRankByCoin().clear();
        rankingStorage.getRankByMovimentation().clear();
        rankingStorage.getRankByMovimentation().addAll(accountRepository.selectSimpleAll("ORDER BY movimentedBalance DESC LIMIT " + RankingValue.get(RankingValue::rankingLimit)));
        val accounts = accountRepository.selectSimpleAll("ORDER BY balance DESC LIMIT " + RankingValue.get(RankingValue::rankingLimit));
        val discordEnabled = DiscordUtil.isEnabled();
        if (discordEnabled && DiscordUtil.getGuild() != null) {
            DiscordUtil.removeDiscordRoles(DiscordUtil.getGuild());
        }
        if (!accounts.isEmpty()) {
            val rankingType = RankingValue.get(RankingValue::rankingType);
            val tycoonTag = RankingValue.get(RankingValue::tycoonTagValue);
            val chatRanking = rankingType.equals("CHAT");
            val bodyLines = new LinkedList<String>();
            val stringBuilder = DiscordValue.get(DiscordValue::enable) ? new StringBuilder() : null;
            int position = 1;
            for (val account : accounts) {
                if (position == 1)
                    rankingStorage.setTopPlayer(account.getUsername());
                rankingStorage.getRankByCoin().put(account.getUsername(), account);
                Group group = chatRanking || stringBuilder != null ? groupManager.getGroup(account.getUsername()) : null;
                if (chatRanking) {
                    val body = RankingValue.get(RankingValue::chatModelBody);
                    bodyLines.add(body.replace("$position", String.valueOf(position)).replace("$prefix", group.getPrefix()).replace("$suffix", group.getSuffix()).replace("$player", account.getUsername()).replace("$tycoon", position == 1 ? tycoonTag : "").replace("$amount", account.getBalanceFormated()));
                }
                if (stringBuilder != null) {
                    if (position == 1)
                        stringBuilder.append(DiscordValue.get(DiscordValue::topEmoji));
                    val line = DiscordValue.get(DiscordValue::topLine);
                    stringBuilder.append(line.replace("$position", String.valueOf(position)).replace("$username", account.getUsername()).replace("$prefix", group.getPrefix()).replace("$suffix", group.getSuffix()).replace("$amount", account.getBalanceFormated())).append("\n");
                }
                if (discordEnabled && DiscordUtil.getGuild() != null) {
                    DiscordUtil.addDiscordRole(account, position, DiscordUtil.getGuild());
                }
                position++;
            }
            rankingChatBody.setMinecraftBodyLines(bodyLines.toArray(new String[] {}));
            rankingChatBody.setDiscordBodyLines(stringBuilder == null ? "" : stringBuilder.toString());
            if (lastAccount != null) {
                val topAccount = rankingStorage.getTopPlayer();
                if (!lastAccount.getUsername().equals(topAccount))
                    pluginManager.callEvent(new AsyncMoneyTopPlayerChangedEvent(lastAccount, rankingStorage.getTopPlayer(false)));
            }
        } else {
            rankingChatBody.setMinecraftBodyLines(new String[] { ColorUtil.colored("  &cNenhum jogador está no ranking!") });
            rankingChatBody.setDiscordBodyLines(":x: Nenhum jogador está no ranking!");
        }
        val instance = CustomRankingRegistry.getInstance();
        if (!instance.isEnabled())
            return;
        Bukkit.getScheduler().runTaskLater(pluginInstance, instance.getRunnable(), 20L);
    });
}
Also used : lombok.val(lombok.val) SimpleAccount(com.nextplugins.economy.model.account.SimpleAccount) Group(com.nextplugins.economy.api.group.Group) RankingValue(com.nextplugins.economy.configuration.RankingValue) AsyncMoneyTopPlayerChangedEvent(com.nextplugins.economy.api.event.operations.AsyncMoneyTopPlayerChangedEvent) DiscordValue(com.nextplugins.economy.configuration.DiscordValue) LinkedList(java.util.LinkedList) EventHandler(org.bukkit.event.EventHandler)

Aggregations

RankingValue (com.nextplugins.economy.configuration.RankingValue)4 SimpleAccount (com.nextplugins.economy.model.account.SimpleAccount)4 lombok.val (lombok.val)4 CMIHologram (com.Zrips.CMI.Modules.Holograms.CMIHologram)2 ItemBuilder (com.nextplugins.economy.util.ItemBuilder)2 ArrayList (java.util.ArrayList)2 Profile (com.github.juliarn.npc.profile.Profile)1 AsyncMoneyTopPlayerChangedEvent (com.nextplugins.economy.api.event.operations.AsyncMoneyTopPlayerChangedEvent)1 Group (com.nextplugins.economy.api.group.Group)1 AnimationValue (com.nextplugins.economy.configuration.AnimationValue)1 DiscordValue (com.nextplugins.economy.configuration.DiscordValue)1 LinkedList (java.util.LinkedList)1 UUID (java.util.UUID)1 ArmorStand (org.bukkit.entity.ArmorStand)1 EventHandler (org.bukkit.event.EventHandler)1 ItemStack (org.bukkit.inventory.ItemStack)1 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)1