Solved Config list gets emptied when new thing gets added?

Discussion in 'Plugin Development' started by Larsn, Jul 1, 2015.

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

    Larsn

    I have these three if statements set up:
    First if statement (working) (open)

    Code:
    if(plugin.getDispensersConfig().contains("." + p.getName()) == false){
                            plugin.getDispensersConfig().set("." + p.getName() + ".dispenser1" + ".id", 1);
                            plugin.getDispensersConfig().set("." + p.getName() + ".dispenser1" + ".cords", Main.LocList);
                            plugin.saveDispensersConfig();
                        }

    Second if statement (not working) (open)

    Code:
    if(args.length >= 1){                       
                            ArrayList<String> allColors = new ArrayList<String>();
                            for(int i = 1;i<args.length;i++){
                                allColors.add(args[i]);
                            }
                            p.sendMessage(allColors.toString() + " < colors");
                            int dispenserAmount = plugin.getDispensersConfig().getConfigurationSection(p.getName()).getKeys(false).size();
                            plugin.getDispensersConfig().set("." + p.getName() + ".dispenser" + dispenserAmount + ".colors", allColors);
                            plugin.saveDispensersConfig();
                            allColors.clear();
                        }
    

    Third if statement (not working) (open)

    Code:
    if(args.length >= 1){
                            ArrayList<String> allFadeColors = new ArrayList<String>();
                            for(int i = 1;i<args.length;i++){
                                allFadeColors.add(args[i]);
                            }
                            int dispenserAmount = plugin.getDispensersConfig().getConfigurationSection(p.getName()).getKeys(false).size();
                            plugin.getDispensersConfig().set("." + p.getName() + ".dispenser" + dispenserAmount + ".fColors", allFadeColors);
                            plugin.saveDispensersConfig();
                            allFadeColors.clear();
                        }
    


    My problem is:
    The first "cords" if statement adds the cords just fine into the config file. Also when allColors get added it works, but then it messes up: when I add fColors to my config this happens:
    dispenserconfig.yml (open)

    PlayerName:
    dispenser1:
    id: 1
    cords:
    - 28
    - 64
    - 224
    colors: []
    fColors:
    - blue
    - green
    - red


    I can't get my head around what is going wrong.

    It's probably the most obvious thing ever too.

    Facepalm.
    Told you it was obvious.
    I was clearing it after the statement, instead of the beginning.

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

Share This Page