Getting highest player balance - Essentials - Vault

Discussion in 'Spigot Plugin Development' started by JacksonHogan, Jun 10, 2016.

Thread Status:
Not open for further replies.
  1. How would i go about getting the highest player balance from vault, Kinda like a baltop.
     
  2. You could loop through Bukkit.getOfflinePlayers
     
  3. Just loop through all of the keys it stores (not sure if it's yml based) and check who has the highest balance out of all of them.
     
  4. I'm using hashmaps.
    How would i loop through them and get the highest integer (double) value?
     
  5. Ah, just loop through each key and get the corresponding value.
     
  6. Code (Text):
    double highest = 0

    for(Double value: map.values())
    {
        if( value > highest)
            highest = value;
    }
    That's just basic Java. I'd recommend reading some Java tutorials online to get the basics before making plugins.
     
  7. That won't work exactly. The user doesn't know the highest amount.
     
  8. Code (Text):
    int maxValue = Collections.max(yourMapHere.values());
     
  9. The highest is a placeholder, which'll give you highest value.
     
  10. Yes it would.
     
    • Agree Agree x 1
  11. I've already posted how to get the highest value. The above method does not work. A "placeholder" does nothing at all.
     
  12. Sorry, I missed the bit where it was setting the new value. But using my method is more efficient and more readable.
     
  13. Yours uses Java 8, not everything supports Java 8.

    -_- One day you'll realize what I mean.
     
  14. I am so confused....
    If i use Double balTop1 = Collections.max(topbal.values());
    Code (Text):
    Double balTop1 = Collections.max(topbal.values());
    Then how would i get the player?
     
  15. Use this:
    Code (Text):
    double highest = 0;
    Player highestPlayer;

    for (Map.Entry<Player, Double> balance : map.entrySet())
    {
        if(balance.getValue() > highest)
        {
            highest = balance.getValue();
            highestPlayer = balance.getKey();
        }
    }
     
    #15 SpiroMarshes, Jun 11, 2016
    Last edited: Jun 11, 2016
  16. I realized pretty quickly! xD I just had skimmed your code before without totally reading it. And yes, almost everything now supports Java 8 (this includes our main source of development in this case... namely Minecraft :p)
     
  17. Just thought I'd pop in here to say Java 8 is the recommended version to use.

    It is strongly advised to stop supporting Java 7 in favor of Java 8. Java 7 has been EOL for over a year now, and is no longer receiving security updates. Supporting anything less than Java 8 is enabling security risks, not to mention limiting you from using the new features it offers.

    Last thing we need is a repeat of Java 6 lasting 10 years too long after it was marked EOL. Let Java 7 die already.
     
    #17 BillyGalbreath, Jun 11, 2016
    Last edited: Jun 11, 2016
    • Agree Agree x 1
  18. I meant for idiotic shared hosts. I love Java 8 for the simplicity it offers, the reliable, and the overall improvements. I use Java 8 for my server & my private plugins.

    However, if you're working on a public plugin its best to make it compatible with Java 7&8.
     
  19. Yeah... No it's not. If you're looking for publicity, go ahead compile with JDK 7. If you're smart and know that Java 7
    you would switch to Java 8 regardless if it's a public plugin or not. If these so called "popular Minecraft hosts" don't want to update their software, they probably shouldn't be running in the first place. Running outdated software can only cause bad things.
     
  20. Any idea how annoying it is to get the same complaints over and over again?
     
Thread Status:
Not open for further replies.