Solved How to check if a configuration section is empty?

Discussion in 'Plugin Development' started by XXLuigiMario, Jul 11, 2014.

Thread Status:
Not open for further replies.
  1. Imagine I have a config like this:
    Code:
    Worlds:
      World1:
        Spawn:
          x: 123
          y: 123
          z: 123
    
    How can I check if the configuration section "Worlds" is empty?
     
  2. Offline

    Anonomoose

    if(settings.getConfig().contains("Worlds"), should work fine
     
  3.  
  4. Offline

    Epicballzy

    Maybe do something like:
    Code:java
    1. if(settings.getConfig().getConfigurationSection("Worlds") == null) {
    2. //Do your stuff...
    3. }
     
  5. I already tested it :/
    It only checks if it exists.
     
  6. Offline

    JustinsCool15

    Can you post more of the code so we can see how you're using the data in the config?
     

  7. Code:
    Settings:
      Enabled:
      PrefixEnabled:
      Prefix:
      Message:
      AlternativeMessage:
    List:
      Command:
        Permission:
        Message:
    ^ This is my config, I just need to check if the configuration section (List) is empty or not.
     
  8. Offline

    JustinsCool15

    When are you trying to check if it's empty? During an event, once a command is executed, etc.?
     
  9. Inside a method.
     
  10. Offline

    fireblast709

    XXLuigiMario getConfigurationSection() in combination with getKeys() and isEmpty()
     
  11. fireblast709 Thanks for the reply, i'll try it in a sec :D

    It's working :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page