[SOLVED] Configs have me stumped.

Discussion in 'Plugin Development' started by Taco, Jun 19, 2012.

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

    Taco

    Alright, so here's my issue. I've got a config that's written like this:

    Code:
    warps:
      derp:
        x: 55
        y: 78
        z: -76
        world: world
      herp:
        x: 74
        y: 78
        z: -79
        world: world
    
    And I want to get a list containing all the subvalues of warps, though I can't seem to manage to do so. My current method of trying to do this is as follows:
    Code:
    List<String> warpList = Config.getStringList("warps");
    I've tried also tried using getList(), and just get() and they all return either empty or null with this config. Does anyone see what I'm missing here?
     
  2. Offline

    CorrieKay

    I have an idea
    Code:
    HashMap<String,ArrayList<String>> warps = new HashMap<String,ArrayList<String>>();
    FileConfiguration config = //your configuration file;
    for(String warpName : config.getConfigurationSection("warps").getKeys(false)){
      ArrayList<String> warpData = new ArrayList<String>();
      warpData.add(config.getString("warps."+warpName+".x"));
      warpData.add(config.getString("warps."+warpName+".y"));
      warpData.add(config.getString("warps."+warpName+".z"));
      warpData.add(config.getString("warps."+warpName+".world"));
      warps.put(warpName,warpData);
    }
    
    To get a warp from warps, do this
    Code:
    String warptoget;
    Location loc;
     
    ArrayList<String> warp = warps.get(warptoget);
    if(warp != null){
      World world = Bukkit.getWorld(warp.get(3));
      double x = Double.parseDouble(warp.get(0));
      double y = Double.parseDouble(warp.get(1));
      double z = Double.parseDouble(warp.get(2));
      loc = new Location(world,x,y,z);
    }
     
  3. Offline

    Taco

    I already had code very similar to all of that, with the exception of:

    Code:
    config.getConfigurationSection("warps").getKeys(false)
    which was precisely what I needed. So thank you for that!
     
    CorrieKay likes this.
Thread Status:
Not open for further replies.

Share This Page