Search in sources :

Example 1 with Group

use of com.nextplugins.economy.api.group.Group in project NextEconomy by NextPlugins.

the class VaultGroupWrapper method getGroup.

@Override
public Group getGroup(String player) {
    if (chatApi == null)
        return new Group();
    try {
        val prefix = chatApi.getPlayerPrefix(Bukkit.getWorlds().get(0), player);
        val suffix = chatApi.getPlayerSuffix(Bukkit.getWorlds().get(0), player);
        return new Group(prefix, suffix);
    } catch (Exception exception) {
    // boa vault !!!
    }
    if (permissionApi == null)
        return new Group();
    try {
        val primaryGroup = permissionApi.getPrimaryGroup(Bukkit.getWorlds().get(0), player);
        val prefix = chatApi.getGroupPrefix(Bukkit.getWorlds().get(0), primaryGroup);
        val suffix = chatApi.getGroupSuffix(Bukkit.getWorlds().get(0), primaryGroup);
        return new Group(prefix, suffix);
    } catch (Exception exception) {
        return new Group();
    }
}
Also used : lombok.val(lombok.val) Group(com.nextplugins.economy.api.group.Group)

Example 2 with Group

use of com.nextplugins.economy.api.group.Group 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)

Example 3 with Group

use of com.nextplugins.economy.api.group.Group in project NextEconomy by NextPlugins.

the class NextTestServerGroupWrapper method getGroup.

@Override
public Group getGroup(String player) {
    val user = userStorage.findUserByName(player);
    if (user == null)
        return new Group();
    val group = user.getGroup();
    return new Group(group.getPrefix(), "");
}
Also used : lombok.val(lombok.val) Group(com.nextplugins.economy.api.group.Group)

Aggregations

Group (com.nextplugins.economy.api.group.Group)3 lombok.val (lombok.val)3 AsyncMoneyTopPlayerChangedEvent (com.nextplugins.economy.api.event.operations.AsyncMoneyTopPlayerChangedEvent)1 DiscordValue (com.nextplugins.economy.configuration.DiscordValue)1 RankingValue (com.nextplugins.economy.configuration.RankingValue)1 SimpleAccount (com.nextplugins.economy.model.account.SimpleAccount)1 LinkedList (java.util.LinkedList)1 EventHandler (org.bukkit.event.EventHandler)1