コード例 #1
0
  public void storeClaimBackup(Claim claim, World world) {
    int baseX = getBase(claim.getX());
    long topX = claim.getX() >= 0 ? baseX + claimSize : baseX - claimSize;

    int baseZ = getBase(claim.getZ());
    long topZ = claim.getZ() >= 0 ? baseZ + claimSize : baseZ - claimSize;

    int maxY = world.getMaxHeight();

    Properties props = new Properties();

    for (int y = 0; y <= maxY; y++) {
      for (int z = baseZ; z <= topZ; z++) {
        for (int x = baseX; x <= topX; x++) {
          Block blockAt = world.getBlockAt(x, y, z);
          props.put(
              String.format("%d,%d,%d", x, y, z),
              String.format("%d:%d", blockAt.getTypeId(), blockAt.getData()));
        }
      }
    }

    File file = new File(backupFolder, String.format("claim-%d.xml"));

    try {
      props.storeToXML(
          new FileOutputStream(file), String.format("Claim backup for claim %d", claim.getId()));
    } catch (FileNotFoundException e) {
      logger.severe("Could not write backup to file" + file.getName());
    } catch (IOException e) {
      logger.severe("Could not write backup to file" + file.getName() + ": " + e.getMessage());
    }
  }
コード例 #2
0
  synchronized void mapClaims() {
    claims.clear();

    for (Claim claim : database.find(Claim.class).findList()) {
      final int x = claim.getX();
      final int z = claim.getZ();
      final String world = claim.getWorld();

      if (!claims.containsKey(world)) {
        claims.put(world, new SpatialMap<SpatialKey, Claim>(2, 10));
      }

      for (SpatialKey key : getCorners(x, z)) {
        claims.get(world).put(key, claim);
      }
    }
  }