Adding something to config file

Discussion in 'Plugin Development' started by AppleMC, Mar 26, 2015.

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

    AppleMC

    Hi guys, I was wondering how to get something added onto a config file when the player hasn't joined the server before, my code doesn't seem to be working and I don't really know why :/

    if (p.hasPlayedBefore() == false) {

    add a path into the config file?

    }
     
  2. Offline

    ColonelHedgehog

    You'll want to use: config.set("Path.To.Variable", myObject);
     
  3. Offline

    AppleMC

    @ColonelHedgehog
    I've tried that, but it doesn't work :/

    @ColonelHedgehog
    This is the code I have currently

    plugin.getConfig().set("Users." + p.getName(), 0);
     
    Last edited by a moderator: Mar 26, 2015
  4. Offline

    nverdier

    @AppleMC What doesn't work about it? Have you used the #saveConfig() method?
     
  5. Offline

    AppleMC

    @nverdier
    Yes I have saveConfig() in there.
     
  6. Offline

    nverdier

    @AppleMC Please post the entire code.
     
  7. Offline

    AppleMC

    public void onPlayerJoin(final PlayerJoinEvent e) {

    Player p = e.getPlayer();

    if (p.hasPlayedBefore() == false) {

    plugin.getConfig().set("Users." + p.getName() + ".Rep", 0);
    plugin.saveConfig();

    }

    }

    }
     
  8. Offline

    SuchSwegMuchWow

    @AppleMC It probably doesn't work, because you played on the server before. Try checking if they are in the config instead
     
  9. Offline

    AppleMC

    @SuchSwegMuchWow
    No I remade the server to ensure that I haven't played it before, how would I check if they were in the config or not? :/
     
  10. Offline

    SuchSwegMuchWow

    @AppleMC
    Code:
    if(getConfig().contains(player.getName){
    //There in the config
    }
    else{
    //Add them to config
    }
     
  11. Offline

    AppleMC

Thread Status:
Not open for further replies.

Share This Page