Solved ConfigurationSection cannot be read if there's a stringlist before it?

Discussion in 'Plugin Development' started by XXLuigiMario, Dec 14, 2014.

Thread Status:
Not open for further replies.
  1. ConfigurationSection will always be null even if it DOES exist but can't be read.

    Here's my NPE:

    Code:
    ConfigurationSection actions = ccommand.getConfigurationSection(value);
                            for (String action : actions.getKeys(false)) {
    ccommand's path is "Commands.SaveMe", and value equals "Run".

    Config:

    Code:
    Commands:
      SaveMe:
        Enabled: true
        Permission: none
        Cost: 0
        Output:
        - You were teleported to safety, %PLAYER%.
        Run:
          Teleport: world;0;0;0
          Health: 20
          Hunger: 20
    
    But here's the weird thing... If I remove "Output: blablablabla", it works just fine...

    It does work now... I think YAML was just being weird as always. -.-

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

    Techy4198

    @XXLuigiMario Why do you use a list if it's just one string?
     
  3. That's just an example... what If people wanna have multiple lines?
     
  4. Offline

    Techy4198

    @XXLuigiMario Why would one wish to take up multiple lines to tell a player why they've been teleported?
    Anyway, I believe it may be an indentation issue. Add two spaces before the -.
     
  5. Offline

    tcvs

    @XXLuigiMario If they wanted multiple lines you could add in support for it to seperate the line when they use for example \n. That way it is not a list where there could be spacing issue.
     
  6. Also... It's not just being teleported it can do other things.
    I don't think so, as the config was created automatically adding defaults from inside code.
    I don't know, I think i'll leave it like that, so It's easier to read.
     
  7. Offline

    caderape

    String path = "Commands.SaveM.Run";
    for (String s : config.getconfigurationsection(path).getkeys(false)
    s will be teleport, health and hunger
    so a config.getstring(path+"."+s) will get all the values
     
  8. Offline

    tcvs

    @XXLuigiMario It may be easier to read but may in the end cause more issues as a lot of users don't understand YAML formatting.
     
  9. Offline

    fireblast709

    It's not an identation issue, YAML will still parse it perfectly fine
     
  10. It wasn't YAML's fault I found out that while I was copy-pasting some code from another class into a switch I accidentally replaced the "break;" statement in one of the cases, so it was falling through, so value had "Output" as it's value, and given that "Output" is not a configuration section, it was giving a NullPointerException, but eclipse didn't warn me about it missing the break statement, because by default it ignores it :/

    Also, how do I set this thread to solved (I can't see the edit button :/), I fixed the problem this morning, but people are still commenting. Edit: Nvm, now it's under Thread Tools.
     
Thread Status:
Not open for further replies.

Share This Page