Solved Removing a key from a configuration section

Discussion in 'Plugin Development' started by Hoolean, Nov 24, 2012.

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

    Hoolean Retired Staff

    Hello! Now as I'm sure you are all aware there is the addDefault(path, value) method, is there a removeKey(path) method?

    E.g.
    Code:
    yay: Wafflecopter
    nong: Boogie
    Code:java
    1. config.removeKey("yay");

    Code:
    nong: Boogie
     
  2. Offline

    gomeow

    I believe you do something like this:
    Code:java
    1. config.set("path", null);

    I just read that somewhere, not entirely sure
     
  3. Offline

    fireblast709

    this would work for a config, though you would still get the default if the key is non-existant
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    That is only true if you blindly set copyDefaults to true.
     
  5. Offline

    fireblast709

    Sagacious_Zed high chance he uses defaults :3
     
  6. Offline

    Hoolean Retired Staff

    Didn't work, it stayed there :(
     
  7. Offline

    Hoolean Retired Staff

    Bumpity Bump
     
  8. Offline

    Hoolean Retired Staff

    Don't make me bring out the tags :p...
     
  9. Offline

    zeeveener

    Ok. Removing something from config files...
    Code:java
    1. File configFile = new File(getDataFolder(), "config.yml");
    2. FileConfiguration config = YamlConfiguration.loadConfiguration(configFile);
    3. config.set("yay", null);
    4. try{
    5. config.save(configFile);
    6. }catch(IOException e){
    7. Logger.getLogger("Minecraft").info("Twas an error");
    8. }
     
  10. Offline

    Hoolean Retired Staff

    Solved! I forgot to save the config xD
     
  11. Offline

    micrlink

    How would you remove it if it was a list or if it was a longer string when i set it to null it ends up like this
    Code:
    Test:
      Test1:
        test: message
      Test: {}
      Test3:
        test: message
     
Thread Status:
Not open for further replies.

Share This Page