mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-01 15:36:45 +00:00
add progressbar to object writing
This commit is contained in:
parent
cc584ba377
commit
18e57e4097
@ -381,7 +381,7 @@ public class CommandObject implements DecreeExecutor {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
o.write(file);
|
||||
o.write(file, sender());
|
||||
} catch (IOException e) {
|
||||
sender().sendMessage(C.RED + "Failed to save object because of an IOException: " + e.getMessage());
|
||||
Iris.reportError(e);
|
||||
|
@ -43,6 +43,7 @@ import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import com.volmit.iris.util.scheduling.IrisLock;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import com.volmit.iris.util.scheduling.jobs.Job;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
@ -63,7 +64,9 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@ -384,6 +387,88 @@ public class IrisObject extends IrisRegistrant {
|
||||
}
|
||||
}
|
||||
|
||||
public void write(OutputStream o, VolmitSender sender) throws IOException {
|
||||
AtomicReference<IOException> ref = new AtomicReference<>();
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
new Job() {
|
||||
private int total = getBlocks().size() * 3 + getStates().size();
|
||||
private int c = 0;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Saving Object";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
DataOutputStream dos = new DataOutputStream(o);
|
||||
dos.writeInt(w);
|
||||
dos.writeInt(h);
|
||||
dos.writeInt(d);
|
||||
dos.writeUTF("Iris V2 IOB;");
|
||||
|
||||
KList<String> palette = new KList<>();
|
||||
|
||||
for (BlockData i : getBlocks().values()) {
|
||||
palette.addIfMissing(i.getAsString());
|
||||
++c;
|
||||
}
|
||||
total -= getBlocks().size() - palette.size();
|
||||
|
||||
dos.writeShort(palette.size());
|
||||
|
||||
for (String i : palette) {
|
||||
dos.writeUTF(i);
|
||||
++c;
|
||||
}
|
||||
|
||||
dos.writeInt(getBlocks().size());
|
||||
|
||||
for (BlockVector i : getBlocks().keySet()) {
|
||||
dos.writeShort(i.getBlockX());
|
||||
dos.writeShort(i.getBlockY());
|
||||
dos.writeShort(i.getBlockZ());
|
||||
dos.writeShort(palette.indexOf(getBlocks().get(i).getAsString()));
|
||||
++c;
|
||||
}
|
||||
|
||||
dos.writeInt(getStates().size());
|
||||
for (BlockVector i : getStates().keySet()) {
|
||||
dos.writeShort(i.getBlockX());
|
||||
dos.writeShort(i.getBlockY());
|
||||
dos.writeShort(i.getBlockZ());
|
||||
getStates().get(i).toBinary(dos);
|
||||
++c;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ref.set(e);
|
||||
} finally {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeWork() {}
|
||||
|
||||
@Override
|
||||
public int getTotalWork() {
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWorkCompleted() {
|
||||
return c;
|
||||
}
|
||||
}.execute(sender, true, () -> {});
|
||||
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException ignored) {}
|
||||
if (ref.get() != null)
|
||||
throw ref.get();
|
||||
}
|
||||
|
||||
public void read(File file) throws IOException {
|
||||
var fin = new BufferedInputStream(new FileInputStream(file));
|
||||
try {
|
||||
@ -408,6 +493,16 @@ public class IrisObject extends IrisRegistrant {
|
||||
out.close();
|
||||
}
|
||||
|
||||
public void write(File file, VolmitSender sender) throws IOException {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
write(out, sender);
|
||||
out.close();
|
||||
}
|
||||
|
||||
public void shrinkwrap() {
|
||||
BlockVector min = new BlockVector();
|
||||
BlockVector max = new BlockVector();
|
||||
|
Loading…
x
Reference in New Issue
Block a user