ConfigurationSection help

Discussion in 'Plugin Development' started by ZeusAllMighty11, Apr 6, 2013.

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

    ZeusAllMighty11

    Code:
    warps:
      mywarp: world,0,0,0,0,0
      test: world,0,0,0,0,0
    
    Example of my warps file above. I tried using a configuration section to iterate over the keys and values to load them into a map. it failed. here's what I did:

    Code:
    public void loadWarps()
        {
            reloadWarps();
            FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsFile);
            Map<String, Object> values = warps.getConfigurationSection("Warps").getValues(false);
            for (String s : values.keySet())
            {
                for (Object o : values.values())
                {
                    String[] locS = ((String) o).split(",");
                    // !format
                    Location loc = new Location(Bukkit.getServer().getWorld(locS[0]), 
                            Double.parseDouble(locS[1]), 
                            Double.parseDouble(locS[2]),
                            Double.parseDouble(locS[3]));
                    //format
                    loc.setPitch(Float.parseFloat(locS[4]));
                    loc.setYaw(Float.parseFloat(locS[5]));
                    new WarpCommand(plugin).availableWarps.put(s, loc);
                }
            }
        }
    
    Keep in mind nothing here is null, and it's pretty obvious what it does. What am I doing wrong? :(
     
  2. 1) "It failed" does not tell us how it failed. Compile error? NPE? Logic bug? Spawns mischievous elves out of the DVD drive?

    2) and I'm taking great assumptions here on what the failure actually is, the loops are wrong as is the hashmap saving.

    Code:
    Set<String> keys = warps.getConfigurationSection("Warps").getKeys(false);//Get All id's for items under Warps
    for(String keys : key){
      String warpString =  warps.getString("Warps." + key);// Get the string with the location data
      ...Process string to location
      ... place in hashmap, see point below on how to do
    }
     
    
    Also:
    Code:
    new WarpCommand(plugin).availableWarps.put(s, loc);
    
    That will just not work probably.

    You are creating a NEW warp command object, without ANY other warp data, and then losing the reference to it.

    Make availableWarps a static field in WarpCommand, then change the line to:

    Code:
    WarpCommand.availableWarps.put(key,loc)
    
     
    1SmallVille1 likes this.
Thread Status:
Not open for further replies.

Share This Page