use of cn.nukkit.level.format.leveldb.LevelDB in project Nukkit by Nukkit.
the class LevelProviderConverter method perform.
LevelProvider perform() throws IOException {
new File(path).mkdir();
File dat = new File(provider.getPath(), "level.dat.old");
new File(provider.getPath(), "level.dat").renameTo(dat);
Utils.copyFile(dat, new File(path, "level.dat"));
LevelProvider result;
try {
if (provider instanceof LevelDB) {
try (FileInputStream stream = new FileInputStream(path + "level.dat")) {
stream.skip(8);
CompoundTag levelData = NBTIO.read(stream, ByteOrder.LITTLE_ENDIAN);
if (levelData != null) {
NBTIO.writeGZIPCompressed(new CompoundTag().putCompound("Data", levelData), new FileOutputStream(path + "level.dat"));
} else {
throw new IOException("LevelData can not be null");
}
} catch (IOException e) {
throw new LevelException("Invalid level.dat");
}
}
result = toClass.getConstructor(Level.class, String.class).newInstance(level, path);
} catch (Exception e) {
throw new RuntimeException(e);
}
if (toClass == Anvil.class) {
if (provider instanceof McRegion) {
new File(path, "region").mkdir();
for (File file : new File(provider.getPath() + "region/").listFiles()) {
Matcher m = Pattern.compile("-?\\d+").matcher(file.getName());
int regionX, regionZ;
try {
if (m.find()) {
regionX = Integer.parseInt(m.group());
} else
continue;
if (m.find()) {
regionZ = Integer.parseInt(m.group());
} else
continue;
} catch (NumberFormatException e) {
continue;
}
RegionLoader region = new RegionLoader(provider, regionX, regionZ);
for (Integer index : region.getLocationIndexes()) {
int chunkX = index & 0x1f;
int chunkZ = index >> 5;
BaseFullChunk old = region.readChunk(chunkX, chunkZ);
if (old == null)
continue;
int x = (regionX << 5) | chunkX;
int z = (regionZ << 5) | chunkZ;
FullChunk chunk = new ChunkConverter(result).from(old).to(Chunk.class).perform();
result.saveChunk(x, z, chunk);
}
region.close();
}
}
if (provider instanceof LevelDB) {
new File(path, "region").mkdir();
for (byte[] key : ((LevelDB) provider).getTerrainKeys()) {
int x = getChunkX(key);
int z = getChunkZ(key);
BaseFullChunk old = ((LevelDB) provider).readChunk(x, z);
FullChunk chunk = new ChunkConverter(result).from(old).to(Chunk.class).perform();
result.saveChunk(x, z, chunk);
}
}
result.doGarbageCollection();
}
return result;
}
Aggregations