More Config Help -- Arbitrary number of entries

Discussion in 'Plugin Development' started by croxis, Feb 12, 2011.

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

    croxis

    I'm working on a border plugin that supports individual configs for individual worlds, but I am not exactly sure how to create the code to read/write it.

    Here is an example the yaml I want:
    Code:
    worlds:
      world1name:
        x: 0
        z: 0
        radius: 100
      world2name:
        x: 0
        z: 0
        radius: 200
    (etc etc for as many worlds being used)
    globalconfig1: true
    globalconfig2: false
    
    I think the code I need to read it is something like this, but I don't know if it is the best way to go about this, or if it will even work at all. Thanks for any pointers
    Code:
    HashMap<String, HashMap> worlddb = new HashMap<String, HashMap>();       
            Map<String, ConfigurationNode> worlds = _config.getNodes("worlds");
            Set<String> keys = worlds.keySet();
            Iterator<String> a = keys.iterator();
            for(i=0; i<worlds.size(); i++){    
                String name = a.next();
                int x = worlds.get(name).getInt("x", 0);
                int z = worlds.get(name).getInt("z", 0);
                int r = worlds.get(name).getInt("radius", 0);
                HashMap<String, Integer> world = new HashMap<String, Integer>();
                world.put("x", x);
                world.put("z", z);
                world.put("radius", r);
                worlddb.put(name, world);
            }
     
  2. Offline

    fullwall

    Have you tried using an entry set instead of keyset?
    for (Map.Entry<String, ConfigurationNode> entry : worlds.entrySet()) {
    String name = entry.getKey();
    int x = worlds.get(name).getInt("x", 0);
    int z = worlds.get(name).getInt("z", 0);
    int r = worlds.get(name).getInt("radius", 0);
    HashMap<String, Integer> world = new HashMap<String, Integer>();
    world.put("x", x);
    world.put("z", z);
    world.put("radius", r);
    worlddb.put(name, world);

    }
     
  3. Offline

    croxis

    That worked, thank you
     
Thread Status:
Not open for further replies.

Share This Page