mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-06-18 06:41:08 +00:00
sync
This commit is contained in:
@@ -18,6 +18,7 @@ import com.volmit.iris.util.plugin.VolmitSender;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
@@ -31,7 +32,6 @@ public class IrisWorldDump {
|
|||||||
private File MCADirectory;
|
private File MCADirectory;
|
||||||
private AtomicInteger regionsProcessed;
|
private AtomicInteger regionsProcessed;
|
||||||
private AtomicInteger chunksProcessed;
|
private AtomicInteger chunksProcessed;
|
||||||
private AtomicInteger totalToProcess;
|
|
||||||
private AtomicInteger totalMaxChunks;
|
private AtomicInteger totalMaxChunks;
|
||||||
private AtomicInteger totalMCAFiles;
|
private AtomicInteger totalMCAFiles;
|
||||||
private RollingSequence chunksPerSecond;
|
private RollingSequence chunksPerSecond;
|
||||||
@@ -41,7 +41,6 @@ public class IrisWorldDump {
|
|||||||
private ExecutorService executor;
|
private ExecutorService executor;
|
||||||
private ScheduledExecutorService scheduler;
|
private ScheduledExecutorService scheduler;
|
||||||
private AtomicLong startTime;
|
private AtomicLong startTime;
|
||||||
private mode mode;
|
|
||||||
private File dumps;
|
private File dumps;
|
||||||
private File worldDump;
|
private File worldDump;
|
||||||
private int mcaCacheSize;
|
private int mcaCacheSize;
|
||||||
@@ -49,8 +48,8 @@ public class IrisWorldDump {
|
|||||||
private File blocks;
|
private File blocks;
|
||||||
private File structures;
|
private File structures;
|
||||||
|
|
||||||
public IrisWorldDump(World world, VolmitSender sender, mode mode) {
|
public IrisWorldDump(World world, VolmitSender sender) {
|
||||||
sender.sendMessage("Initializing IrisWorldDump...");
|
sender.sendMessage("Building IrisWorldDump...");
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.MCADirectory = new File(world.getWorldFolder(), "region");
|
this.MCADirectory = new File(world.getWorldFolder(), "region");
|
||||||
@@ -60,8 +59,6 @@ public class IrisWorldDump {
|
|||||||
this.mcaCacheSize = IrisSettings.get().getWorldDump().mcaCacheSize;
|
this.mcaCacheSize = IrisSettings.get().getWorldDump().mcaCacheSize;
|
||||||
this.regionsProcessed = new AtomicInteger(0);
|
this.regionsProcessed = new AtomicInteger(0);
|
||||||
this.chunksProcessed = new AtomicInteger(0);
|
this.chunksProcessed = new AtomicInteger(0);
|
||||||
this.totalToProcess = new AtomicInteger(0);
|
|
||||||
this.totalMaxChunks = new AtomicInteger(totalMCAFiles.get() * 1024);
|
|
||||||
this.chunksPerSecond = new RollingSequence(10);
|
this.chunksPerSecond = new RollingSequence(10);
|
||||||
this.temp = new File(worldDump, "temp");
|
this.temp = new File(worldDump, "temp");
|
||||||
this.executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() - 1);
|
this.executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() - 1);
|
||||||
@@ -69,48 +66,29 @@ public class IrisWorldDump {
|
|||||||
this.startTime = new AtomicLong();
|
this.startTime = new AtomicLong();
|
||||||
this.storage = new KMap<>();
|
this.storage = new KMap<>();
|
||||||
this.airStorage = new AtomicLong(0);
|
this.airStorage = new AtomicLong(0);
|
||||||
this.blocks = new File(worldDump, "blocks");
|
|
||||||
this.structures = new File(worldDump, "structures");
|
|
||||||
initialize();
|
|
||||||
try {
|
try {
|
||||||
this.engine = IrisToolbelt.access(world).getEngine();
|
this.engine = IrisToolbelt.access(world).getEngine();
|
||||||
this.IrisWorld = true;
|
this.IrisWorld = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
this.IrisWorld = false;
|
this.IrisWorld = false;
|
||||||
}
|
}
|
||||||
|
CompletableFuture<Void> setupFuture = CompletableFuture.runAsync(this::initialize, executor);
|
||||||
|
setupFuture.join();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
if (!dumps.exists()) {
|
try {
|
||||||
if (!dumps.mkdirs()) {
|
this.blocks = new File(worldDump, "blocks");
|
||||||
System.err.println("Failed to create dump directory.");
|
this.structures = new File(worldDump, "structures");
|
||||||
return;
|
if (worldDump.exists()) {
|
||||||
}
|
deleteFileOrDirectory(worldDump);
|
||||||
}
|
|
||||||
|
|
||||||
if (worldDump.exists() && !worldDump.delete()) {
|
|
||||||
System.err.println("Failed to delete existing world dump directory.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!worldDump.mkdir()) {
|
|
||||||
System.err.println("Failed to create world dump directory.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!blocks.mkdir()) {
|
|
||||||
System.err.println("Failed to create blocks directory.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!structures.mkdir()) {
|
|
||||||
System.err.println("Failed to create structures directory.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (File mcaFile : MCADirectory.listFiles()) {
|
|
||||||
if (mcaFile.getName().endsWith(".mca")) {
|
|
||||||
totalToProcess.getAndIncrement();
|
|
||||||
}
|
}
|
||||||
|
this.totalMaxChunks = new AtomicInteger(getChunkCount().get());
|
||||||
|
this.totalMCAFiles = new AtomicInteger(getMCACount().get());
|
||||||
|
sender.sendMessage("Finished Building!");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,28 +97,6 @@ public class IrisWorldDump {
|
|||||||
updater();
|
updater();
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum mode {
|
|
||||||
RAW {
|
|
||||||
@Override
|
|
||||||
public void methodDump() {
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
DISK {
|
|
||||||
@Override
|
|
||||||
public void methodDump() {
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
PACKED {
|
|
||||||
@Override
|
|
||||||
public void methodDump() {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
public abstract void methodDump();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updater() {
|
private void updater() {
|
||||||
startTime.set(System.currentTimeMillis());
|
startTime.set(System.currentTimeMillis());
|
||||||
scheduler.scheduleAtFixedRate(() -> {
|
scheduler.scheduleAtFixedRate(() -> {
|
||||||
@@ -156,10 +112,9 @@ public class IrisWorldDump {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void dump() {
|
private void dump() {
|
||||||
Iris.info("Starting the dump process.");
|
Iris.info("Starting the dump process.");
|
||||||
int threads = Runtime.getRuntime().availableProcessors();
|
CompletableFuture<Void> dump = CompletableFuture.runAsync(() -> {
|
||||||
AtomicInteger f = new AtomicInteger();
|
AtomicInteger f = new AtomicInteger();
|
||||||
for (File mcaFile : MCADirectory.listFiles()) {
|
for (File mcaFile : MCADirectory.listFiles()) {
|
||||||
if (mcaFile.getName().endsWith(".mca")) {
|
if (mcaFile.getName().endsWith(".mca")) {
|
||||||
@@ -174,6 +129,62 @@ public class IrisWorldDump {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}).thenRun(() -> {
|
||||||
|
try {
|
||||||
|
executor.shutdown();
|
||||||
|
executor.awaitTermination(Integer.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
dump.join();
|
||||||
|
Iris.info("Dump process completed.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Iris.error("An error occurred during the dump process: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private AtomicInteger getChunkCount() {
|
||||||
|
AtomicInteger count = new AtomicInteger();
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
for (File mcaFile : MCADirectory.listFiles()) {
|
||||||
|
executor.submit(() -> {
|
||||||
|
try {
|
||||||
|
if (mcaFile.getName().endsWith(".mca")) {
|
||||||
|
MCAFile mca = MCAUtil.read(mcaFile);
|
||||||
|
for (int x = 0; x < 32; x++) {
|
||||||
|
for (int z = 0; z < 32; z++) {
|
||||||
|
if (mca.hasChunk(x, z)) count.getAndIncrement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).thenRunAsync(() -> {
|
||||||
|
try {
|
||||||
|
executor.shutdown();
|
||||||
|
executor.awaitTermination(4, TimeUnit.SECONDS);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AtomicInteger getMCACount() {
|
||||||
|
AtomicInteger i = new AtomicInteger(0);
|
||||||
|
for (File mca : MCADirectory.listFiles()) {
|
||||||
|
if (mca.toPath().endsWith(".mca")) {
|
||||||
|
i.getAndIncrement();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processMCARegion(MCAFile mca) {
|
private void processMCARegion(MCAFile mca) {
|
||||||
@@ -228,4 +239,17 @@ public class IrisWorldDump {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void deleteFileOrDirectory(File file) throws IOException {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
File[] entries = file.listFiles();
|
||||||
|
if (entries != null) {
|
||||||
|
for (File entry : entries) {
|
||||||
|
deleteFileOrDirectory(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!file.delete()) {
|
||||||
|
throw new IOException("Failed to delete " + file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user