Custom File StringList

Discussion in 'Plugin Development' started by Marten Mooij, Oct 17, 2014.

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

    Marten Mooij

  2. Offline

    fireblast709

    Marten Mooij if getConfig() is called before create / reload, then it will return null.
     
  3. Offline

    Marten Mooij

  4. Offline

    nopvpgamer

    Code:java
    1. public void addToList(String word) throws IOException{
    2. File file = new File("plugins//FOLDER//FILE.yml");
    3. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    4. List<String> wordlist = cfg.getStringList("wordlist");
    5. wordlist.add(word);
    6. cfg.set("wordlist", wordlist);
    7. cfg.save(file)
    8. }
    9.  
    10. public void removeFromList(String word) throws IOException{
    11. File file = new File("plugins//FOLDER//FILE.yml");
    12. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    13. List<String> wordlist = cfg.getStringList("wordlist");
    14. if(wordlist.contains(word){
    15. wordlist.remove(word);
    16. }
    17. cfg.set("wordlist", wordlist);
    18. cfg.save(file)
    19. }
    20.  
    21. //to show the stringlist ingame
    22. Player player = //PLAYER
    23.  
    24. player.sendMessage("Words from Stringlist:");
    25. player.sendMessage(wordlist.toString());
     
Thread Status:
Not open for further replies.

Share This Page