How to save value in config?

Discussion in 'Spigot Plugin Development' started by kinukin, Jun 4, 2017.

  1. If I wrote something in a config, how would I save it?

    Because at the moment it just resets to its default value:

    Code (Text):
    customConfig.set(p.getUniqueId().toString() + ".nickname", "");
     
  2. To save it do customConfig.getKeys(false); and if that doesn't work try customConfig.save();
     
  3. Err.. MemorySection#getKeys just returns a set of the keys in the config. FileConfiguration#save is what OP is looking for.
     
  4. That's what I meant, didn't know if his customConfig was either value.
     
  5. It still gets reset to a blank space.

    Also I can't set a string, any idea why?

    Items.customConfig.set(p.getUniqueId().toString(), "this will be blank");
     
  6. You can save a string to a config.
    FileConfiguration#set(path, string)
    FileConfiguration#save

    optional: FileConfiguration#reload

    personally, I create a method so I don't forget to save and update the config each time I save something to it.
    Code (Text):
    public void setConfig(String path, Object obj) {
          getConfig().set(path, obj);
          getConfig().save();
          getConfig().reload();
    }