Development Assistance Mulitple Variables in one Path

Discussion in 'Plugin Help/Development/Requests' started by MrSamuelB, Dec 30, 2015.

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

    MrSamuelB

    Hello. So on PLayerJoinEvent, I know how to create a path but how would I add multiple things to it. so my code looks sort of like
    Code:
    onJoin(PlayerJoinEvent e){
    Player p = e.getPlayer;
    if(!getConfig().contains(p.getName())) {
      getConfig().addDefault(p.getName(), null)
    }
    }
    im not sure if thats exactly how i have it but the thing im confused about how to do is have my config look like this:

    Code:
    mrsamuelb:
      kills:
      deaths:
      ration:
      something:
      somethingelse:
    Anything would help! Thanks for reading!
     
  2. Offline

    biewers2

    You could try creating a statement for each sub-path like this:
    Code:
    onJoin(PlayerJoinEvent e) {
        Player p = e.getPlayer();
    
        if (!getConfig().contains(p.getName())) {
            getConfig().addDefault(p.getName(), null);
            getConfig().addDefault(p.getName() + ".kills", null);
            getConfig().addDefault(p.getName() + ".deaths", null);
            getConfig().addDefault(p.getName() + ".ration", null);
            getConfig().addDefault(p.getName() + ".something", null);
            getConfig().addDefault(p.getName() + ".soemthingelse", null);
        }
    It's a bit messy but it gets the job done. You could also use a map which I don't know much about.
     
  3. Online

    timtower Administrator Administrator Moderator

    @MrSamuelB if config !contains name
    createConfigurationSection name
    end if
    getConfigurationSection name.set("kills",value)

    @biewers2 Why would you use addDefault? And null will remove the key value pair.
     
  4. Offline

    biewers2

    @timtower I was just addressing the question on how to add multiple sub-classes. I agree addDefault() shouldn't be used in this case but I used it now to agree with @MrSamuelB 's code.
     
Thread Status:
Not open for further replies.

Share This Page