Search in sources :

Example 11 with RankingValue

use of com.nextplugins.economy.configuration.RankingValue 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)11 lombok.val (lombok.val)11 ArrayList (java.util.ArrayList)5 CMIHologram (com.Zrips.CMI.Modules.Holograms.CMIHologram)4 SimpleAccount (com.nextplugins.economy.model.account.SimpleAccount)4 AnimationValue (com.nextplugins.economy.configuration.AnimationValue)2 MessageValue (com.nextplugins.economy.configuration.MessageValue)2 ItemBuilder (com.nextplugins.economy.util.ItemBuilder)2 Command (me.saiintbrisson.minecraft.command.annotation.Command)2 EventHandler (org.bukkit.event.EventHandler)2 Profile (com.github.juliarn.npc.profile.Profile)1 Hologram (com.gmail.filoghost.holographicdisplays.api.Hologram)1 AsyncMoneyTopPlayerChangedEvent (com.nextplugins.economy.api.event.operations.AsyncMoneyTopPlayerChangedEvent)1 Group (com.nextplugins.economy.api.group.Group)1 DiscordValue (com.nextplugins.economy.configuration.DiscordValue)1 ArmorStandRunnable (com.nextplugins.economy.ranking.types.ArmorStandRunnable)1 HologramRunnable (com.nextplugins.economy.ranking.types.HologramRunnable)1 NPCRunnable (com.nextplugins.economy.ranking.types.NPCRunnable)1 LinkedList (java.util.LinkedList)1 UUID (java.util.UUID)1