Config Help

Discussion in 'Plugin Development' started by bobthefish, Aug 2, 2014.

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

    bobthefish

    Hi,

    I am trying to add something from a config file into an ArrayList. how might I do this. here is an example config file

    Code:
    Example-Players:
      Example-me:
        Example-Kills: 2
        Example-Deaths: 5
        Example-Bank: 20
      Example-him:
        Example-Kills: 3
        Example-Deaths: 4
        Example-Bank: 29
      Example-her:
        Example-Kills: 1
        Example-Deaths: 3
        Example-Bank: 10
    I would like to add Example-me, Example-him, and Example-Her into an array list, but not add their things like kills and deaths. any help?
     
  2. Offline

    xTigerRebornx

    bobthefish use ConfigurationSection#getKeys(), it gives you the "keys" in that section, passing in true will give child nodes, so you want to pass in false so that it only gets the direct keys.
     
  3. Offline

    bobthefish

    I looked at that, but it seems to be a String, not an array list, is that because i probably don't know what I am doing?

    I tried

    Code:
    ArrayList<String> ls = getConfig.getConfigurationSection("Example-Players").getKeys(false);
    it said that it could not convert from set to arraylist, the only thing is, i don't know what a set is :p so... idk what to do, besides go learn more java, which Im working on
     
  4. Offline

    xTigerRebornx

    bobthefish getKeys() returns a Set, not an ArrayList. Set is another form of a collection that prevents duplicate elements. You should still be able to use it as you would a List (aside from method name changes and possibly a few others things)
     
    bobthefish likes this.
  5. Offline

    bobthefish

    Ok, I see, what I wanted to do with it is basically be able to put all of the players in an array list in order of highest kill to lowest kill count. I was going to do this by getting all of the names in the config file, then in a for loop putting each kill for each name into an array list, then organizing the array list. can I still do that with a set?

    I looked at it a little bit, it looks like it should work, thank you xTigerRebornx

    EDIT: How might I use the ArrayList's get(index) for a Set?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    xTigerRebornx

    bobthefish The set is a LinkedHashSet (could change at any time), so AFAIK, there is no equivalent to it. There is probably another way to do what you want, such as using a comparator, or simply making a new ArrayList and transferring the contents.
     
  7. Offline

    bobthefish

    xTigerRebornx ok, I got it to an array list, but I ran into another problem, this one is with my logic. so I am trying to create a leaderboards sort of thing. so what I need to do is order each player in the array list by his kills. how might I do that? my problem is that I can create a separate array list of integers and order that, but then I have nothing to tie it back to any specific player.
     
  8. Offline

    xTigerRebornx

Thread Status:
Not open for further replies.

Share This Page