Get integer from all data in config.yml

Discussion in 'Spigot Plugin Development' started by KohakuSaintCrown, May 25, 2016.

  1. Hi, i want to get the data from all data in my config.yml
    for example i want get the integer from:
    player1: 10
    player2: 16
    player3: 15

    i want get and collect in array all integers.
  2. Get the configuration section that is storing all the players, use getConfig().getKeys() in a loop, then use getConfig().getInt(*String Path*); and add them all to an array.
    • Agree Agree x 2
  3. You'll actually want to use getConfig().getKeys(true) because you want to collect keys with values. :)
    Not trying to be rude to you @Hunky524 just expanding on your idea.
    • Agree Agree x 1
  4. Useless if there's only what author said in his file.
    getKeys(true) is for getting subvalues, like
    player1: 10

    getKeys(false) will return "players"
    and getKeys(true) will return "players" "player1"
  5. I don't think that's true, I think the point of getting keys will only get the config sections if false, if true then it will list keys with values attached, at least that's what I've seen work before. If I'm wrong feel free to link me to a javadoc or something that supports your point of view. I might be wrong in this.
    • Agree Agree x 1
  7. Damnit man, use code tags! :'(
  8. Damnit man, don't except spoonfeeding !
  9. how would he use code tags for that?
  10. Code (Java):
    Set<String> sets = Config#getConfigurationSection(String path)#getKeys(boolean value);

    for(int i : sets + p.getName()) {
       // i returns to the playername's int value
    • Optimistic Optimistic x 1
  11. I like to use for each loops with a Set just fine it easier
  12. well I don't see any efficient much easier than this way.
  13. With a for each loop you dont have to get the element with the int plus a Set doesn't give you a direct method to get the element unlike with an ArrayList with #get()
  14. Code (Java):
    FileInputStream fs=newFileInputStream("someFile.txt");
    BufferedReader br =newBufferedReader(newInputStreamReader(fs));
    for(int i =0; i <31;++i)
    String lineIWant = br.readLine();
  15. Orrr:

    for(String path : Config#..#getKeys(false)){

    Just showing what I would prefer to do
  16. eh ??

    Code (Java):
    Set<String> set = #Set;

    for(String s : set) {
  17. That literally has no relevance to anything mentioned in the thread, other than that you're interacting with a File in a way that, still, wasn't mentioned in this thread.
    • Agree Agree x 1
  18. Why would you take the extra step to store the set in temporary memory if you're just wasting a line, I mean what else will you do with the set?
  19. He seems to have his own skewed views of Java conventions so he probably thought it was what the OP was asking about.