Solved Point rankings for players

Discussion in 'Plugin Development' started by ScopeTowel, Mar 16, 2020.

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

    ScopeTowel

    I have a question, would like to know how I could do so that when I do /ranking, it gives me the rankings of the players say that:

    Player 1 : 20 points
    Player 2 : 10 points
    Player 3 : 45 points


    I would like it to display like this :

    ----------------=RANKING=-------------------
    Player 2 - 10 points
    Player 1 - 20 points
    Player 3 - 45 points
    ---------------------------------------------------

    How can i do that
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    ScopeTowel

    @timtower In a HashMap like:

    HashMap<Player, Integer> = new HashMap<>();
     
  4. Offline

    timtower Administrator Administrator Moderator

    Make a copy of the hashmap.
    Find the highest value.
    Send to the players.
    Remove key from copy.
    Repeat ... times.
     
  5. Offline

    ScopeTowel

    @timtower , 1er i don't know how to find the hightest value, 2e treemap ?
     
  6. Offline

    timtower Administrator Administrator Moderator

    @ScopeTowel 1. You loop over the map.
    2. Why do you think treemap? Any map will do.
     
  7. Offline

    KarimAKL

  8. Offline

    ScopeTowel

    Can you give me an example ?

    @timtower Because I know how to display them but not to sort

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 16, 2020
  9. Offline

    yPedx

    Why not store the UUID instead? Unless I remember wrong, it's not recommended to store Player objects.
     
  10. Offline

    timtower Administrator Administrator Moderator

    @ScopeTowel Have you tried the link that KarimAKL posted?.
    You are correct in that.
     
  11. Offline

    ScopeTowel

    @timtower
    Yes I know, but I put that, because its with an api, the real HashMap is :

    HashMap<Faction, Integer>

    But i need an exemple, because i don't know how to found the highest value with a loop
     
  12. Offline

    timtower Administrator Administrator Moderator

    https://stackoverflow.com/questions/5911174/finding-key-associated-with-max-value-in-a-java-map
    https://www.baeldung.com/java-find-map-max
    https://www.leveluplunch.com/java/examples/find-max-value-in-map/
    https://www.geeksforgeeks.org/finding-minimum-and-maximum-element-of-a-collection-in-java/
    https://www.spigotmc.org/threads/get-the-highest-value-in-an-hashmap.378153/
    And a couple hundred more if you start to search.
     
Thread Status:
Not open for further replies.

Share This Page