-2

Vault is a plugin for Bukkit that is also an Economy API. It can be used to post updates to Players' money, and used as a Currency in a server.

VaultAPI is also open-sourced at Github

I'm trying to get the accounts which have the biggest amount of money, but that's not straight-forward in Vault's API.

So, what I tried to do was:

  1. Iterating through all OfflinePlayers and comparing money values
  2. Recovering the biggest value

Code:

double highest = 0;
OfflinePlayer topPlayer;
OfflinePlayer[] players = Bukkit.getOfflinePlayers();

for (OfflinePlayer p : players) {
    double playerAmount = econ.getBalance(p);    //Econ is Economy  instance from Vault.
    if (playerAmount > highest){
        highest = playerAmount;
        topPlayer = p;
    }
}

I tried iterating all acounts to find the highest amount, but it lags a lot when you have too many Players.

Is there any way to find which players have the biggest amount of money?

LeoColman
  • 6,950
  • 7
  • 34
  • 63

1 Answers1

2

There are a few ways you can accomplish this.

First of all, you could use Essentials' UserBalanceUpdateEvent and determine if the balance is higher than the high score in the config (in which case, you update the stored value with the new value and the UUID it belongs to).

Second, you could iterate through the OfflinePlayers, but using an Asynchronous task.

ColonelHedgehog
  • 438
  • 3
  • 18