Solved Config.yml doesn't save ??? :(

Discussion in 'Plugin Development' started by Nico4898, Aug 23, 2014.

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

    Nico4898

    Hi there,
    I'm using a config.yml file in my Plugin ,which should save the uuid of a Player , but when I open the config it's not written in it.... :( Could anybody help my with that???

    MainClass
    Code:java
    1. package me.Nico4898;
    2.  
    3. import java.io.File;
    4.  
    5.  
    6.  
    7. import org.bukkit.configuration.file.FileConfiguration;
    8. import org.bukkit.plugin.Plugin;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11.  
    12. public class MainVillagerPvP extends JavaPlugin {
    13.  
    14. File newConfig;
    15. FileConfiguration newConfigz;
    16.  
    17. private static MainVillagerPvP plugin;
    18. public static Plugin getPlugin() {
    19.  
    20. JavaPlugin plugin = MainVillagerPvP.plugin;
    21.  
    22. return plugin;
    23.  
    24. }
    25.  
    26. public void onEnable(){
    27. plugin = this;
    28. new quitev(this);
    29. System.out.println("VillagerDrop aktiv!");
    30. loadConfig();
    31. }
    32.  
    33.  
    34. public void onDisable(){
    35. System.out.println("VillagerDrop inaktiv!");
    36. }
    37.  
    38.  
    39.  
    40. private void loadConfig() {
    41. final FileConfiguration cfg = this.getConfig();
    42. cfg.options().copyDefaults(true);
    43. this.saveConfig();
    44. }
    45. }
    46.  




    Adds it to Config
    Code:java
    1.  
    2. Player p = Bukkit.getPlayer(event.getEntity().getCustomName().toString());
    3. String uuid = p.getUniqueId().toString();
    4. if(!cfg.getStringList("Logouts").contains(uuid)){
    5. cfg.getStringList("Logouts").add(uuid);
    6. MainVillagerPvP.getPlugin().saveConfig();
    7. MainVillagerPvP.getPlugin().reloadConfig();
    8. }


    Removes it from Config
    Code:java
    1. if(cfg.getStringList("Logouts").contains(uuid)){
    2. cfg.getStringList("Logouts").remove(uuid);
    3. MainVillagerPvP.getPlugin().saveConfig();
    4. MainVillagerPvP.getPlugin().reloadConfig();
    5. }


    config.yml
    Code:java
    1. Logouts:
     
  2. Offline

    stormneo7

    What if the player doesn't have a custom name?...
    Your path would be 'null'; there's nothing to save.
    I also believe that players cannot have a custom name. They can only have a Display Name.

    Also, since you are using Bukkit.getPlayer(), it's best to use OfflinePlayer instead of Player because they might not be online.
    Alternatively, use Bukkit.getOfflinePlayer();
     
  3. Offline

    Nico4898

    I'm using this code in an enetity death Event and it gets the customname of the Mob , it it has one.
     
  4. Offline

    L33m4n123

    you nowhere change any settings in your config
     
  5. Offline

    molenzwiebel

    Using getStringList().add doesn't actually change the value in the config. What you need to do is:
    1. Get the list with getStringList(path)
    2. Change the list (add, remove)
    3. Save the list with set(path, list)
     
  6. Offline

    Nico4898

    Still doesn't work...
    Code:java
    1. List<String> Logout = cfg.getStringList("Logout");
    2.  
    3. if(!Logout.contains(uuid)){
    4. Logout.add(uuid);
    5. cfg.set("Logout", Logout);
    6. MainVillagerPvP.getPlugin().saveConfig();
    7. MainVillagerPvP.getPlugin().reloadConfig();
    8. }

    EDIT: Fixed it now :)
     
Thread Status:
Not open for further replies.

Share This Page