config

Discussion in 'Spigot Plugin Development' started by TheFuzzyHead5, Apr 22, 2017.

  1. So here is my config:

    Code (Text):
    test:
      test1: 5
      test2: 7
      test3: 100
    So under "test" there are 3 sections which are all Integer values. My question is how to cycle through under "test" and the names of the sections, i.e. test1 etc.

    I've tried this:
    Code (Text):

            for (String line : this.getConfig().getConfigurationSection("test").getKeys(false)) {
                System.out.println(line.toString());
            }
     
    This actually prints out nothing and I've no idea why. Shouldn't it print out test1, test2 and test3?
     
  2. Why do you do line.toString() ? line is already a string.
    Also the "line" is your key.
    Code (Text):

            for (String key : this.getConfig().getConfigurationSection("test").getKeys(false)) {
                System.out.println(this.getConfig().getInt("test." + key));
            }
     
     
  3. Then why doesn't mine work?

    The "key", or as I called "line", should print out to the console as "test1" etc. right?
     
  4. Debug to see if your config is null (getConfig() etc.
     
  5. Yes, but i am not sure about the line.toString(). Just leave line alone
     
  6. Is the problem possibly that I have sections above it in the config?

    For example, my config could be:

    Code (Text):
    mobs:
      whatever: 5
    players:
      even-more-whatever: 10
    test:
      test1: 5
      test2: 7
      test3: 100
     
    I don't think it is but want to cover all grounds here.
     
  7. Have you made sure your config in the actual server has updated? Everything looks right and it should work
     
  8. change getkeys to true