For loop not triggering

Discussion in 'Plugin Development' started by martijnpold, Sep 17, 2015.

Thread Status:
Not open for further replies.
  1. I have this code that reads all the files from a folder and then executes a piece of code on every single room to clear the area defined in the code. For some reason this only works for the first room though :eek:

    Code:
    for (int o = 0; o < files.length; o++) {
                File room = new File(files[o].getPath());
                String filename = files[o].getName().replace(".yml", "");
                YamlConfiguration roomYaml = YamlConfiguration.loadConfiguration(room);
                if (!filename.contains("available")) {
                    int x1 = roomYaml.getInt("Pos.x1");
                    int y1 = roomYaml.getInt("Pos.y1");
                    int z1 = roomYaml.getInt("Pos.z1");
                    int x2 = roomYaml.getInt("Pos.x2");
                    int y2 = roomYaml.getInt("Pos.y2");
                    int z2 = roomYaml.getInt("Pos.z2");
    
                  
                   
                    for (int x = x1; x <= x2; x++) {
                          for (int y = y1; y <= y2; y++) {
                              for (int z = z1; z <= z2; z++) {
                              Block blk = getServer().getWorld(hotelWorldName).getBlockAt(x, y, z);
                              if (blk.getType()!=Material.AIR) {
                              blk.setType(Material.AIR);
                              getLogger().info("X" + x + " Z" + z);
                              }
                         }
                    }
               }
          }
    }
     
  2. Offline

    mine-care

    is that returning a number > 0?
    Also why exacly creating a clone of files[o] ? i dont see why it is needed.
     
  3. @mine-care Yes, it returns all the files in the folder and then loops through them and ignores a file named available.yml
     
  4. Offline

    mine-care

    @martijnpold
    mhm, i still dont get why you need a clone of the file but anyway, have you debuged?
     
  5. @mine-care It doesnt seem to trigger the for loop at all, as you can see i have a getlogger().info in there to shout when it replaces certain blocks but it doesnt call the for loop at all... It does execute the for loop on file itself because if i add a broadcast to the for loop for all the folder files it works just fine.
     
  6. As @mine-care said, did you check if files.length > 0 ? And show a little bit more code (what's above the for-loop)
     
    mine-care likes this.
Thread Status:
Not open for further replies.

Share This Page