Esempio n. 1
0
  public synchronized boolean write(RegionFileCache regionFileCache) {
    boolean error = false;
    RegionFile regionFile = regionFileCache.getRegionFile(this.x << 4, this.z << 4, this.dimension);
    if (!regionFile.isOpen()) {
      error = regionFile.open();
    }
    if (!error) {
      DataOutputStream dos = regionFile.getChunkDataOutputStream(this.x & 31, this.z & 31);
      if (dos != null) {
        Nbt chunkNbt = this.getNbt();
        try {
          // RegionManager.logInfo("writing chunk (%d, %d) to region file", this.x, this.z);
          chunkNbt.writeElement(dos);
        } catch (IOException e) {
          RegionManager.logError(
              "%s: could not write chunk (%d, %d) to region file", e, this.x, this.z);
          error = true;
        } finally {
          try {
            dos.close();
          } catch (IOException e) {
            RegionManager.logError("%s while closing chunk data output stream", e);
          }
        }
      } else {
        RegionManager.logError(
            "error: could not get output stream for chunk (%d, %d)", this.x, this.z);
      }
    } else {
      RegionManager.logError(
          "error: could not open region file for chunk (%d, %d)", this.x, this.z);
    }

    return error;
  }
 public int getPostGradHousing(HttpSession session) {
   int totalHousingOrRent = 0; // If you are commuting for free
   String housingSituation = (String) session.getAttribute("aspirations_house");
   if (housingSituation != null) {
     String s = new String(housingSituation);
     s = s.toLowerCase();
     String region = (String) session.getAttribute("aspirations_region");
     int utility = (Integer) session.getAttribute("lifestyle_bills");
     if (s.contains("own")) {
       totalHousingOrRent = (regionManager.getMortgageBasedOffRegionName(region)) + utility;
     } else if (s.contains("rent")) {
       int rent = regionManager.getRentBasedOffRegionName(region);
       // If we are Apartment based
       totalHousingOrRent = utility + rent;
     }
   }
   return totalHousingOrRent;
 }
Esempio n. 3
0
  @Override
  public void render(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {
    ServletContext context = (ServletContext) request.getAttribute("servletContext");
    boolean verboseOn = Debug.verboseOn();

    if (verboseOn) Debug.logVerbose("Rendering " + this.toString(), module);

    // long viewStartTime = System.currentTimeMillis();
    if (content != null) {
      if ("direct".equals(type)) {
        if (UtilJ2eeCompat.useOutputStreamNotWriter(context)) {
          response.getOutputStream().print(content);
        } else {
          response.getWriter().print(content);
        }
      } else if ("default".equals(type)
          || "region".equals(type)
          || "resource".equals(type)
          || "jpublish".equals(type)) {
        // if type is resource then we won't even look up the region

        // if this is default or region, check to see if the content points to a valid region name
        Region region = null;

        if ("default".equals(type) || "region".equals(type)) {
          region = regionManager.getRegion(content);
        }

        if ("region".equals(type) || region != null) {
          if (region == null) {
            throw new IllegalArgumentException("No region definition found with name: " + content);
          }
          // render the content as a region
          RegionStack.push(request, region);
          region.render(request, response);
          RegionStack.pop(request);
        } else if ("jpublish".equals(type)) {
          // rather then using the view handler use the wrapper directly
          /* NOTE: In order to use the "jpublish" section type the JPublish libraries must be added as described in OPTIONAL_LIBRARIES and then uncomment this section
          ServletContext sctx = (ServletContext) request.getAttribute("servletContext");
          if (sctx != null) {
              JPublishWrapper jp = this.getJPublishWrapper(sctx);
              if (jp != null) {
                  String contentStr = "<!-- " + content + " Not Processed -->";
                  try {
                      contentStr = jp.render(content, request, response);
                  } catch (GeneralException e) {
                      Debug.logError(e, "Problems rendering view from JPublish", module);
                  }
                  if (UtilJ2eeCompat.useOutputStreamNotWriter(context)) {
                      response.getOutputStream().print(contentStr);
                  } else {
                      response.getWriter().print(contentStr);
                  }
              } else {
                  throw new IllegalStateException("No jpublishWrapper found in ServletContext");
              }
          } else {
              throw new IllegalStateException("No servletContext found in request");
          }
           */
        } else {
          // default is the string that the ViewFactory expects for webapp resources
          viewHandlerRender("default", request, response);
        }
      } else {
        viewHandlerRender(type, request, response);
      }
    }
    if (verboseOn) Debug.logVerbose("DONE Rendering " + this.toString(), module);
  }
Esempio n. 4
0
  // load from anvil file
  public static MwChunk read(int x, int z, int dimension, RegionFileCache regionFileCache) {

    byte[] biomeArray = null;
    byte[][] msbArray = new byte[16][];
    byte[][] lsbArray = new byte[16][];
    byte[][] metaArray = new byte[16][];
    byte[][] lightingArray = new byte[16][];

    DataInputStream dis = null;
    RegionFile regionFile = regionFileCache.getRegionFile(x << 4, z << 4, dimension);
    if (!regionFile.isOpen()) {
      if (regionFile.exists()) {
        regionFile.open();
      }
    }

    if (regionFile.isOpen()) {
      dis = regionFile.getChunkDataInputStream(x & 31, z & 31);
    }

    if (dis != null) {
      try {

        // chunk NBT structure:
        //
        // COMPOUND ""
        // COMPOUND "level"
        //  INT "xPos"
        //  INT "zPos"
        //  LONG "LastUpdate"
        //  BYTE "TerrainPopulated"
        //  BYTE_ARRAY "Biomes"
        //  INT_ARRAY "HeightMap"
        //  LIST(COMPOUND) "Sections"
        //	      BYTE "Y"
        //	      BYTE_ARRAY "Blocks"
        //	      BYTE_ARRAY "Add"
        //	      BYTE_ARRAY "Data"
        //	      BYTE_ARRAY "BlockLight"
        //	      BYTE_ARRAY "SkyLight"
        //			 END
        //  LIST(COMPOUND) "Entities"
        //  LIST(COMPOUND) "TileEntities"
        //  LIST(COMPOUND) "TileTicks"
        // END
        // END

        Nbt root = Nbt.readNextElement(dis);
        Nbt level = root.getChild("Level");

        int xNbt = level.getChild("xPos").getInt();
        int zNbt = level.getChild("zPos").getInt();
        if ((xNbt != x) || (zNbt != z)) {
          RegionManager.logWarning("chunk (%d, %d) has NBT coords (%d, %d)", x, z, xNbt, zNbt);
        }

        Nbt sections = level.getChild("Sections");

        // loop through each of the sections (16 x 16 x 16 block volumes) present
        for (int i = 0; i < sections.size(); i++) {
          Nbt section = sections.getChild(i);
          if (!section.isNull()) {
            int y = section.getChild("Y").getByte();
            lsbArray[y & 0xf] = section.getChild("Blocks").getByteArray();
            msbArray[y & 0xf] = section.getChild("Add").getByteArray();
            metaArray[y & 0xf] = section.getChild("Data").getByteArray();
          }
        }
        biomeArray = level.getChild("Biomes").getByteArray();

      } catch (IOException e) {
        RegionManager.logError("%s: could not read chunk (%d, %d) from region file\n", e, x, z);
      } finally {
        try {
          dis.close();
        } catch (IOException e) {
          RegionManager.logError("MwChunk.read: %s while closing input stream", e);
        }
      }
      // this.log("MwChunk.read: chunk (%d, %d) empty=%b", this.x, this.z, empty);
    } else {
      // this.log("MwChunk.read: chunk (%d, %d) input stream is null", this.x, this.z);
    }

    return new MwChunk(x, z, dimension, msbArray, lsbArray, metaArray, lightingArray, biomeArray);
  }