sort datas in .yml file

Discussion in 'Plugin Development' started by Typ, Jul 17, 2016.

Thread Status:
Not open for further replies.
  1. Hello,
    I've got another question: How do I sort the datas in a .yml file (The biggest number on the first Position).

    I am programming a plugin, where every Player has datas (How many blocks he has breaken, number of his deaths and kills, and so on) And I would like to sort it in a .yml file so, that in every cathegory you see all Players, from the best to the lowest, like this:

    Code:
    brokenBlocks:
      decoration:
        player2: 5300
        player1: 4543
        player3: 1233
      redstone:
        player2: 504
        player3: 320
        player1: 45
      materials:
        player2: 30218
        player1: 15390
        player3: 1749
    kills:
      player3: 4
      player1: 3
      player2: 3
    deaths:
      player1: 0
      player2: 3
      player3: 24 
    I hope everybody understands my Problem xD

    And I forgott something: I would Change the yml. file everytime, when a Player did something (break a block, killsomeone, ...) But this makes the Server very slow I think. If there's a better solution, please let me know ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 17, 2016
  2. Offline

    Firestar311

    This would be an example where you should use MySQL in your code. However if you want to use YAML, you can use threads which can be found using the BukkitRunnable object, then it does not freeze the main thread when it is trying to write to the file.
    An article about the BukkitRunnable object can be found here.
     
  3. Offline

    MCMastery

    Just sort the data once you retreive it...

    List<Integer>.sort(); auto sorts numbers.
     
  4. Offline

    Firestar311

    Haha, I forgot to answer the sort question. But this is what you would do so sort things from the YAML file.
     
    MCMastery likes this.
  5. Thank you very much, that all are good ideas!

    But there's one question left: I have to save a playername and a variable for him. How can I do this? How can I save the Player AND the variable in one Point of the Array list?
     
  6. Offline

    ipodtouch0218

    @Typ
    Use a HashMap<String,Integer> instead of the List<Integer>
    (String being the Player.getName())
     
  7. I agree.
     
  8. Offline

    ipodtouch0218

    Edit: Okey den.
     
    Last edited: Jul 19, 2016
  9. k ,now it should work!

    Thank you all very much!!
     
  10. Offline

    Tecno_Wizard

    @Typ, Keep in mind you cannot simply set a UUID into a config file. You must use toString and fromString. I think almost every person has made that mistake at some point. XD
     
Thread Status:
Not open for further replies.

Share This Page