mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-03 00:17:15 +00:00
add progressbar to object saving
This commit is contained in:
parent
0c92c20c65
commit
cc584ba377
@ -36,6 +36,7 @@ import com.volmit.iris.util.plugin.VolmitSender;
|
|||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import com.volmit.iris.util.scheduling.S;
|
import com.volmit.iris.util.scheduling.S;
|
||||||
import com.volmit.iris.util.scheduling.SR;
|
import com.volmit.iris.util.scheduling.SR;
|
||||||
|
import com.volmit.iris.util.scheduling.jobs.Job;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@ -55,11 +56,12 @@ import java.awt.Color;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class WandSVC implements IrisService {
|
public class WandSVC implements IrisService {
|
||||||
private static final Particle CRIT_MAGIC = E.getOrDefault(Particle.class, "CRIT_MAGIC", "CRIT");
|
private static final Particle CRIT_MAGIC = E.getOrDefault(Particle.class, "CRIT_MAGIC", "CRIT");
|
||||||
private static final Particle REDSTONE = E.getOrDefault(Particle.class, "REDSTONE", "DUST");
|
private static final Particle REDSTONE = E.getOrDefault(Particle.class, "REDSTONE", "DUST");
|
||||||
private static final int BLOCKS_PER_TICK = Integer.parseInt(System.getProperty("iris.blocks_per_tick", "1000"));
|
private static final int MS_PER_TICK = Integer.parseInt(System.getProperty("iris.ms_per_tick", "30"));
|
||||||
|
|
||||||
private static ItemStack dust;
|
private static ItemStack dust;
|
||||||
private static ItemStack wand;
|
private static ItemStack wand;
|
||||||
@ -85,27 +87,63 @@ public class WandSVC implements IrisService {
|
|||||||
IrisObject s = new IrisObject(c.getSizeX(), c.getSizeY(), c.getSizeZ());
|
IrisObject s = new IrisObject(c.getSizeX(), c.getSizeY(), c.getSizeZ());
|
||||||
|
|
||||||
var it = c.iterator();
|
var it = c.iterator();
|
||||||
|
|
||||||
|
int total = c.getSizeX() * c.getSizeY() * c.getSizeZ();
|
||||||
|
AtomicInteger i = new AtomicInteger(0);
|
||||||
var latch = new CountDownLatch(1);
|
var latch = new CountDownLatch(1);
|
||||||
|
new Job() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Scanning Selection";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
new SR() {
|
new SR() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (int i = 0; i < BLOCKS_PER_TICK; i++) {
|
var time = M.ms() + MS_PER_TICK;
|
||||||
|
while (time > M.ms()) {
|
||||||
if (!it.hasNext()) {
|
if (!it.hasNext()) {
|
||||||
cancel();
|
cancel();
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
var b = it.next();
|
var b = it.next();
|
||||||
if (b.getType().equals(Material.AIR))
|
if (b.getType().equals(Material.AIR))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
BlockVector bv = b.getLocation().subtract(c.getLowerNE().toVector()).toVector().toBlockVector();
|
BlockVector bv = b.getLocation().subtract(c.getLowerNE().toVector()).toVector().toBlockVector();
|
||||||
s.setUnsigned(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), b);
|
s.setUnsigned(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), b);
|
||||||
|
} finally {
|
||||||
|
i.incrementAndGet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
try {
|
||||||
latch.await();
|
latch.await();
|
||||||
|
} catch (InterruptedException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void completeWork() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalWork() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWorkCompleted() {
|
||||||
|
return i.get();
|
||||||
|
}
|
||||||
|
}.execute(new VolmitSender(p), true, () -> {});
|
||||||
|
try {
|
||||||
|
latch.await();
|
||||||
|
} catch (InterruptedException ignored) {}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user