Check if section in config exists

Discussion in 'Plugin Development' started by TheChugBug, May 22, 2014.

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

    TheChugBug

    I need to check when a player joins the server and isn't in the config to be added to the config.
    My code:
    Code:
    @EventHandler(priority = EventPriority.HIGH)
    public void onPlayerJoin(PlayerJoinEvent e) {
    final Player p = e.getPlayer();
    p.sendMessage("debug1");
    e.setJoinMessage("Debug join");
    if (!plugin.getConfig().contains("players." + p.getName())) {
    p.sendMessage("debug2");
    plugin.getConfig().set("players." + p.getName() + ".stuff", "none");
    plugin.getConfig().set("players." + p.getName() + ".stuff2", "none");
    }
    }
    
    My default config:
    http://pastebin.com/9G5DvCu6

    My error:
    http://pastebin.com/H5YQWSP3

    Please help!
     
  2. Offline

    rsod

    Well, your code seems to be working... can you post entrie class so we can see line numbers?
     
  3. Offline

    metalhedd

    The only part of your code that could raise a NullPointerException would be this line:
    Code:java
    1.  
    2. if (!plugin.getConfig().contains("players." + p.getName())) {
    3.  


    'plugin' is null.
     
  4. Offline

    AoH_Ruthless

    TheChugBug
    Something is wrong when you try to instantiate your main class variable ... can we see your global fields and your constructor?
     
Thread Status:
Not open for further replies.

Share This Page