Creating config.yaml with key value pairs in lists

Discussion in 'Plugin Development' started by croxis, Apr 9, 2011.

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

    croxis

    I am trying to add multiple boundaries for my border plugin, however I am running into issues trying to write the configuration. This is what I am going for:
    Code:
    worlds:
        world:
            -
                radius: 20
                z: -70
                x: -30
                exceptions:
                    - Player1
                    - Player2
            -
                radius: 40
                z: 0
                x: 0
                exceptions:
                    - Player2
                    - Player3
    However I can't figure out how to set it up this way with setProperties (where is my python dict when I need it!). Any suggestions?
     
    islendingabok_team likes this.
  2. Offline

    Lodran

    I don't have any help for you, but I do have the same question. Anyone care to enlighten us?
     
  3. Offline

    vildaberper

    Border class:
    Code:
    public class Border{
        private int radius, x, z;
        private List<String> exceptions;
    
        public Border(int radius, int x, int z, List<String> exceptions){
            this.radius = radius;
            this.x = x;
            this.z = z;
            this.exceptions = exceptions;
        }
        ...getters and setters...
    }
    
    Declare the list:
    Code:
    public List<Border> borders = new ArrayList<Border>();
    
    Load the borders:
    Code:
    for(int u = 0; u < config.getKeys("worlds").size();u++){
        world = config.getKeys("worlds").get(u);
        for(int i = 0; i < config.getKeys("worlds." +config.getKeys("worlds").get(u)).size(); i++){
            radius = config.getInteger("worlds." + config.getKeys("worlds").get(u) + "." + config.getKeys("worlds." + config.getKeys("worlds").get(u)).get(i) + ".radius", 0);
            x = config.getInteger("worlds." + config.getKeys("worlds").get(u) + "." + config.getKeys("worlds." + config.getKeys("worlds").get(u)).get(i) + ".x", 0);
            z = config.getInteger("worlds." + config.getKeys("worlds").get(u) + "." + config.getKeys("worlds." + config.getKeys("worlds").get(u)).get(i) + ".z", 0);
            exceptions = config.getStringList("worlds." + "world." + config.getKeys("worlds." + config.getKeys("worlds").get(u)).get(i) + ".exceptions", new List<String());
        }
    }
    
    Save the borders:
    Code:
    for(int i = 0; i < borders.size(); i ++){
        config.setProperty("worlds." + border.get(i).getWorld() + "." + border.get(i).getId() + ".radius", border.get(i).getRadius());
        config.setProperty("worlds." + border.get(i).getWorld() + "." + border.get(i).getId() + ".x", border.get(i).getX());
        config.setProperty("worlds." + border.get(i).getWorld() + "." + border.get(i).getId() + ".Z", border.get(i).getZ());
        config.setProperty("worlds." + border.get(i).getWorld() + "." + border.get(i).getId() + "exceptions", border.get(i).getExceptions());
    }
    
    It would look like this:
    Code:
    worlds:
        world:
            border1:
                radius: 20
                z: -70
                x: -30
                exceptions:
                    - Player1
                    - Player2
            border2:
                radius: 40
                z: 0
                x: 0
                exceptions:
                    - Player2
                    - Player3
    
     
  4. lol i am having the same problem, and I agree that Python dicts and Python in general rule the world :D... btw im working on a Jython2Bukkit bridge so maybe eventually a python dict could be used here
     
Thread Status:
Not open for further replies.

Share This Page