Make a list of top values with their keys [HashMap]

Discussion in 'Plugin Development' started by ThatBox, Jun 20, 2012.

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

    ThatBox

    Sort of like a leader board.

    | Key | top value |
    | key | 2nd top value |

    I tried collections but I don't know how to get a key from that.

    Sql is not an option >.<
     
  2. Offline

    ProFatal

    From my knowledge of HashMaps I don't think you can sort them. BUT I think there is stuff called TreeMaps or something like that, that you can sort.
     
  3. Offline

    ThatBox

    I tried TreeMaps. You can only get the highest key from that. Maybe I can use the .firstEntry() though.
     
  4. Offline

    ProFatal

    You could use an array maybe?
     
  5. Offline

    ThatBox

    Yes but I wouldn't be able to get the keys from that only the values. >.<
     
  6. Offline

    Xemos

    You can use a config.yml to store it all; and thus it will hold persistent through server downtimes
     
  7. Offline

    ThatBox

    It is saved to a file already.
     
  8. Offline

    Xemos

    Retrieve the key in something like this to use in your plugin
    Code:
    List <String> leaderboard = config.getStringList(" Leaderboard.Winners");
    
    List is orginized by index values so 0 = 1st place 1 = 2nd place ect ect


    To set the leaderboard after you modify it
    Code:
    config.set("Leaderboard.Winners", null); //Deletes all in old
    config.set("Leaderboard.Winners", leaderboard); //Puts in new
    

    this is a rough idea of course.
     
Thread Status:
Not open for further replies.

Share This Page