Esempio n. 1
0
  @Override
  public RegionDatabase load(UUID uuid) {
    HashMap<UUID, ProtectedChunkRegion> protectedChunks = new HashMap<>();
    PreparedStatement preparedStatement =
        baseSqliteConnection.createPreparedStatement(
            "SELECT COUNT(REGION_DATA) AS _SIZE_ FROM UPRO_%w_REGIONS"
                .replace("%w", uuid.toString().replace("-", "")));

    try {
      int size = preparedStatement.executeQuery().getInt("_SIZE_");
      preparedStatement =
          baseSqliteConnection.createPreparedStatement(
              "SELECT REGION_DATA FROM UPRO_%w_REGIONS"
                  .replace("%w", uuid.toString().replace("-", "")));
      ResultSet regions = preparedStatement.executeQuery();

      int i = 0;
      while (i < size) {
        ProtectedChunkRegion protectedChunkRegion =
            ProtectedChunkRegion.deserialize(regions.getString(1));
        protectedChunks.put(protectedChunkRegion.getUUID(), protectedChunkRegion);
        i++;
        regions.next();
      }
      preparedStatement.close();

    } catch (SQLException e) {
      e.printStackTrace();
    }

    return new RegionDatabase(protectedChunks);
  }
Esempio n. 2
0
  @Override
  public void save(ProtectedChunkRegion protectedChunkRegion) {
    PreparedStatement var1;
    Iterator<ProtectedChunk> var2 = protectedChunkRegion.getProtectedChunks().iterator();
    ProtectedChunk var3;
    UUID currentUUID;

    while (var2.hasNext()) {
      try {
        var1 =
            baseSqliteConnection.createPreparedStatement(
                baseSqliteConnection.insertRegionIndex.replace(
                    "%w", protectedChunkRegion.getWorld().getUID().toString().replace("-", "")));

        var3 = var2.next();

        currentUUID = protectedChunkRegion.getUUID();
        var1.setString(1, protectedChunkRegion.getId());
        var1.setInt(2, var3.getX());
        var1.setInt(3, var3.getZ());
        var1.setString(
            4,
            String.format(
                "%s:%s",
                String.valueOf(currentUUID.getMostSignificantBits()),
                String.valueOf(currentUUID.getLeastSignificantBits())));
        var1.executeUpdate();
        var1.close();

        var1 =
            baseSqliteConnection.createPreparedStatement(
                baseSqliteConnection.insertRegion.replace(
                    "%w", protectedChunkRegion.getWorld().getUID().toString().replace("-", "")));
        var1.setString(
            1,
            String.format(
                "%s:%s",
                String.valueOf(currentUUID.getMostSignificantBits()),
                String.valueOf(currentUUID.getLeastSignificantBits())));
        var1.setString(2, protectedChunkRegion.serialize());
        var1.executeUpdate();
        var1.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }