ConfigurationSection returning null when it exists!

Discussion in 'Plugin Development' started by viper_monster, Jun 4, 2014.

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

    viper_monster

    I have been struggling with this for a few hours not and I wen't out of ideas...

    This is the code I'm using:
    Code:java
    1.  
    2. if (getConfig().getConfigurationSection("itemStack.stack") == null) Bukkit.broadcastMessage("§4NULL");
    3. Map<String, Object> map = getConfig().getConfigurationSection("itemStack.stack").getValues(true);
    4.  


    and this is how config.yml looks like:
    PHP:
    itemStack:
      
    stack:
        
    amount1
        durability
    0
        type
    IRON_SWORD
        enchants
    :
        - 
    DAMAGE_ALL,642
        
    DURABILITY,1424
     
  2. Offline

    Mrawesomecookie

  3. Offline

    viper_monster

  4. Offline

    ever_x

    Well, does it broadcast NULL?
     
  5. Offline

    viper_monster

    ever_x I wouldn't create this thread otherwise...
     
  6. Offline

    Lolmewn

    Please post more code, like your whole onEnable and stuff (I'm guessing you're doing all this in onEnable).
     
  7. Offline

    viper_monster

    Lolmewn
    Code:java
    1.  
    2. if (!getConfig().contains("itemStack.stack")) {
    3. getConfig().createSection("itemStack.stack");
    4. saveConfig();
    5. }
    6.  
    7. ItemStack itemStack = new ItemStack(Material.IRON_SWORD, 1);
    8.  
    9. itemStack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 642);
    10. itemStack.addUnsafeEnchantment(Enchantment.DURABILITY, 1424);
    11.  
    12. SItemStack stack = new SItemStack(itemStack);
    13.  
    14. getConfig().set("itemStack.stack", stack.serialize());
    15. saveConfig();
    16.  
    17. if (getConfig().getConfigurationSection("itemStack.stack") == null) Bukkit.broadcastMessage("§4NULL");
    18. Map<String, Object> map = getConfig().getConfigurationSection("itemStack.stack").getValues(true);
    19.  
    20. Bukkit.broadcastMessage(map.toString());
    21.  
    22. SItemStack newStack = new SItemStack(map);
    23.  
    24. Bukkit.broadcastMessage(newStack.toString());
    25.  
     
  8. Offline

    Anonomoose

    Reload the config after saving the new path?
     
  9. Offline

    viper_monster

    Anonomoose looks like that worked xD Such a derp :p
     
Thread Status:
Not open for further replies.

Share This Page