Program: 33839
Project: 33839
Buggy source:
/** 
 * Calculates the level of an island
 * @param plugin
 * @param targetPlayer - UUID of island owner or team member
 * @param sender - requester of the level calculation, if anyone
 * @param report - provide a report to the asker
 */
public LevelCalcByChunk(final ASkyBlock plugin,final UUID targetPlayer,final CommandSender sender,final boolean report){
  final Island island=plugin.getGrid().getIsland(targetPlayer);
  if (island != null) {
    Player player=plugin.getServer().getPlayer(targetPlayer);
    int multiplier=1;
    if (player != null) {
      for (      PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
        if (perms.getPermission().startsWith(Settings.PERMPREFIX + "String_Node_Str")) {
          String spl[]=perms.getPermission().split(Settings.PERMPREFIX + "String_Node_Str");
          if (spl.length > 1) {
            if (!NumberUtils.isDigits(spl[1])) {
              plugin.getLogger().severe("String_Node_Str" + player.getName() + "String_Node_Str"+ perms.getPermission()+ "String_Node_Str");
            }
 else {
              multiplier=Math.max(multiplier,Integer.valueOf(spl[1]));
            }
          }
        }
        if (multiplier < 1) {
          multiplier=1;
        }
      }
    }
    final int levelMultiplier=multiplier;
    final int levelHandicap=island.getLevelHandicap();
    int deaths=plugin.getPlayers().getDeaths(targetPlayer);
    if (plugin.getPlayers().inTeam(targetPlayer)) {
      deaths=plugin.getPlayers().getDeaths(plugin.getPlayers().getTeamLeader(targetPlayer));
      if (Settings.sumTeamDeaths) {
        deaths=0;
        for (        UUID member : plugin.getPlayers().getMembers(targetPlayer)) {
          deaths+=plugin.getPlayers().getDeaths(member);
        }
      }
    }
    final int deathHandicap=deaths;
    final World world=plugin.getPlayers().getIslandLocation(targetPlayer).getWorld();
    Set<ChunkSnapshot> chunkSnapshot=new HashSet<ChunkSnapshot>();
    for (int x=island.getMinProtectedX(); x < (island.getMinProtectedX() + island.getProtectionSize() + 16); x+=16) {
      for (int z=island.getMinProtectedZ(); z < (island.getMinProtectedZ() + island.getProtectionSize() + 16); z+=16) {
        if (!world.isChunkLoaded((int)((double)x / 16),(int)((double)z / 16))) {
          if (world.loadChunk((int)((double)x / 16),(int)((double)z / 16),false)) {
            Chunk chunk=world.getChunkAt((int)((double)x / 16),(int)((double)z / 16));
            chunkSnapshot.add(chunk.getChunkSnapshot());
          }
        }
 else {
          chunkSnapshot.add(world.getBlockAt(x,0,z).getChunk().getChunkSnapshot());
        }
      }
    }
    final Set<ChunkSnapshot> finalChunk=chunkSnapshot;
    final int worldHeight=world.getMaxHeight();
    plugin.getServer().getScheduler().runTaskAsynchronously(plugin,new Runnable(){
      @SuppressWarnings("String_Node_Str") @Override public void run(){
        File log=null;
        PrintWriter out=null;
        List<MaterialData> mdLog=null;
        List<MaterialData> uwLog=null;
        List<MaterialData> noCountLog=null;
        List<MaterialData> overflowLog=null;
        if (Settings.levelLogging) {
          log=new File(plugin.getDataFolder(),"String_Node_Str");
          try {
            if (log.exists()) {
              out=new PrintWriter(new FileWriter(log,true));
            }
 else {
              out=new PrintWriter(log);
            }
          }
 catch (          FileNotFoundException e) {
            System.out.println("String_Node_Str");
            e.printStackTrace();
          }
catch (          IOException e) {
            System.out.println("String_Node_Str");
            e.printStackTrace();
          }
        }
        if (Settings.levelLogging || report) {
          mdLog=new ArrayList<MaterialData>();
          uwLog=new ArrayList<MaterialData>();
          noCountLog=new ArrayList<MaterialData>();
          overflowLog=new ArrayList<MaterialData>();
        }
        HashMap<MaterialData,Integer> limitCount=new HashMap<MaterialData,Integer>(Settings.blockLimits);
        long blockCount=0;
        long underWaterBlockCount=0;
        for (        ChunkSnapshot chunk : finalChunk) {
          for (int x=0; x < 16; x++) {
            if (chunk.getX() * 16 + x < island.getMinProtectedX() || chunk.getX() * 16 + x >= island.getMinProtectedX() + island.getProtectionSize()) {
              continue;
            }
            for (int z=0; z < 16; z++) {
              if (chunk.getZ() * 16 + z < island.getMinProtectedZ() || chunk.getZ() * 16 + z >= island.getMinProtectedZ() + island.getProtectionSize()) {
                continue;
              }
              for (int y=0; y < worldHeight; y++) {
                int type=chunk.getBlockTypeId(x,y,z);
                int data=chunk.getBlockData(x,y,z);
                MaterialData md=new MaterialData(type,(byte)data);
                MaterialData generic=new MaterialData(type);
                if (type != 0) {
                  if (limitCount.containsKey(md) && Settings.blockValues.containsKey(md)) {
                    int count=limitCount.get(md);
                    if (count > 0) {
                      limitCount.put(md,--count);
                      if (Settings.seaHeight > 0 && y <= Settings.seaHeight) {
                        underWaterBlockCount+=Settings.blockValues.get(md);
                        if (Settings.levelLogging || report) {
                          uwLog.add(md);
                        }
                      }
 else {
                        blockCount+=Settings.blockValues.get(md);
                        if (Settings.levelLogging || report) {
                          mdLog.add(md);
                        }
                      }
                    }
 else                     if (Settings.levelLogging || report) {
                      overflowLog.add(md);
                    }
                  }
 else                   if (limitCount.containsKey(generic) && Settings.blockValues.containsKey(generic)) {
                    int count=limitCount.get(generic);
                    if (count > 0) {
                      limitCount.put(generic,--count);
                      if (Settings.seaHeight > 0 && y <= Settings.seaHeight) {
                        underWaterBlockCount+=Settings.blockValues.get(generic);
                        if (Settings.levelLogging || report) {
                          uwLog.add(md);
                        }
                      }
 else {
                        blockCount+=Settings.blockValues.get(generic);
                        if (Settings.levelLogging || report) {
                          mdLog.add(md);
                        }
                      }
                    }
 else                     if (Settings.levelLogging || report) {
                      overflowLog.add(md);
                    }
                  }
 else                   if (Settings.blockValues.containsKey(md)) {
                    if (Settings.seaHeight > 0 && y <= Settings.seaHeight) {
                      underWaterBlockCount+=Settings.blockValues.get(md);
                      if (Settings.levelLogging || report) {
                        uwLog.add(md);
                      }
                    }
 else {
                      blockCount+=Settings.blockValues.get(md);
                      if (Settings.levelLogging || report) {
                        mdLog.add(md);
                      }
                    }
                  }
 else                   if (Settings.blockValues.containsKey(generic)) {
                    if (Settings.seaHeight > 0 && y <= Settings.seaHeight) {
                      underWaterBlockCount+=Settings.blockValues.get(generic);
                      if (Settings.levelLogging || report) {
                        uwLog.add(md);
                      }
                    }
 else {
                      blockCount+=Settings.blockValues.get(generic);
                      if (Settings.levelLogging || report) {
                        mdLog.add(md);
                      }
                    }
                  }
 else                   if (Settings.levelLogging || report) {
                    noCountLog.add(md);
                  }
                }
              }
            }
          }
        }
        blockCount+=(long)((double)underWaterBlockCount * Settings.underWaterMultiplier);
        final long score=(((blockCount * levelMultiplier) - (deathHandicap * Settings.deathpenalty)) / Settings.levelCost) - levelHandicap;
        if (Settings.levelLogging || report) {
          Multiset<MaterialData> uwCount=HashMultiset.create(uwLog);
          Multiset<MaterialData> mdCount=HashMultiset.create(mdLog);
          Multiset<MaterialData> ncCount=HashMultiset.create(noCountLog);
          Multiset<MaterialData> ofCount=HashMultiset.create(overflowLog);
          reportLines.add("String_Node_Str" + island.getCenter());
          if (sender instanceof Player) {
            reportLines.add("String_Node_Str" + sender.getName() + "String_Node_Str"+ ((Player)sender).getUniqueId().toString()+ "String_Node_Str");
          }
 else {
            reportLines.add("String_Node_Str");
          }
          reportLines.add("String_Node_Str" + targetPlayer.toString());
          reportLines.add("String_Node_Str" + String.format("String_Node_Str",blockCount));
          reportLines.add("String_Node_Str" + Settings.levelCost);
          reportLines.add("String_Node_Str" + levelMultiplier + "String_Node_Str");
          reportLines.add("String_Node_Str" + levelHandicap + "String_Node_Str");
          reportLines.add("String_Node_Str" + (deathHandicap * Settings.deathpenalty) + "String_Node_Str"+ deathHandicap+ "String_Node_Str");
          reportLines.add("String_Node_Str" + score);
          reportLines.add("String_Node_Str");
          int total=0;
          if (!uwCount.isEmpty()) {
            reportLines.add("String_Node_Str" + Settings.underWaterMultiplier + "String_Node_Str");
            reportLines.add("String_Node_Str" + String.format("String_Node_Str",uwCount.size()));
            Iterable<Multiset.Entry<MaterialData>> entriesSortedByCount=Multisets.copyHighestCountFirst(uwCount).entrySet();
            Iterator<Entry<MaterialData>> it=entriesSortedByCount.iterator();
            while (it.hasNext()) {
              Entry<MaterialData> type=it.next();
              int value=0;
              if (Settings.blockValues.containsKey(type)) {
                value=Settings.blockValues.get(type);
              }
 else               if (Settings.blockValues.containsKey(new MaterialData(type.getElement().getItemType()))) {
                value=Settings.blockValues.get(new MaterialData(type.getElement().getItemType()));
              }
              if (value > 0) {
                reportLines.add(type.getElement().toString() + "String_Node_Str" + String.format("String_Node_Str",type.getCount())+ "String_Node_Str"+ value+ "String_Node_Str"+ (value * type.getCount()));
                total+=(value * type.getCount());
              }
            }
            reportLines.add("String_Node_Str" + total);
            reportLines.add("String_Node_Str");
          }
          reportLines.add("String_Node_Str");
          reportLines.add("String_Node_Str" + String.format("String_Node_Str",mdCount.size()));
          Iterable<Multiset.Entry<MaterialData>> entriesSortedByCount=mdCount.entrySet();
          Iterator<Entry<MaterialData>> it=entriesSortedByCount.iterator();
          while (it.hasNext()) {
            Entry<MaterialData> type=it.next();
            int value=0;
            if (Settings.blockValues.containsKey(type)) {
              value=Settings.blockValues.get(type);
            }
 else             if (Settings.blockValues.containsKey(new MaterialData(type.getElement().getItemType()))) {
              value=Settings.blockValues.get(new MaterialData(type.getElement().getItemType()));
            }
            if (value > 0) {
              reportLines.add(type.getElement().toString() + "String_Node_Str" + String.format("String_Node_Str",type.getCount())+ "String_Node_Str"+ value+ "String_Node_Str"+ (value * type.getCount()));
              total+=(value * type.getCount());
            }
          }
          reportLines.add("String_Node_Str" + total);
          reportLines.add("String_Node_Str");
          reportLines.add("String_Node_Str" + String.format("String_Node_Str",ofCount.size()));
          entriesSortedByCount=ofCount.entrySet();
          it=entriesSortedByCount.iterator();
          while (it.hasNext()) {
            Entry<MaterialData> type=it.next();
            Integer limit=Settings.blockLimits.get(type.getElement());
            String explain="String_Node_Str";
            if (limit == null) {
              MaterialData generic=new MaterialData(type.getElement().getItemType());
              limit=Settings.blockLimits.get(generic);
              explain="String_Node_Str";
            }
            reportLines.add(type.getElement().toString() + "String_Node_Str" + String.format("String_Node_Str",type.getCount())+ "String_Node_Str"+ limit+ explain);
          }
          reportLines.add("String_Node_Str");
          reportLines.add("String_Node_Str");
          reportLines.add("String_Node_Str" + String.format("String_Node_Str",ncCount.size()));
          entriesSortedByCount=ncCount.entrySet();
          it=entriesSortedByCount.iterator();
          while (it.hasNext()) {
            Entry<MaterialData> type=it.next();
            reportLines.add(type.getElement().toString() + "String_Node_Str" + String.format("String_Node_Str",type.getCount())+ "String_Node_Str");
          }
          reportLines.add("String_Node_Str");
        }
        if (out != null) {
          for (          String line : reportLines) {
            out.println(line);
          }
          System.out.println("String_Node_Str");
          out.close();
        }
        long calculatePointsToNextLevel=(Settings.levelCost * (score + 1 + levelHandicap)) - ((blockCount * levelMultiplier) - (deathHandicap * Settings.deathpenalty));
        if (calculatePointsToNextLevel == 0)         calculatePointsToNextLevel=(Settings.levelCost * (score + 2 + levelHandicap)) - ((blockCount * levelMultiplier) - (deathHandicap * Settings.deathpenalty));
        final long pointsToNextLevel=calculatePointsToNextLevel;
        plugin.getServer().getScheduler().runTask(plugin,new Runnable(){
          @Override public void run(){
            Island island=plugin.getGrid().getIsland(targetPlayer);
            final IslandPreLevelEvent event=new IslandPreLevelEvent(targetPlayer,island,score);
            event.setLongPointsToNextLevel(pointsToNextLevel);
            plugin.getServer().getPluginManager().callEvent(event);
            long oldLevel=plugin.getPlayers().getIslandLevel(targetPlayer);
            if (!event.isCancelled()) {
              if (oldLevel != event.getLevel()) {
                plugin.getPlayers().setIslandLevel(targetPlayer,event.getLevel());
                plugin.getPlayers().save(targetPlayer);
              }
              if (plugin.getPlayers().inTeam(targetPlayer)) {
                for (                UUID member : plugin.getPlayers().getMembers(targetPlayer)) {
                  if (plugin.getPlayers().getIslandLevel(member) != event.getLevel()) {
                    plugin.getPlayers().setIslandLevel(member,event.getLevel());
                    plugin.getPlayers().save(member);
                  }
                }
              }
              if (plugin.getPlayers().inTeam(targetPlayer)) {
                UUID leader=plugin.getPlayers().getTeamLeader(targetPlayer);
                if (leader != null) {
                  TopTen.topTenAddEntry(leader,event.getLongLevel());
                }
              }
 else {
                TopTen.topTenAddEntry(targetPlayer,event.getLongLevel());
              }
            }
            final IslandPostLevelEvent event3=new IslandPostLevelEvent(targetPlayer,island,event.getLongLevel(),event.getLongPointsToNextLevel());
            plugin.getServer().getPluginManager().callEvent(event3);
            if (!event3.isCancelled()) {
              if (sender != null) {
                if (!(sender instanceof Player)) {
                  if (!report) {
                    Util.sendMessage(sender,ChatColor.GREEN + plugin.myLocale().islandislandLevelis + "String_Node_Str"+ ChatColor.WHITE+ plugin.getPlayers().getIslandLevel(targetPlayer));
                  }
 else {
                    for (                    String line : reportLines) {
                      Util.sendMessage(sender,line);
                    }
                    Util.sendMessage(sender,ChatColor.GREEN + plugin.myLocale().islandislandLevelis + "String_Node_Str"+ ChatColor.WHITE+ plugin.getPlayers().getIslandLevel(targetPlayer));
                    if (event.getLongPointsToNextLevel() >= 0) {
                      String toNextLevel=ChatColor.GREEN + plugin.myLocale().islandrequiredPointsToNextLevel.replace("String_Node_Str",String.valueOf(event.getLongPointsToNextLevel()));
                      toNextLevel=toNextLevel.replace("String_Node_Str",String.valueOf(plugin.getPlayers().getIslandLevel(targetPlayer) + 1));
                      Util.sendMessage(sender,toNextLevel);
                    }
                  }
                }
 else {
                  if (!report) {
                    if (plugin.getPlayers().getIslandLevel(targetPlayer) != oldLevel) {
                      plugin.getMessages().tellOfflineTeam(targetPlayer,ChatColor.GREEN + plugin.myLocale(targetPlayer).islandislandLevelis + "String_Node_Str"+ ChatColor.WHITE+ plugin.getPlayers().getIslandLevel(targetPlayer));
                    }
                    if (sender instanceof Player && ((Player)sender).isOnline()) {
                      String message=ChatColor.GREEN + plugin.myLocale(((Player)sender).getUniqueId()).islandislandLevelis + "String_Node_Str"+ ChatColor.WHITE+ plugin.getPlayers().getIslandLevel(targetPlayer);
                      if (Settings.deathpenalty != 0) {
                        message+="String_Node_Str" + plugin.myLocale(((Player)sender).getUniqueId()).levelDeaths.replace("String_Node_Str",String.valueOf(deathHandicap));
                      }
                      Util.sendMessage(sender,message);
                      if (event.getLongPointsToNextLevel() >= 0) {
                        String toNextLevel=ChatColor.GREEN + plugin.myLocale(((Player)sender).getUniqueId()).islandrequiredPointsToNextLevel.replace("String_Node_Str",String.valueOf(event.getLongPointsToNextLevel()));
                        toNextLevel=toNextLevel.replace("String_Node_Str",String.valueOf(plugin.getPlayers().getIslandLevel(targetPlayer) + 1));
                        Util.sendMessage(sender,toNextLevel);
                      }
                    }
                  }
 else {
                    if (((Player)sender).isOnline()) {
                      for (                      String line : reportLines) {
                        Util.sendMessage(sender,line);
                      }
                    }
                    Util.sendMessage(sender,ChatColor.GREEN + plugin.myLocale().islandislandLevelis + "String_Node_Str"+ ChatColor.WHITE+ plugin.getPlayers().getIslandLevel(targetPlayer));
                    if (event.getLongPointsToNextLevel() >= 0) {
                      String toNextLevel=ChatColor.GREEN + plugin.myLocale().islandrequiredPointsToNextLevel.replace("String_Node_Str",String.valueOf(event.getLongPointsToNextLevel()));
                      toNextLevel=toNextLevel.replace("String_Node_Str",String.valueOf(plugin.getPlayers().getIslandLevel(targetPlayer) + 1));
                      Util.sendMessage(sender,toNextLevel);
                    }
                  }
                }
              }
            }
          }
        }
);
      }
    }
);
  }
}

Fixed version (ground truth):
/** 
 * Calculates the level of an island
 * @param plugin
 * @param targetPlayer - UUID of island owner or team member
 * @param sender - requester of the level calculation, if anyone
 * @param report - provide a report to the asker
 */
public LevelCalcByChunk(final ASkyBlock plugin,final UUID targetPlayer,final CommandSender sender,final boolean report){
  final Island island=plugin.getGrid().getIsland(targetPlayer);
  if (island != null) {
    Player player=plugin.getServer().getPlayer(targetPlayer);
    int multiplier=1;
    if (player != null) {
      for (      PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
        if (perms.getPermission().startsWith(Settings.PERMPREFIX + "String_Node_Str")) {
          String spl[]=perms.getPermission().split(Settings.PERMPREFIX + "String_Node_Str");
          if (spl.length > 1) {
            if (!NumberUtils.isDigits(spl[1])) {
              plugin.getLogger().severe("String_Node_Str" + player.getName() + "String_Node_Str"+ perms.getPermission()+ "String_Node_Str");
            }
 else {
              multiplier=Math.max(multiplier,Integer.valueOf(spl[1]));
            }
          }
        }
        if (multiplier < 1) {
          multiplier=1;
        }
      }
    }
    final int levelMultiplier=multiplier;
    final int levelHandicap=island.getLevelHandicap();
    int deaths=plugin.getPlayers().getDeaths(targetPlayer);
    if (plugin.getPlayers().inTeam(targetPlayer)) {
      deaths=plugin.getPlayers().getDeaths(plugin.getPlayers().getTeamLeader(targetPlayer));
      if (Settings.sumTeamDeaths) {
        deaths=0;
        for (        UUID member : plugin.getPlayers().getMembers(targetPlayer)) {
          deaths+=plugin.getPlayers().getDeaths(member);
        }
      }
    }
    final int deathHandicap=deaths;
    final World world=plugin.getPlayers().getIslandLocation(targetPlayer).getWorld();
    Set<ChunkSnapshot> chunkSnapshot=new HashSet<ChunkSnapshot>();
    for (int x=island.getMinProtectedX(); x < (island.getMinProtectedX() + island.getProtectionSize() + 16); x+=16) {
      for (int z=island.getMinProtectedZ(); z < (island.getMinProtectedZ() + island.getProtectionSize() + 16); z+=16) {
        if (!world.getBlockAt(x,0,z).getChunk().isLoaded()) {
          world.getBlockAt(x,0,z).getChunk().load();
          chunkSnapshot.add(world.getBlockAt(x,0,z).getChunk().getChunkSnapshot());
          world.getBlockAt(x,0,z).getChunk().unload();
        }
 else {
          chunkSnapshot.add(world.getBlockAt(x,0,z).getChunk().getChunkSnapshot());
        }
      }
    }
    final Set<ChunkSnapshot> finalChunk=chunkSnapshot;
    final int worldHeight=world.getMaxHeight();
    plugin.getServer().getScheduler().runTaskAsynchronously(plugin,new Runnable(){
      @SuppressWarnings("String_Node_Str") @Override public void run(){
        File log=null;
        PrintWriter out=null;
        List<MaterialData> mdLog=null;
        List<MaterialData> uwLog=null;
        List<MaterialData> noCountLog=null;
        List<MaterialData> overflowLog=null;
        if (Settings.levelLogging) {
          log=new File(plugin.getDataFolder(),"String_Node_Str");
          try {
            if (log.exists()) {
              out=new PrintWriter(new FileWriter(log,true));
            }
 else {
              out=new PrintWriter(log);
            }
          }
 catch (          FileNotFoundException e) {
            System.out.println("String_Node_Str");
            e.printStackTrace();
          }
catch (          IOException e) {
            System.out.println("String_Node_Str");
            e.printStackTrace();
          }
        }
        if (Settings.levelLogging || report) {
          mdLog=new ArrayList<MaterialData>();
          uwLog=new ArrayList<MaterialData>();
          noCountLog=new ArrayList<MaterialData>();
          overflowLog=new ArrayList<MaterialData>();
        }
        HashMap<MaterialData,Integer> limitCount=new HashMap<MaterialData,Integer>(Settings.blockLimits);
        long blockCount=0;
        long underWaterBlockCount=0;
        for (        ChunkSnapshot chunk : finalChunk) {
          for (int x=0; x < 16; x++) {
            if (chunk.getX() * 16 + x < island.getMinProtectedX() || chunk.getX() * 16 + x >= island.getMinProtectedX() + island.getProtectionSize()) {
              continue;
            }
            for (int z=0; z < 16; z++) {
              if (chunk.getZ() * 16 + z < island.getMinProtectedZ() || chunk.getZ() * 16 + z >= island.getMinProtectedZ() + island.getProtectionSize()) {
                continue;
              }
              for (int y=0; y < worldHeight; y++) {
                int type=chunk.getBlockTypeId(x,y,z);
                int data=chunk.getBlockData(x,y,z);
                MaterialData md=new MaterialData(type,(byte)data);
                MaterialData generic=new MaterialData(type);
                if (type != 0) {
                  if (limitCount.containsKey(md) && Settings.blockValues.containsKey(md)) {
                    int count=limitCount.get(md);
                    if (count > 0) {
                      limitCount.put(md,--count);
                      if (Settings.seaHeight > 0 && y <= Settings.seaHeight) {
                        underWaterBlockCount+=Settings.blockValues.get(md);
                        if (Settings.levelLogging || report) {
                          uwLog.add(md);
                        }
                      }
 else {
                        blockCount+=Settings.blockValues.get(md);
                        if (Settings.levelLogging || report) {
                          mdLog.add(md);
                        }
                      }
                    }
 else                     if (Settings.levelLogging || report) {
                      overflowLog.add(md);
                    }
                  }
 else                   if (limitCount.containsKey(generic) && Settings.blockValues.containsKey(generic)) {
                    int count=limitCount.get(generic);
                    if (count > 0) {
                      limitCount.put(generic,--count);
                      if (Settings.seaHeight > 0 && y <= Settings.seaHeight) {
                        underWaterBlockCount+=Settings.blockValues.get(generic);
                        if (Settings.levelLogging || report) {
                          uwLog.add(md);
                        }
                      }
 else {
                        blockCount+=Settings.blockValues.get(generic);
                        if (Settings.levelLogging || report) {
                          mdLog.add(md);
                        }
                      }
                    }
 else                     if (Settings.levelLogging || report) {
                      overflowLog.add(md);
                    }
                  }
 else                   if (Settings.blockValues.containsKey(md)) {
                    if (Settings.seaHeight > 0 && y <= Settings.seaHeight) {
                      underWaterBlockCount+=Settings.blockValues.get(md);
                      if (Settings.levelLogging || report) {
                        uwLog.add(md);
                      }
                    }
 else {
                      blockCount+=Settings.blockValues.get(md);
                      if (Settings.levelLogging || report) {
                        mdLog.add(md);
                      }
                    }
                  }
 else                   if (Settings.blockValues.containsKey(generic)) {
                    if (Settings.seaHeight > 0 && y <= Settings.seaHeight) {
                      underWaterBlockCount+=Settings.blockValues.get(generic);
                      if (Settings.levelLogging || report) {
                        uwLog.add(md);
                      }
                    }
 else {
                      blockCount+=Settings.blockValues.get(generic);
                      if (Settings.levelLogging || report) {
                        mdLog.add(md);
                      }
                    }
                  }
 else                   if (Settings.levelLogging || report) {
                    noCountLog.add(md);
                  }
                }
              }
            }
          }
        }
        blockCount+=(long)((double)underWaterBlockCount * Settings.underWaterMultiplier);
        final long score=(((blockCount * levelMultiplier) - (deathHandicap * Settings.deathpenalty)) / Settings.levelCost) - levelHandicap;
        if (Settings.levelLogging || report) {
          Multiset<MaterialData> uwCount=HashMultiset.create(uwLog);
          Multiset<MaterialData> mdCount=HashMultiset.create(mdLog);
          Multiset<MaterialData> ncCount=HashMultiset.create(noCountLog);
          Multiset<MaterialData> ofCount=HashMultiset.create(overflowLog);
          reportLines.add("String_Node_Str" + island.getCenter());
          if (sender instanceof Player) {
            reportLines.add("String_Node_Str" + sender.getName() + "String_Node_Str"+ ((Player)sender).getUniqueId().toString()+ "String_Node_Str");
          }
 else {
            reportLines.add("String_Node_Str");
          }
          reportLines.add("String_Node_Str" + targetPlayer.toString());
          reportLines.add("String_Node_Str" + String.format("String_Node_Str",blockCount));
          reportLines.add("String_Node_Str" + Settings.levelCost);
          reportLines.add("String_Node_Str" + levelMultiplier + "String_Node_Str");
          reportLines.add("String_Node_Str" + levelHandicap + "String_Node_Str");
          reportLines.add("String_Node_Str" + (deathHandicap * Settings.deathpenalty) + "String_Node_Str"+ deathHandicap+ "String_Node_Str");
          reportLines.add("String_Node_Str" + score);
          reportLines.add("String_Node_Str");
          int total=0;
          if (!uwCount.isEmpty()) {
            reportLines.add("String_Node_Str" + Settings.underWaterMultiplier + "String_Node_Str");
            reportLines.add("String_Node_Str" + String.format("String_Node_Str",uwCount.size()));
            Iterable<Multiset.Entry<MaterialData>> entriesSortedByCount=Multisets.copyHighestCountFirst(uwCount).entrySet();
            Iterator<Entry<MaterialData>> it=entriesSortedByCount.iterator();
            while (it.hasNext()) {
              Entry<MaterialData> type=it.next();
              int value=0;
              if (Settings.blockValues.containsKey(type)) {
                value=Settings.blockValues.get(type);
              }
 else               if (Settings.blockValues.containsKey(new MaterialData(type.getElement().getItemType()))) {
                value=Settings.blockValues.get(new MaterialData(type.getElement().getItemType()));
              }
              if (value > 0) {
                reportLines.add(type.getElement().toString() + "String_Node_Str" + String.format("String_Node_Str",type.getCount())+ "String_Node_Str"+ value+ "String_Node_Str"+ (value * type.getCount()));
                total+=(value * type.getCount());
              }
            }
            reportLines.add("String_Node_Str" + total);
            reportLines.add("String_Node_Str");
          }
          reportLines.add("String_Node_Str");
          reportLines.add("String_Node_Str" + String.format("String_Node_Str",mdCount.size()));
          Iterable<Multiset.Entry<MaterialData>> entriesSortedByCount=mdCount.entrySet();
          Iterator<Entry<MaterialData>> it=entriesSortedByCount.iterator();
          while (it.hasNext()) {
            Entry<MaterialData> type=it.next();
            int value=0;
            if (Settings.blockValues.containsKey(type)) {
              value=Settings.blockValues.get(type);
            }
 else             if (Settings.blockValues.containsKey(new MaterialData(type.getElement().getItemType()))) {
              value=Settings.blockValues.get(new MaterialData(type.getElement().getItemType()));
            }
            if (value > 0) {
              reportLines.add(type.getElement().toString() + "String_Node_Str" + String.format("String_Node_Str",type.getCount())+ "String_Node_Str"+ value+ "String_Node_Str"+ (value * type.getCount()));
              total+=(value * type.getCount());
            }
          }
          reportLines.add("String_Node_Str" + total);
          reportLines.add("String_Node_Str");
          reportLines.add("String_Node_Str" + String.format("String_Node_Str",ofCount.size()));
          entriesSortedByCount=ofCount.entrySet();
          it=entriesSortedByCount.iterator();
          while (it.hasNext()) {
            Entry<MaterialData> type=it.next();
            Integer limit=Settings.blockLimits.get(type.getElement());
            String explain="String_Node_Str";
            if (limit == null) {
              MaterialData generic=new MaterialData(type.getElement().getItemType());
              limit=Settings.blockLimits.get(generic);
              explain="String_Node_Str";
            }
            reportLines.add(type.getElement().toString() + "String_Node_Str" + String.format("String_Node_Str",type.getCount())+ "String_Node_Str"+ limit+ explain);
          }
          reportLines.add("String_Node_Str");
          reportLines.add("String_Node_Str");
          reportLines.add("String_Node_Str" + String.format("String_Node_Str",ncCount.size()));
          entriesSortedByCount=ncCount.entrySet();
          it=entriesSortedByCount.iterator();
          while (it.hasNext()) {
            Entry<MaterialData> type=it.next();
            reportLines.add(type.getElement().toString() + "String_Node_Str" + String.format("String_Node_Str",type.getCount())+ "String_Node_Str");
          }
          reportLines.add("String_Node_Str");
        }
        if (out != null) {
          for (          String line : reportLines) {
            out.println(line);
          }
          System.out.println("String_Node_Str");
          out.close();
        }
        long calculatePointsToNextLevel=(Settings.levelCost * (score + 1 + levelHandicap)) - ((blockCount * levelMultiplier) - (deathHandicap * Settings.deathpenalty));
        if (calculatePointsToNextLevel == 0)         calculatePointsToNextLevel=(Settings.levelCost * (score + 2 + levelHandicap)) - ((blockCount * levelMultiplier) - (deathHandicap * Settings.deathpenalty));
        final long pointsToNextLevel=calculatePointsToNextLevel;
        plugin.getServer().getScheduler().runTask(plugin,new Runnable(){
          @Override public void run(){
            Island island=plugin.getGrid().getIsland(targetPlayer);
            final IslandPreLevelEvent event=new IslandPreLevelEvent(targetPlayer,island,score);
            event.setLongPointsToNextLevel(pointsToNextLevel);
            plugin.getServer().getPluginManager().callEvent(event);
            long oldLevel=plugin.getPlayers().getIslandLevel(targetPlayer);
            if (!event.isCancelled()) {
              if (oldLevel != event.getLevel()) {
                plugin.getPlayers().setIslandLevel(targetPlayer,event.getLevel());
                plugin.getPlayers().save(targetPlayer);
              }
              if (plugin.getPlayers().inTeam(targetPlayer)) {
                for (                UUID member : plugin.getPlayers().getMembers(targetPlayer)) {
                  if (plugin.getPlayers().getIslandLevel(member) != event.getLevel()) {
                    plugin.getPlayers().setIslandLevel(member,event.getLevel());
                    plugin.getPlayers().save(member);
                  }
                }
              }
              if (plugin.getPlayers().inTeam(targetPlayer)) {
                UUID leader=plugin.getPlayers().getTeamLeader(targetPlayer);
                if (leader != null) {
                  TopTen.topTenAddEntry(leader,event.getLongLevel());
                }
              }
 else {
                TopTen.topTenAddEntry(targetPlayer,event.getLongLevel());
              }
            }
            final IslandPostLevelEvent event3=new IslandPostLevelEvent(targetPlayer,island,event.getLongLevel(),event.getLongPointsToNextLevel());
            plugin.getServer().getPluginManager().callEvent(event3);
            if (!event3.isCancelled()) {
              if (sender != null) {
                if (!(sender instanceof Player)) {
                  if (!report) {
                    Util.sendMessage(sender,ChatColor.GREEN + plugin.myLocale().islandislandLevelis + "String_Node_Str"+ ChatColor.WHITE+ plugin.getPlayers().getIslandLevel(targetPlayer));
                  }
 else {
                    for (                    String line : reportLines) {
                      Util.sendMessage(sender,line);
                    }
                    Util.sendMessage(sender,ChatColor.GREEN + plugin.myLocale().islandislandLevelis + "String_Node_Str"+ ChatColor.WHITE+ plugin.getPlayers().getIslandLevel(targetPlayer));
                    if (event.getLongPointsToNextLevel() >= 0) {
                      String toNextLevel=ChatColor.GREEN + plugin.myLocale().islandrequiredPointsToNextLevel.replace("String_Node_Str",String.valueOf(event.getLongPointsToNextLevel()));
                      toNextLevel=toNextLevel.replace("String_Node_Str",String.valueOf(plugin.getPlayers().getIslandLevel(targetPlayer) + 1));
                      Util.sendMessage(sender,toNextLevel);
                    }
                  }
                }
 else {
                  if (!report) {
                    if (plugin.getPlayers().getIslandLevel(targetPlayer) != oldLevel) {
                      plugin.getMessages().tellOfflineTeam(targetPlayer,ChatColor.GREEN + plugin.myLocale(targetPlayer).islandislandLevelis + "String_Node_Str"+ ChatColor.WHITE+ plugin.getPlayers().getIslandLevel(targetPlayer));
                    }
                    if (sender instanceof Player && ((Player)sender).isOnline()) {
                      String message=ChatColor.GREEN + plugin.myLocale(((Player)sender).getUniqueId()).islandislandLevelis + "String_Node_Str"+ ChatColor.WHITE+ plugin.getPlayers().getIslandLevel(targetPlayer);
                      if (Settings.deathpenalty != 0) {
                        message+="String_Node_Str" + plugin.myLocale(((Player)sender).getUniqueId()).levelDeaths.replace("String_Node_Str",String.valueOf(deathHandicap));
                      }
                      Util.sendMessage(sender,message);
                      if (event.getLongPointsToNextLevel() >= 0) {
                        String toNextLevel=ChatColor.GREEN + plugin.myLocale(((Player)sender).getUniqueId()).islandrequiredPointsToNextLevel.replace("String_Node_Str",String.valueOf(event.getLongPointsToNextLevel()));
                        toNextLevel=toNextLevel.replace("String_Node_Str",String.valueOf(plugin.getPlayers().getIslandLevel(targetPlayer) + 1));
                        Util.sendMessage(sender,toNextLevel);
                      }
                    }
                  }
 else {
                    if (((Player)sender).isOnline()) {
                      for (                      String line : reportLines) {
                        Util.sendMessage(sender,line);
                      }
                    }
                    Util.sendMessage(sender,ChatColor.GREEN + plugin.myLocale().islandislandLevelis + "String_Node_Str"+ ChatColor.WHITE+ plugin.getPlayers().getIslandLevel(targetPlayer));
                    if (event.getLongPointsToNextLevel() >= 0) {
                      String toNextLevel=ChatColor.GREEN + plugin.myLocale().islandrequiredPointsToNextLevel.replace("String_Node_Str",String.valueOf(event.getLongPointsToNextLevel()));
                      toNextLevel=toNextLevel.replace("String_Node_Str",String.valueOf(plugin.getPlayers().getIslandLevel(targetPlayer) + 1));
                      Util.sendMessage(sender,toNextLevel);
                    }
                  }
                }
              }
            }
          }
        }
);
      }
    }
);
  }
}