@Override
  public void undoFromTemplate() {

    if (this.nextWallBuilt == null) {
      for (BlockCoord coord : wallBlocks.keySet()) {
        WallBlock wb = wallBlocks.get(coord);
        ItemManager.setTypeId(coord.getBlock(), wb.getOldId());
        ItemManager.setData(coord.getBlock(), wb.getOldData());
        try {
          wb.delete();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }

      // Remove this wall chunk.
      ChunkCoord coord = new ChunkCoord(this.getCorner());
      CivGlobal.removeWallChunk(this, coord);
    } else {
      try {
        this.nextWallBuilt.processUndo();
      } catch (CivException e) {
        e.printStackTrace();
      }
    }
  }
  @Override
  public void processUndo() throws CivException {

    double refund = 0.0;
    for (WallBlock wb : wallBlocks.values()) {

      Material material = ItemManager.getMaterial(wb.getOldId());
      if (CivSettings.restrictedUndoBlocks.contains(material)) {
        continue;
      }

      ItemManager.setTypeId(wb.getCoord().getBlock(), wb.getOldId());
      ItemManager.setData(wb.getCoord().getBlock(), wb.getOldData());
      refund += COST_PER_SEGMENT;
      try {
        wb.delete();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }

    refund /= HEIGHT;
    refund = Math.round(refund);
    this.getTown().getTreasury().deposit(refund);
    CivMessage.sendTown(
        this.getTown(), CivColor.Yellow + "Refunded " + refund + " coins from wall construction.");
    try {
      this.delete();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }