Help adding things to string lists

Discussion in 'Plugin Development' started by Jackson12, May 26, 2015.

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

    Jackson12

    Hey, So what im trying to do here is make it so when players type /recommend <Staff Name> It saves the staff name that they recommended to the config.yml under the string "Recommendations" This is my code that i have, Please tell me what i can add in order for this to work (Or what i can change). Thanks for any help.
    Code:
                    cooldowns.put(player.getName(), System.currentTimeMillis());
                    player.sendMessage(ChatColor.GOLD + "You have successfully recommended:\n" + ChatColor.BOLD + ChatColor.LIGHT_PURPLE + (args[0]));
                    for (String line : getConfig().getStringList("Recommends")) {
                        player.sendMessage(line);
                    }    
    Please let me know if i need to add more of my code for you to understand what im saying i need.
     
  2. Offline

    Tecno_Wizard

    @Jackson12, you posted a thread that was extremely similar to this just this week. We're not going to keep spoon feeding you; you need to learn java.

    Use the .add(Object o) method of list and add another entry, then save the list back to the config.
     
    Last edited: May 26, 2015
  3. Offline

    Jackson12

    This is what i added
    Code:
    getConfig().getStringList("Recommends").add(args[0]);
    After i type /recommend Player then stop the server and go into the config its only showing one players name and its not making it a list.
     
    Last edited: May 26, 2015
  4. Offline

    SuperOriginal

    • store the list locally
    • add to that list
    • set the modified list as a whole back to the config
    • save config.
     
  5. Offline

    Jackson12

    This is what i have, and its not working, please help me.
    Code:
                    cooldowns.put(player.getName(), System.currentTimeMillis());
                    player.sendMessage(ChatColor.GOLD + "You have successfully recommended:\n" + ChatColor.BOLD + ChatColor.LIGHT_PURPLE + (args[0]));
                    getConfig().getStringList("Recommends").add(args[1]);
                   
                    for (String line : getConfig().getStringList("Recommends")) {
                        player.sendMessage(line);
                    }    
    Ok i got it, I added this....
    Code:
    List<String> Recommends = getConfig().getStringList("Recommends");
    Recommends.add(args[0]);
    getConfig().set("Recommends", Recommends);
    saveConfig();
    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