top15 richest player with vault

Discussion in 'Plugin Development' started by dekrosik, Jan 10, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    dekrosik

    Hello i need made top15 richest player in tab
    Tab is done but i must make LinkedHashMap with the richest player
    but i don't know how;/
    vault have connection with mysql?
     
  2. Offline

    Boomer

    vault is merely a bridging program to the economy plugins, it is the responsibility of the economy plugin to take care of storing the data, so vault is not mysql linked, but the economy plugin would be.
     
  3. I really don't know if this can works but you can try to do this:
    Code:java
    1.  
    2. //On player join event
    3.  
    4. //Save player uuid in yml file or create a yml file with his uuid
    5.  
    6. //Get all uuids
    7.  
    8. //Get offlineplayer with the uuids
    9.  
    10. //Get offlineplayer money
    11.  
    12. //Use a map to make the top
    13.  
     
  4. Offline

    dekrosik

    who to get all uuids when i have config:
    Code:
    -uuid1
    -uuid2
    -uuid3
    
    and how i get this uuid to map/list?
     
  5. Offline

    drpk

  6. I don't know what MaTaMoR_ is really suggesting, his seems too over complicated. It is similar though, just does not need storing UUIDs... From what I think you want, you want to get the top 15 richest players on the server which uses Vault.

    I'm pretty sure you could easily do this, though if it is a big server (in terms of number of past players), this may be resource intensive:
    Code:
    Map<String, Integer> playerBalances = new HashMap<String, Integer>();
    for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
        if (vaultEconomy.hasAccount(onlinePlayer)) playerBalances.put(onlinePlayer.getName(), vaultEconomy.getBalance(onlinePlayer));
    }
    for (OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) {
        if (offlinePlayer != null && offlinePlayer.getName() != null) { // I have a habit of checking for nulls, you don't need this I think.
            if (vaultEconomy.hasAccount(offlinePlayer)) playerBalances.put(offlinePlayer.getName(), vaultEconomy.getBalance(offlinePlayer));
        }
    }
    // Sort playerBalances from largest to smallest - look up on how to do this. Then get the top 15 in the list, drpk gave a link.
    
    Sorting from largest to smallest: https://gist.github.com/aadnk/9632795

    Example:
    Code:
    MapSorting.sortedValues(playerBalances);
    
     
    Last edited: Jan 16, 2015
  7. Offline

    Experminator

    @dekrosik Java has a built-in sort function from the class Collections.
    You can use it with: 'Collections.sort(<arraylist or something>)'
     
  8. Offline

    xTrollxDudex

    How about instead of using runtime overhead, we cause more overhead upon insertion but much faster retrieval? There's Queues in the JCF (I'm looking at your PriorityQueue). Use a comparator to assign the wealthiest player a higher priority than the compared players.
     
Thread Status:
Not open for further replies.

Share This Page