Ranking

Discussion in 'Plugin Development' started by zakarls, Jun 19, 2014.

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

    zakarls

    How can I find the rank of a player based on kills if my config looked like this:
    Code:
    Player1:
      deaths: 10
      kills: 2
    Player2:
      deaths: 3
      kills: 4
    Player3:
      deaths: 7
      kills: 12
    
    Example:
    Since player3 has 12 kills they would be rank 1 and player2 would be rank 2 player1 rank 3.

    My question is how would I get this rank for each player.
    Thanks for any help
     
  2. Offline

    Deleted user


    coding in GChrome...
    something along the lines of this"

    Code:java
    1.  
    2. ConfigFile config = Plugin.getConfig();
    3. int player1deaths = config.getInt("Player1.deaths");
    4.  
     
  3. Offline

    Smerfa

    load all player to HashMap Nickname, kills

    So when you have map of all scores
    Code:
    Map<String, Comparable> variableMap = new HashMap<>();
    (you can change Comparable to other Object that is comparable, like Integer)
    And then use:
    Code:
    SortedMap<String, Comparable> sortedMap = ImmutableSortedMap.copyOf(variableMap, <one of two options>);
    But you have 2 options, sorting ASC or DESC so:
    Code:
    Ordering.natural().onResultOf(Functions.forMap(variableMap)).compound(Ordering.natural());
    or
    Code:
    Ordering.natural().reverse().onResultOf(Functions.forMap(variableMap)).compound(Ordering.natural().reverse());
    like:
    Code:java
    1. SortedMap<String, Comparable> sortedMap = ImmutableSortedMap.copyOf(variableMap, Ordering.natural().reverse().onResultOf(Functions.forMap(variableMap)).compound(Ordering.natural().reverse()));

    But is much better to use MySQL or LiteSQL :p

    That is good when you can't use SQLite because is only temporally data and that have no sense to add it to SQLite for 0.01 seconds :D
     
  4. Offline

    zakarls

    Smerfa
    Thanks but, since you are recommending MySQL do you have a link or something where i can learn how to use it?
     
Thread Status:
Not open for further replies.

Share This Page