Solved Iterating Through Config

Discussion in 'Plugin Development' started by mcserverdev, Jul 14, 2014.

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

    mcserverdev

    I have a config like so:
    Code:java
    1.  
    2. ranks:
    3. A: 0
    4. B: 50000
    5. C: 100000
    6. D: 250000
    7. E: 1000000
    8. F: 5250000
    9. G: 10000000
    10. H: 60000000
    11. I: 95000000
    12. J: 111000000
    13. K: 150000000
    14. L: 300000000
    15. M: 770000000
    16. N: 800000000
    17. O: 910000000
    18. P: 1075000000
    19. Q: 4000000000
    20. R: 6200000000
    21. S: 8750000000
    22. T: 8000000000
    23. U: 10000000000
    24. V: 13000000000
    25. W: 20000000000
    26. X: 35000000000
    27. Y: 50000000000
    28. Z: 75000000000


    Is there a way I can iterate through that? I want to check which group the player is currently in and get the next one. Can anyone help?
     
  2. Offline

    nzkiwi.5000

    I don't remember exactly but i think its something like that:

    ConfigurationSection cs = getConfig()
    cs.getValues(false); //this returns a HashMap<String, Object> representing config contents.

    The values are identicals as on YAML (both YAML and hashMap represent Key-Value pairs)
    Ex.:
    Get the value of C from this hash map
    HashMap<String, Object> hm = cs.getValues(false);
    int c = Integer.valueOf(cs.get("c") + " ");

    cs.get(...) is convertes to strong with +" " because valueOf accepts only string.

    the you have to convert Objects to ints (a loop iterating over a hashmap.keySet() converting Object to string then to int)

    If you need help Tahg me .

    This code is written as-i-remember it and should work. feel free to look ad the docs http://jd.bukkit.org
     
  3. Offline

    ImDeJay

    Use vault to get what group the player is in.
    then proceed from there

    If player is in group D then obviously E group is next, so just change the players group.

    Unless im misunderstanding what your trying to do .
     
  4. Offline

    hankered

    I suggest doing a config for each player, something like:
    Code:
    Players:
     
    (Player Name):
    Rank:
    and then use the OP to go through. it
     
  5. Offline

    Ba7marker

    ImDeJay
    That would mean hard coding the alphabet into the plugin not giving access to other rank names
     
  6. Offline

    ImDeJay


    If your doing what i think your trying to do, you don't have to hard code it.
    I made a plugin like this, if i'm right about what you're doing.

    What i made was for donors to claim their money after a server reset. i had to check what group the person was in, then i checked the config to see if that group had a value, if it did, i gave that person their money.

    What you need to do is loop through all the ranks, then check if the player is in that group. here is the code i used for my plugin modified for your config.

    Code:java
    1. ConfigurationSection groups = this.getConfig().getConfigurationSection("ranks");
    2.  
    3. for(String gName : groups.getKeys(false)){
    4.  
    5. if(perms.playerInGroup(player, gName)){ //uses vault to check if player is in any of the groups define in the config.
    6.  
    7. long a = this.getConfig().getLong("ranks." + gName); //gets the amount of money that should be paid in your case would resolve to 'ranks.A' or 'ranks.b' etc etc.
    8.  
    9. this.payPlayer(player, a); //This is a method i created to pay players
    10.  
    11. }
    12.  
    13. }


    if you need further help just tahg me.
     
  7. Offline

    mcserverdev

    imjack16 that is what I had done at first but it was really messy considering that these groups went from A to Prestige Free
    a, b, c -> Prestige Z Prestige Free

    ImDeJay hankered ImDeJay nzkiwi.5000 Thank you all for the responses! :D

    ImDeJay Yours seemed to work for me, thanks!
     
Thread Status:
Not open for further replies.

Share This Page