public boolean hasPermission(Resident res, Segment segment, int dim, Volume area) { boolean inWild = false; for (int townBlockX = area.getMinX() >> 4; townBlockX <= area.getMaxX() >> 4; townBlockX++) { for (int townBlockZ = area.getMinZ() >> 4; townBlockZ <= area.getMaxZ() >> 4; townBlockZ++) { TownBlock townBlock = getDatasource().getBlock(dim, townBlockX, townBlockZ); if (townBlock == null) { inWild = true; } else { Town town = townBlock.getTown(); Volume rangeBox = townBlock.getAreaLimit(area); int totalIntersectArea = 0; // Check every plot in the current TownBlock and sum all plot areas for (Plot plot : townBlock.getPlots()) { int plotIntersectArea = plot.getIntersectingArea(rangeBox); if (plotIntersectArea > 0) { if (res == null) { if (plot.getValue(segment.getFlag()).equals(segment.getDenialValue())) { return false; } } else { if (!plot.hasPermission(res, segment.getFlag(), segment.getDenialValue())) { res.protectionDenial( segment.getFlag().getLocalizedProtectionDenial(), LocalizationProxy.getLocalization() .getLocalization( "mytown.notification.town.owners", town.getMayor() == null ? "SERVER ADMINS" : town.getMayor().getPlayerName())); return false; } } } totalIntersectArea += plotIntersectArea; } // If plot area sum is not equal to range area, check town permission if (totalIntersectArea != getArea(rangeBox)) { if (res == null) { if (town.getValue(segment.getFlag()).equals(segment.getDenialValue())) { return false; } } else { if (!town.hasPermission(res, segment.getFlag(), segment.getDenialValue())) { res.protectionDenial( segment.getFlag().getLocalizedProtectionDenial(), LocalizationProxy.getLocalization() .getLocalization( "mytown.notification.town.owners", town.getMayor() == null ? "SERVER ADMINS" : town.getMayor().getPlayerName())); return false; } } } } } } if (inWild) { if (res == null) { if (Wild.instance.getValue(segment.getFlag()).equals(segment.getDenialValue())) { return false; } } else { if (!Wild.instance.hasPermission(res, segment.getFlag(), segment.getDenialValue())) { res.sendMessage(segment.getFlag().getLocalizedProtectionDenial()); return false; } } } return true; }