Solved Config change/replace

Discussion in 'Plugin Development' started by Elimnator, Feb 9, 2015.

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

    Elimnator

    I want to change/move sections in my config file.

    For example, I want to change this:
    Code:
    players:
      Bob:
        stuff: (All kins of lists and things under here)
      
    To this:
    Code:
    players:
      526929-45205580-349757:
        stuff: (All kins of lists and things under here)
      
     
  2. Offline

    jebbo

    Instead of getName() use getUniqueId()
     
  3. Offline

    timtower Administrator Administrator Moderator

    @Elimnator Get the configurationSection, get the keys (so that you will get the player names)
    Then get the section that belongs to the name
    Convert name to uuid
    Get uuid section
    Get ALL keys in the name section, so deep values
    uuid.set(key,name.get(key));
    Make sure to ignore configurationsections though.
     
  4. Offline

    Elimnator

    @timtower
    Like this?

    Code:
    getConfig().set("players." + p.getUniqueId().toString(), getConfig().getConfigurationSection("players." + p.getName()).getKeys(true));
     
  5. Offline

    timtower Administrator Administrator Moderator

  6. Offline

    Elimnator

  7. Offline

    timtower Administrator Administrator Moderator

    @Elimnator Told you already. Won't spoonfeed code.
     
  8. Offline

    Elimnator

    @timtower
    You said: "uuid.set(key,name.get(key));"

    I know how to set each value individually, thats not what I want.

    I want to ether move all the stuff under the name at once, or just replace the name with the UUID>
     
  9. Offline

    timtower Administrator Administrator Moderator

    @Elimnator You need to move them one by one though. Or being able to set the configurationsection, not sure if that works.
     
  10. Offline

    Elimnator

    @timtower
    I think I found a way to loop through all of them and set it, so it is 1 by 1, but its in a loop so I don't have to manually code it all.
     
  11. Offline

    timtower Administrator Administrator Moderator

    @Elimnator I never said that you couldn't use a loop...
     
  12. Offline

    Elimnator

    Ok, for anyone else who doesn't know how to do this, here is how to do it:
    Code:
                    for(String key : getConfig().getConfigurationSection("players." + p.getName()).getKeys(true)){
                        if(getConfig().isString("players." + p.getName() + "." + key)){
                            getConfig().set("players." + p.getUniqueId().toString() + "." + key, getConfig().getString("players." + p.getName() + "." + key));
                        }else if(getConfig().isInt("players." + p.getName() + "." + key)){
                            getConfig().set("players." + p.getUniqueId().toString() + "." + key, getConfig().getInt("players." + p.getName() + "." + key));
                        }
                    }
     
Thread Status:
Not open for further replies.

Share This Page