public static List<Thread> ts = new ArrayList<>();
public static void build(Location loc, Chest chest, String fileName) {
File file = new File("plugins/WorldEdit/schematics/" + fileName + ".schematic");
SchematicFormat format = SchematicFormat.getFormat(file);
try {
CuboidClipboard cc = format.load(file);
int rotation = (getD(chest.getFacing()) - getD(cc.getOffset())) * 90;
if (rotation < 0) rotation += 360;
cc.rotate2D(rotation);
Location origin = loc.clone().add(
cc.getOffset().getBlockX(),
cc.getOffset().getBlockY(),
cc.getOffset().getBlockZ());
Thread t = new Thread() {
public void run() {
for (int y = 0, ly = cc.getHeight(); y < ly; y++) {
for (int x = 0, lx = cc.getWidth(); x < lx; x++) {
for (int z = 0, lz = cc.getLength(); z < lz; z++) {
BaseBlock b = cc.getBlock(new Vector(x, y, z));
Location l = origin.clone().add(x, y, z);
new BukkitRunnable() {
@Override
public void run() {
l.getBlock().setTypeIdAndData(b.getType(), (byte) b.getData(), false);
}
}.runTaskLater(Main.get(), 0L);
if (b.getType() != 0) {
origin.getWorld().playEffect(l, Effect.STEP_SOUND, 1);
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
}
};
t.start();
ts.add(t);
} catch (DataException | IOException e) {
e.printStackTrace();
}