private void validateBlockLocation(Player player, Location loc) throws CivException {
    Block b = loc.getBlock();

    if (ItemManager.getId(b) == CivData.CHEST) {
      throw new CivException("Cannot build here, would destroy chest.");
    }

    TownChunk tc = CivGlobal.getTownChunk(b.getLocation());

    if (tc != null
        && !tc.perms.hasPermission(PlotPermissions.Type.DESTROY, CivGlobal.getResident(player))) {
      // Make sure we have permission to destroy any block in this area.
      throw new CivException(
          "Cannot build here, you need DESTROY permissions to the block at "
              + b.getX()
              + ","
              + b.getY()
              + ","
              + b.getZ());
    }

    BlockCoord coord = new BlockCoord(b);
    // not building a trade outpost, prevent protected blocks from being destroyed.
    if (CivGlobal.getProtectedBlock(coord) != null) {
      throw new CivException("Cannot build here, protected blocks in the way.");
    }

    if (CivGlobal.getStructureBlock(coord) != null) {
      throw new CivException("Cannot build here, structure blocks in the way at " + coord);
    }

    if (CivGlobal.getFarmChunk(new ChunkCoord(coord.getLocation())) != null) {
      throw new CivException("Cannot build here, in the same chunk as a farm improvement.");
    }

    if (loc.getBlockY() >= Wall.MAX_HEIGHT) {
      throw new CivException("Cannot build here, wall is too high.");
    }

    if (loc.getBlockY() <= 1) {
      throw new CivException("Cannot build here, too close to bedrock.");
    }

    BlockCoord bcoord = new BlockCoord(loc);
    for (int y = 0; y < 256; y++) {
      bcoord.setY(y);
      StructureBlock sb = CivGlobal.getStructureBlock(bcoord);
      if (sb != null) {
        throw new CivException(
            "Cannot build here, this wall segment overlaps with a structure block belonging to a "
                + sb.getOwner().getName()
                + " structure.");
      }
    }
  }
  private boolean isValidWall() {
    for (WallBlock block : this.wallBlocks.values()) {
      BlockCoord bcoord = new BlockCoord(block.getCoord());

      for (int y = 0; y < 256; y++) {
        bcoord.setY(y);

        StructureBlock sb = CivGlobal.getStructureBlock(bcoord);
        if (sb != null) {
          if (sb.getOwner() != this) {
            return false;
          }
        }
      }
    }

    return true;
  }
  public void onHit() {
    // launchExplodeFirework(loc);

    int radius = (int) yield;
    HashSet<Buildable> structuresHit = new HashSet<Buildable>();

    for (int x = -radius; x < radius; x++) {
      for (int z = -radius; z < radius; z++) {
        for (int y = -radius; y < radius; y++) {

          Block b = loc.getBlock().getRelative(x, y, z);
          if (ItemManager.getId(b) == CivData.BEDROCK) {
            continue;
          }

          if (loc.distance(b.getLocation()) <= yield) {
            bcoord.setFromLocation(b.getLocation());
            StructureBlock sb = CivGlobal.getStructureBlock(bcoord);
            CampBlock cb = CivGlobal.getCampBlock(bcoord);

            if (sb == null && cb == null) {
              explodeBlock(b);
              continue;
            }

            if (sb != null) {

              if (!sb.isDamageable()) {
                continue;
              }

              if (sb.getOwner() instanceof TownHall) {
                TownHall th = (TownHall) sb.getOwner();
                if (th.getControlPoints().containsKey(bcoord)) {
                  continue;
                }
              }

              if (!sb.getOwner().isDestroyed()) {
                if (!structuresHit.contains(sb.getOwner())) {

                  structuresHit.add(sb.getOwner());

                  if (sb.getOwner() instanceof TownHall) {
                    TownHall th = (TownHall) sb.getOwner();

                    if (th.getHitpoints() == 0) {
                      explodeBlock(b);
                    } else {
                      th.onCannonDamage(cannon.getDamage());
                    }
                  } else {
                    Player player = null;
                    try {
                      player = CivGlobal.getPlayer(whoFired);
                    } catch (CivException e) {
                    }

                    if (!sb.getCiv().getDiplomacyManager().atWarWith(whoFired.getCiv())) {
                      if (player != null) {
                        CivMessage.sendError(
                            player,
                            "Cannot damage structures in civilizations we're not at war with.");
                        return;
                      }
                    }

                    sb.getOwner()
                        .onDamage(cannon.getDamage(), b.getWorld(), player, sb.getCoord(), sb);
                    CivMessage.sendCiv(
                        sb.getCiv(),
                        CivColor.Yellow
                            + "Our "
                            + sb.getOwner().getDisplayName()
                            + " at ("
                            + sb.getOwner().getCenterLocation().getX()
                            + ","
                            + sb.getOwner().getCenterLocation().getY()
                            + ","
                            + sb.getOwner().getCenterLocation().getZ()
                            + ")"
                            + " was hit by a cannon! ("
                            + sb.getOwner().getHitpoints()
                            + "/"
                            + sb.getOwner().getMaxHitPoints()
                            + ")");
                  }

                  CivMessage.sendCiv(
                      whoFired.getCiv(),
                      CivColor.LightGreen
                          + "We've hit "
                          + sb.getOwner().getTown().getName()
                          + "'s "
                          + sb.getOwner().getDisplayName()
                          + " with a cannon!"
                          + " ("
                          + sb.getOwner().getHitpoints()
                          + "/"
                          + sb.getOwner().getMaxHitPoints()
                          + ")");
                }
              } else {

                if (!IronCannon.cannonBlocks.containsKey(bcoord)) {
                  explodeBlock(b);
                }
              }
              continue;
            }
          }
        }
      }
    }

    /* Instantly kill any players caught in the blast. */
    LinkedList<Entity> players =
        EntityProximity.getNearbyEntities(null, loc, yield, EntityPlayer.class);
    for (Entity e : players) {
      Player player = (Player) e;
      player.damage(playerDamage);
      if (player.isDead()) {
        CivMessage.global(
            CivColor.LightGray
                + whoFired.getName()
                + " obliterated "
                + player.getName()
                + " with a cannon blast!");
      }
    }
  }