Program: 34062
Project: 34062
Buggy source:
/** 
 * This method pastes a schematic and returns a location where a cow (or other entity) could be placed. Actually, the location should be that of a grass block.
 * @param world
 * @param loc
 * @param player
 * @return Location of highest grass block
 */
@SuppressWarnings("String_Node_Str") public void pasteSchematic(final Location loc,final Player player){
  if (this.file == null) {
    if (Settings.GAMETYPE == GameType.ACIDISLAND) {
      generateIslandBlocks(loc,player);
    }
 else {
      loc.getBlock().setType(Material.BEDROCK);
      ASkyBlock.getPlugin().getLogger().severe("String_Node_Str");
    }
    return;
  }
  World world=loc.getWorld();
  Map<BlockVector,Map<String,Tag>> tileEntitiesMap=this.getTileEntitiesMap();
  Location bedrock=null;
  Location chest=null;
  Location welcomeSign=null;
  Set<Vector> grassBlocks=new HashSet<Vector>();
  for (int x=0; x < width; ++x) {
    for (int y=0; y < height; ++y) {
      for (int z=0; z < length; ++z) {
        int index=y * width * length + z * width + x;
        if (blocks[index] == 7) {
          if (bedrock == null || bedrock.getY() < y) {
            bedrock=new Location(world,x,y,z);
          }
        }
 else         if (blocks[index] == 54) {
          if (chest == null || chest.getY() < y) {
            chest=new Location(world,x,y,z);
          }
        }
 else         if (blocks[index] == 63) {
          if (welcomeSign == null || welcomeSign.getY() < y) {
            welcomeSign=new Location(world,x,y,z);
          }
        }
 else         if (blocks[index] == 2) {
          grassBlocks.add(new Vector(x,y,z));
        }
      }
    }
  }
  if (bedrock == null) {
    Bukkit.getLogger().severe("String_Node_Str");
    return;
  }
  if (chest == null) {
    Bukkit.getLogger().severe("String_Node_Str");
    return;
  }
  if (grassBlocks.isEmpty()) {
    Bukkit.getLogger().severe("String_Node_Str");
    return;
  }
  Location blockLoc=new Location(world,loc.getX(),loc.getY(),loc.getZ());
  blockLoc.subtract(bedrock);
  for (int x=0; x < width; ++x) {
    for (int y=0; y < height; ++y) {
      for (int z=0; z < length; ++z) {
        int index=y * width * length + z * width + x;
        Block block=new Location(world,x,y,z).add(blockLoc).getBlock();
        try {
          if (blocks[index] != Material.TORCH.getId()) {
            block.setTypeIdAndData(blocks[index],data[index],this.usePhysics);
          }
        }
 catch (        Exception e) {
          if (blocks[index] == 179) {
            block.setTypeIdAndData(12,(byte)1,this.usePhysics);
          }
 else {
            Bukkit.getLogger().info("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str"+ z+ "String_Node_Str"+ blocks[index]+ "String_Node_Str"+ data[index]);
          }
        }
      }
    }
  }
  for (int x=0; x < width; ++x) {
    for (int y=0; y < height; ++y) {
      for (int z=0; z < length; ++z) {
        int index=y * width * length + z * width + x;
        Block block=new Location(world,x,y,z).add(blockLoc).getBlock();
        try {
          block.setTypeIdAndData(blocks[index],data[index],this.usePhysics);
        }
 catch (        Exception e) {
          if (blocks[index] == 179) {
            block.setTypeIdAndData(12,(byte)1,this.usePhysics);
          }
 else {
            Bukkit.getLogger().info("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str"+ z+ "String_Node_Str"+ blocks[index]+ "String_Node_Str"+ data[index]);
          }
        }
        if (tileEntitiesMap.containsKey(new BlockVector(x,y,z))) {
          String ver=Bukkit.getServer().getBukkitVersion();
          int major=Integer.valueOf(ver.substring(0,1));
          int minor=Integer.valueOf(ver.substring(ver.indexOf("String_Node_Str") + 1,ver.indexOf("String_Node_Str") + 2));
          if (major >= 1 && minor >= 8) {
            if (block.getType() == Material.STANDING_BANNER || block.getType() == Material.WALL_BANNER) {
              BannerBlock.set(block,tileEntitiesMap.get(new BlockVector(x,y,z)));
            }
          }
          if ((block.getType() == Material.SIGN_POST) || (block.getType() == Material.WALL_SIGN)) {
            Sign sign=(Sign)block.getState();
            Map<String,Tag> tileData=tileEntitiesMap.get(new BlockVector(x,y,z));
            List<String> text=new ArrayList<String>();
            text.add(((StringTag)tileData.get("String_Node_Str")).getValue());
            text.add(((StringTag)tileData.get("String_Node_Str")).getValue());
            text.add(((StringTag)tileData.get("String_Node_Str")).getValue());
            text.add(((StringTag)tileData.get("String_Node_Str")).getValue());
            JSONParser parser=new JSONParser();
            ContainerFactory containerFactory=new ContainerFactory(){
              public List creatArrayContainer(){
                return new LinkedList();
              }
              public Map createObjectContainer(){
                return new LinkedHashMap();
              }
            }
;
            for (int line=0; line < 4; line++) {
              if (!text.get(line).equals("String_Node_Str") && !text.get(line).isEmpty()) {
                String lineText="String_Node_Str";
                try {
                  Map json=(Map)parser.parse(text.get(line),containerFactory);
                  List list=(List)json.get("String_Node_Str");
                  Iterator iter=list.iterator();
                  while (iter.hasNext()) {
                    Object next=iter.next();
                    String format=JSONValue.toJSONString(next);
                    if (format.startsWith("String_Node_Str")) {
                      Map jsonFormat=(Map)parser.parse(format,containerFactory);
                      Iterator formatIter=jsonFormat.entrySet().iterator();
                      while (formatIter.hasNext()) {
                        Map.Entry entry=(Map.Entry)formatIter.next();
                        String key=entry.getKey().toString();
                        String value=entry.getValue().toString();
                        if (key.equalsIgnoreCase("String_Node_Str")) {
                          try {
                            lineText+=ChatColor.valueOf(value.toUpperCase());
                          }
 catch (                          Exception noColor) {
                            Bukkit.getLogger().warning("String_Node_Str" + value + "String_Node_Str");
                          }
                        }
 else                         if (key.equalsIgnoreCase("String_Node_Str")) {
                          lineText+=value;
                        }
 else {
                          if (key.equalsIgnoreCase("String_Node_Str") && value.equalsIgnoreCase("String_Node_Str")) {
                            lineText+=ChatColor.MAGIC;
                          }
 else                           if (key.equalsIgnoreCase("String_Node_Str") && value.equalsIgnoreCase("String_Node_Str")) {
                            lineText+=ChatColor.UNDERLINE;
                          }
 else {
                            try {
                              lineText+=ChatColor.valueOf(key.toUpperCase());
                            }
 catch (                            Exception noFormat) {
                              Bukkit.getLogger().warning("String_Node_Str" + value + "String_Node_Str");
                            }
                          }
                        }
                      }
                    }
 else {
                      if (format.length() > 1) {
                        lineText+=ChatColor.RESET + format.substring(format.indexOf('"') + 1,format.lastIndexOf('"'));
                      }
                    }
                  }
                }
 catch (                ParseException e) {
                  e.printStackTrace();
                }
                sign.setLine(line,lineText);
              }
            }
            sign.update();
          }
          if (block.getType().equals(Material.CHEST)) {
            Chest chestBlock=(Chest)block.getState();
            Map<String,Tag> tileData=tileEntitiesMap.get(new BlockVector(x,y,z));
            try {
              ListTag chestItems=(ListTag)tileData.get("String_Node_Str");
              if (chestItems != null) {
                for (                Tag item : chestItems.getValue()) {
                  if (item instanceof CompoundTag) {
                    try {
                      short itemType=(Short)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                      short itemDamage=(Short)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                      byte itemAmount=(Byte)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                      byte itemSlot=(Byte)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                      ItemStack chestItem=new ItemStack(itemType,itemAmount,itemDamage);
                      chestBlock.getInventory().setItem(itemSlot,chestItem);
                    }
 catch (                    ClassCastException ex) {
                      String itemType=(String)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                      try {
                        if (itemType.startsWith("String_Node_Str")) {
                          String material=itemType.substring(10).toUpperCase();
                          if (material.equalsIgnoreCase("String_Node_Str")) {
                            material="String_Node_Str";
                          }
                          if (material.equalsIgnoreCase("String_Node_Str")) {
                            material="String_Node_Str";
                          }
                          if (material.equalsIgnoreCase("String_Node_Str")) {
                            material="String_Node_Str";
                          }
                          Material itemMaterial=Material.valueOf(material);
                          short itemDamage=(Short)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                          byte itemAmount=(Byte)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                          byte itemSlot=(Byte)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                          ItemStack chestItem=new ItemStack(itemMaterial,itemAmount,itemDamage);
                          chestBlock.getInventory().setItem(itemSlot,chestItem);
                        }
                      }
 catch (                      Exception exx) {
                        Bukkit.getLogger().severe("String_Node_Str" + itemType.substring(10).toUpperCase() + "String_Node_Str");
                      }
                    }
                  }
                }
              }
            }
 catch (            Exception e) {
              Bukkit.getLogger().severe("String_Node_Str");
            }
          }
        }
      }
    }
  }
  List<Vector> sorted=new ArrayList<Vector>();
  for (  Vector v : grassBlocks) {
    v.subtract(bedrock.toVector());
    v.add(loc.toVector());
    v.add(new Vector(0.5D,1.1D,0.5D));
    boolean inserted=false;
    for (int i=0; i < sorted.size(); i++) {
      if (v.getBlockY() > sorted.get(i).getBlockY()) {
        sorted.add(i,v);
        inserted=true;
        break;
      }
    }
    if (!inserted) {
      sorted.add(v);
    }
  }
  final Location grass=sorted.get(0).toLocation(world);
  Block blockToChange=null;
  if (welcomeSign != null) {
    welcomeSign.subtract(bedrock);
    welcomeSign.add(loc);
    blockToChange=welcomeSign.getBlock();
    blockToChange.setType(Material.SIGN_POST);
    Sign sign=(Sign)blockToChange.getState();
    sign.setLine(0,ASkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine1.replace("String_Node_Str",player.getName()));
    sign.setLine(1,ASkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine2.replace("String_Node_Str",player.getName()));
    sign.setLine(2,ASkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine3.replace("String_Node_Str",player.getName()));
    sign.setLine(3,ASkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine4.replace("String_Node_Str",player.getName()));
    ((org.bukkit.material.Sign)sign.getData()).setFacingDirection(BlockFace.NORTH);
    sign.update();
  }
  chest.subtract(bedrock);
  chest.add(loc);
  blockToChange=chest.getBlock();
  if (useDefaultChest && Settings.chestItems[0] != null) {
    if (blockToChange.getType() == Material.CHEST) {
      final Chest islandChest=(Chest)blockToChange.getState();
      final Inventory inventory=islandChest.getInventory();
      inventory.clear();
      inventory.setContents(Settings.chestItems);
    }
  }
  if (Settings.islandCompanion != null) {
    Bukkit.getServer().getScheduler().runTaskLater(ASkyBlock.getPlugin(),new Runnable(){
      @Override public void run(){
        spawnCompanion(player,grass);
      }
    }
,40L);
  }
}

Fixed version (ground truth):
/** 
 * This method pastes a schematic and returns a location where a cow (or other entity) could be placed. Actually, the location should be that of a grass block.
 * @param world
 * @param loc
 * @param player
 * @return Location of highest grass block
 */
@SuppressWarnings("String_Node_Str") public void pasteSchematic(final Location loc,final Player player){
  if (this.file == null) {
    if (Settings.GAMETYPE == GameType.ACIDISLAND) {
      generateIslandBlocks(loc,player);
    }
 else {
      loc.getBlock().setType(Material.BEDROCK);
      ASkyBlock.getPlugin().getLogger().severe("String_Node_Str");
    }
    return;
  }
  World world=loc.getWorld();
  Map<BlockVector,Map<String,Tag>> tileEntitiesMap=this.getTileEntitiesMap();
  Location bedrock=null;
  Location chest=null;
  Location welcomeSign=null;
  Set<Vector> grassBlocks=new HashSet<Vector>();
  for (int x=0; x < width; ++x) {
    for (int y=0; y < height; ++y) {
      for (int z=0; z < length; ++z) {
        int index=y * width * length + z * width + x;
        if (blocks[index] == 7) {
          if (bedrock == null || bedrock.getY() < y) {
            bedrock=new Location(world,x,y,z);
          }
        }
 else         if (blocks[index] == 54) {
          if (chest == null || chest.getY() < y) {
            chest=new Location(world,x,y,z);
          }
        }
 else         if (blocks[index] == 63) {
          if (welcomeSign == null || welcomeSign.getY() < y) {
            welcomeSign=new Location(world,x,y,z);
          }
        }
 else         if (blocks[index] == 2) {
          grassBlocks.add(new Vector(x,y,z));
        }
      }
    }
  }
  if (bedrock == null) {
    Bukkit.getLogger().severe("String_Node_Str");
    return;
  }
  if (chest == null) {
    Bukkit.getLogger().severe("String_Node_Str");
    return;
  }
  if (grassBlocks.isEmpty()) {
    Bukkit.getLogger().severe("String_Node_Str");
    return;
  }
  Location blockLoc=new Location(world,loc.getX(),loc.getY(),loc.getZ());
  blockLoc.subtract(bedrock);
  for (int x=0; x < width; ++x) {
    for (int y=0; y < height; ++y) {
      for (int z=0; z < length; ++z) {
        int index=y * width * length + z * width + x;
        Block block=new Location(world,x,y,z).add(blockLoc).getBlock();
        try {
          if (blocks[index] != Material.TORCH.getId()) {
            block.setTypeIdAndData(blocks[index],data[index],this.usePhysics);
          }
        }
 catch (        Exception e) {
          if (blocks[index] == 179) {
            block.setTypeIdAndData(12,(byte)1,this.usePhysics);
          }
 else {
            Bukkit.getLogger().info("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str"+ z+ "String_Node_Str"+ blocks[index]+ "String_Node_Str"+ data[index]);
          }
        }
      }
    }
  }
  for (int x=0; x < width; ++x) {
    for (int y=0; y < height; ++y) {
      for (int z=0; z < length; ++z) {
        int index=y * width * length + z * width + x;
        Block block=new Location(world,x,y,z).add(blockLoc).getBlock();
        try {
          block.setTypeIdAndData(blocks[index],data[index],this.usePhysics);
        }
 catch (        Exception e) {
          if (blocks[index] == 179) {
            block.setTypeIdAndData(12,(byte)1,this.usePhysics);
          }
 else {
            Bukkit.getLogger().info("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str"+ z+ "String_Node_Str"+ blocks[index]+ "String_Node_Str"+ data[index]);
          }
        }
        if (tileEntitiesMap.containsKey(new BlockVector(x,y,z))) {
          String ver=Bukkit.getServer().getBukkitVersion();
          int major=Integer.valueOf(ver.substring(0,1));
          int minor=Integer.valueOf(ver.substring(ver.indexOf("String_Node_Str") + 1,ver.indexOf("String_Node_Str") + 2));
          if (major >= 1 && minor >= 8) {
            if (block.getType() == Material.STANDING_BANNER || block.getType() == Material.WALL_BANNER) {
              BannerBlock.set(block,tileEntitiesMap.get(new BlockVector(x,y,z)));
            }
          }
          if ((block.getType() == Material.SIGN_POST) || (block.getType() == Material.WALL_SIGN)) {
            Sign sign=(Sign)block.getState();
            Map<String,Tag> tileData=tileEntitiesMap.get(new BlockVector(x,y,z));
            List<String> text=new ArrayList<String>();
            text.add(((StringTag)tileData.get("String_Node_Str")).getValue());
            text.add(((StringTag)tileData.get("String_Node_Str")).getValue());
            text.add(((StringTag)tileData.get("String_Node_Str")).getValue());
            text.add(((StringTag)tileData.get("String_Node_Str")).getValue());
            JSONParser parser=new JSONParser();
            ContainerFactory containerFactory=new ContainerFactory(){
              public List creatArrayContainer(){
                return new LinkedList();
              }
              public Map createObjectContainer(){
                return new LinkedHashMap();
              }
            }
;
            for (int line=0; line < 4; line++) {
              if (!text.get(line).equals("String_Node_Str") && !text.get(line).isEmpty()) {
                String lineText="String_Node_Str";
                if (text.get(line).startsWith("String_Node_Str")) {
                  try {
                    Map json=(Map)parser.parse(text.get(line),containerFactory);
                    List list=(List)json.get("String_Node_Str");
                    Iterator iter=list.iterator();
                    while (iter.hasNext()) {
                      Object next=iter.next();
                      String format=JSONValue.toJSONString(next);
                      if (format.startsWith("String_Node_Str")) {
                        Map jsonFormat=(Map)parser.parse(format,containerFactory);
                        Iterator formatIter=jsonFormat.entrySet().iterator();
                        while (formatIter.hasNext()) {
                          Map.Entry entry=(Map.Entry)formatIter.next();
                          String key=entry.getKey().toString();
                          String value=entry.getValue().toString();
                          if (key.equalsIgnoreCase("String_Node_Str")) {
                            try {
                              lineText+=ChatColor.valueOf(value.toUpperCase());
                            }
 catch (                            Exception noColor) {
                              Bukkit.getLogger().warning("String_Node_Str" + value + "String_Node_Str");
                            }
                          }
 else                           if (key.equalsIgnoreCase("String_Node_Str")) {
                            lineText+=value;
                          }
 else {
                            if (key.equalsIgnoreCase("String_Node_Str") && value.equalsIgnoreCase("String_Node_Str")) {
                              lineText+=ChatColor.MAGIC;
                            }
 else                             if (key.equalsIgnoreCase("String_Node_Str") && value.equalsIgnoreCase("String_Node_Str")) {
                              lineText+=ChatColor.UNDERLINE;
                            }
 else {
                              try {
                                lineText+=ChatColor.valueOf(key.toUpperCase());
                              }
 catch (                              Exception noFormat) {
                                Bukkit.getLogger().warning("String_Node_Str" + value + "String_Node_Str");
                              }
                            }
                          }
                        }
                      }
 else {
                        if (format.length() > 1) {
                          lineText+=ChatColor.RESET + format.substring(format.indexOf('"') + 1,format.lastIndexOf('"'));
                        }
                      }
                    }
                  }
 catch (                  ParseException e) {
                    e.printStackTrace();
                  }
                }
 else {
                  if (text.get(line).length() > 1) {
                    lineText=text.get(line).substring(text.get(line).indexOf('"') + 1,text.get(line).lastIndexOf('"'));
                  }
 else {
                    lineText=text.get(line);
                  }
                }
                sign.setLine(line,lineText);
              }
            }
            sign.update();
          }
          if (block.getType().equals(Material.CHEST)) {
            Chest chestBlock=(Chest)block.getState();
            Map<String,Tag> tileData=tileEntitiesMap.get(new BlockVector(x,y,z));
            try {
              ListTag chestItems=(ListTag)tileData.get("String_Node_Str");
              if (chestItems != null) {
                for (                Tag item : chestItems.getValue()) {
                  if (item instanceof CompoundTag) {
                    try {
                      short itemType=(Short)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                      short itemDamage=(Short)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                      byte itemAmount=(Byte)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                      byte itemSlot=(Byte)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                      ItemStack chestItem=new ItemStack(itemType,itemAmount,itemDamage);
                      chestBlock.getInventory().setItem(itemSlot,chestItem);
                    }
 catch (                    ClassCastException ex) {
                      String itemType=(String)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                      try {
                        if (itemType.startsWith("String_Node_Str")) {
                          String material=itemType.substring(10).toUpperCase();
                          if (material.equalsIgnoreCase("String_Node_Str")) {
                            material="String_Node_Str";
                          }
                          if (material.equalsIgnoreCase("String_Node_Str")) {
                            material="String_Node_Str";
                          }
                          if (material.equalsIgnoreCase("String_Node_Str")) {
                            material="String_Node_Str";
                          }
                          Material itemMaterial=Material.valueOf(material);
                          short itemDamage=(Short)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                          byte itemAmount=(Byte)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                          byte itemSlot=(Byte)((CompoundTag)item).getValue().get("String_Node_Str").getValue();
                          ItemStack chestItem=new ItemStack(itemMaterial,itemAmount,itemDamage);
                          chestBlock.getInventory().setItem(itemSlot,chestItem);
                        }
                      }
 catch (                      Exception exx) {
                        Bukkit.getLogger().severe("String_Node_Str" + itemType.substring(10).toUpperCase() + "String_Node_Str");
                      }
                    }
                  }
                }
              }
            }
 catch (            Exception e) {
              Bukkit.getLogger().severe("String_Node_Str");
            }
          }
        }
      }
    }
  }
  List<Vector> sorted=new ArrayList<Vector>();
  for (  Vector v : grassBlocks) {
    v.subtract(bedrock.toVector());
    v.add(loc.toVector());
    v.add(new Vector(0.5D,1.1D,0.5D));
    boolean inserted=false;
    for (int i=0; i < sorted.size(); i++) {
      if (v.getBlockY() > sorted.get(i).getBlockY()) {
        sorted.add(i,v);
        inserted=true;
        break;
      }
    }
    if (!inserted) {
      sorted.add(v);
    }
  }
  final Location grass=sorted.get(0).toLocation(world);
  Block blockToChange=null;
  if (welcomeSign != null) {
    welcomeSign.subtract(bedrock);
    welcomeSign.add(loc);
    blockToChange=welcomeSign.getBlock();
    blockToChange.setType(Material.SIGN_POST);
    Sign sign=(Sign)blockToChange.getState();
    sign.setLine(0,ASkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine1.replace("String_Node_Str",player.getName()));
    sign.setLine(1,ASkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine2.replace("String_Node_Str",player.getName()));
    sign.setLine(2,ASkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine3.replace("String_Node_Str",player.getName()));
    sign.setLine(3,ASkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine4.replace("String_Node_Str",player.getName()));
    ((org.bukkit.material.Sign)sign.getData()).setFacingDirection(BlockFace.NORTH);
    sign.update();
  }
  chest.subtract(bedrock);
  chest.add(loc);
  blockToChange=chest.getBlock();
  if (useDefaultChest && Settings.chestItems[0] != null) {
    if (blockToChange.getType() == Material.CHEST) {
      final Chest islandChest=(Chest)blockToChange.getState();
      final Inventory inventory=islandChest.getInventory();
      inventory.clear();
      inventory.setContents(Settings.chestItems);
    }
  }
  if (Settings.islandCompanion != null) {
    Bukkit.getServer().getScheduler().runTaskLater(ASkyBlock.getPlugin(),new Runnable(){
      @Override public void run(){
        spawnCompanion(player,grass);
      }
    }
,40L);
  }
}