mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Fix schematic saving (and improve performance slightly)
This commit is contained in:
parent
2ede77318a
commit
1bf621fb4b
@ -78,7 +78,6 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
new ListTag(CompoundTag.class, tileEntities));
|
new ListTag(CompoundTag.class, tileEntities));
|
||||||
whenDone.value = new CompoundTag(schematic);
|
whenDone.value = new CompoundTag(schematic);
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
System.gc();
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -87,41 +86,40 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
Location pos1 = new Location(world, region.minX, region.minY, region.minZ);
|
Location pos1 = new Location(world, region.minX, region.minY, region.minZ);
|
||||||
Location pos2 = new Location(world, region.maxX, region.maxY, region.maxZ);
|
Location pos2 = new Location(world, region.maxX, region.maxY, region.maxZ);
|
||||||
final int p1x = pos1.getX();
|
final int p1x = pos1.getX();
|
||||||
|
final int sy = pos1.getY();
|
||||||
final int p1z = pos1.getZ();
|
final int p1z = pos1.getZ();
|
||||||
final int p2x = pos2.getX();
|
final int p2x = pos2.getX();
|
||||||
final int p2z = pos2.getZ();
|
final int p2z = pos2.getZ();
|
||||||
final int sy = pos1.getY();
|
|
||||||
final int ey = pos2.getY();
|
final int ey = pos2.getY();
|
||||||
Iterator<Integer> yiter = IntStream.range(sy, ey).iterator();
|
Iterator<Integer> yiter = IntStream.range(sy, ey + 1).iterator();
|
||||||
TaskManager.runTask(new Runnable() {
|
final Runnable yTask = new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
final Runnable yTask = this;
|
|
||||||
long ystart = System.currentTimeMillis();
|
long ystart = System.currentTimeMillis();
|
||||||
while (yiter.hasNext()
|
while (yiter.hasNext()
|
||||||
&& System.currentTimeMillis() - ystart < 20) {
|
&& System.currentTimeMillis() - ystart < 20) {
|
||||||
final int fy = yiter.next();
|
final int y = yiter.next();
|
||||||
Iterator<Integer> ziter = IntStream.range(p1z, p2z).iterator();
|
Iterator<Integer> ziter =
|
||||||
TaskManager.runTask(new Runnable() {
|
IntStream.range(p1z, p2z + 1).iterator();
|
||||||
|
final Runnable zTask = new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
final Runnable zTask = this;
|
|
||||||
long zstart = System.currentTimeMillis();
|
long zstart = System.currentTimeMillis();
|
||||||
Iterator<Integer> xiter =
|
|
||||||
IntStream.range(p1x, p2x).iterator();
|
|
||||||
while (ziter.hasNext()
|
while (ziter.hasNext()
|
||||||
&& System.currentTimeMillis() - zstart < 20) {
|
&& System.currentTimeMillis() - zstart < 20) {
|
||||||
final int fz = ziter.next();
|
final int z = ziter.next();
|
||||||
TaskManager.runTask(new Runnable() {
|
Iterator<Integer> xiter =
|
||||||
|
IntStream.range(p1x, p2x + 1).iterator();
|
||||||
|
final Runnable xTask = new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
long xstart = System.currentTimeMillis();
|
long xstart = System.currentTimeMillis();
|
||||||
|
final int ry = y - sy;
|
||||||
|
final int rz = z - p1z;
|
||||||
while (xiter.hasNext()
|
while (xiter.hasNext()
|
||||||
&& System.currentTimeMillis() - xstart
|
&& System.currentTimeMillis() - xstart
|
||||||
< 20) {
|
< 20) {
|
||||||
final int x = xiter.next();
|
final int x = xiter.next();
|
||||||
int rx = x - p1x;
|
final int rx = x - p1x;
|
||||||
int ry = fy - sy;
|
|
||||||
int rz = fz - p1z;
|
|
||||||
BlockVector3 point =
|
BlockVector3 point =
|
||||||
BlockVector3.at(x, fy, fz);
|
BlockVector3.at(x, y, z);
|
||||||
BaseBlock block =
|
BaseBlock block =
|
||||||
cuboidRegion.getWorld()
|
cuboidRegion.getWorld()
|
||||||
.getFullBlock(point);
|
.getFullBlock(point);
|
||||||
@ -169,28 +167,27 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
buffer.write(blockId);
|
buffer.write(blockId);
|
||||||
}
|
}
|
||||||
if (xiter.hasNext()) {
|
if (xiter.hasNext()) {
|
||||||
TaskManager.runTaskLater(this, 1);
|
this.run();
|
||||||
} else {
|
|
||||||
zTask.run();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
xTask.run();
|
||||||
}
|
}
|
||||||
if (ziter.hasNext()) {
|
if (ziter.hasNext()) {
|
||||||
TaskManager.runTaskLater(zTask, 1);
|
this.run();
|
||||||
} else {
|
|
||||||
yTask.run();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
zTask.run();
|
||||||
}
|
}
|
||||||
if (yiter.hasNext()) {
|
if (yiter.hasNext()) {
|
||||||
TaskManager.runTaskLater(yTask, 1);
|
TaskManager.runTaskLater(this, 1);
|
||||||
} else {
|
} else {
|
||||||
regionTask.run();
|
regionTask.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
yTask.run();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -43,18 +43,17 @@ public class Save extends SubCommand {
|
|||||||
plot.addRunning();
|
plot.addRunning();
|
||||||
SchematicHandler.manager.getCompoundTag(plot, new RunnableVal<CompoundTag>() {
|
SchematicHandler.manager.getCompoundTag(plot, new RunnableVal<CompoundTag>() {
|
||||||
@Override public void run(final CompoundTag value) {
|
@Override public void run(final CompoundTag value) {
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(() -> {
|
||||||
@Override public void run() {
|
|
||||||
String time = (System.currentTimeMillis() / 1000) + "";
|
String time = (System.currentTimeMillis() / 1000) + "";
|
||||||
Location[] corners = plot.getCorners();
|
Location[] corners = plot.getCorners();
|
||||||
corners[0].setY(0);
|
corners[0].setY(0);
|
||||||
corners[1].setY(255);
|
corners[1].setY(255);
|
||||||
int size = (corners[1].getX() - corners[0].getX()) + 1;
|
int size = (corners[1].getX() - corners[0].getX()) + 1;
|
||||||
PlotId id = plot.getId();
|
PlotId id = plot.getId();
|
||||||
String world = plot.getArea().toString().replaceAll(";", "-")
|
String world1 = plot.getArea().toString().replaceAll(";", "-")
|
||||||
.replaceAll("[^A-Za-z0-9]", "");
|
.replaceAll("[^A-Za-z0-9]", "");
|
||||||
final String file =
|
final String file =
|
||||||
time + '_' + world + '_' + id.x + '_' + id.y + '_' + size;
|
time + '_' + world1 + '_' + id.x + '_' + id.y + '_' + size;
|
||||||
UUID uuid = player.getUUID();
|
UUID uuid = player.getUUID();
|
||||||
SchematicHandler.manager.upload(value, uuid, file, new RunnableVal<URL>() {
|
SchematicHandler.manager.upload(value, uuid, file, new RunnableVal<URL>() {
|
||||||
@Override public void run(URL url) {
|
@Override public void run(URL url) {
|
||||||
@ -70,7 +69,6 @@ public class Save extends SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -114,8 +114,7 @@ public class MainUtil {
|
|||||||
whenDone.run();
|
whenDone.run();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(() -> {
|
||||||
@Override public void run() {
|
|
||||||
try {
|
try {
|
||||||
String boundary = Long.toHexString(System.currentTimeMillis());
|
String boundary = Long.toHexString(System.currentTimeMillis());
|
||||||
URLConnection con = new URL(website).openConnection();
|
URLConnection con = new URL(website).openConnection();
|
||||||
@ -151,22 +150,22 @@ public class MainUtil {
|
|||||||
writer.append(CRLF).flush();
|
writer.append(CRLF).flush();
|
||||||
writer.append("--" + boundary + "--").append(CRLF).flush();
|
writer.append("--" + boundary + "--").append(CRLF).flush();
|
||||||
}
|
}
|
||||||
// try (Reader response = new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)) {
|
try (Reader response = new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)) {
|
||||||
// final char[] buffer = new char[256];
|
final char[] buffer = new char[256];
|
||||||
// final StringBuilder result = new StringBuilder();
|
final StringBuilder result = new StringBuilder();
|
||||||
// while (true) {
|
while (true) {
|
||||||
// final int r = response.read(buffer);
|
final int r = response.read(buffer);
|
||||||
// if (r < 0) {
|
if (r < 0) {
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// result.append(buffer, 0, r);
|
result.append(buffer, 0, r);
|
||||||
// }
|
}
|
||||||
// if (!result.toString().startsWith("Success")) {
|
if (!result.toString().startsWith("Success")) {
|
||||||
// PS.debug(result);
|
PlotSquared.debug(result);
|
||||||
// }
|
}
|
||||||
// } catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// e.printStackTrace();
|
e.printStackTrace();
|
||||||
// }
|
}
|
||||||
int responseCode = ((HttpURLConnection) con).getResponseCode();
|
int responseCode = ((HttpURLConnection) con).getResponseCode();
|
||||||
if (responseCode == 200) {
|
if (responseCode == 200) {
|
||||||
whenDone.value = url;
|
whenDone.value = url;
|
||||||
@ -176,7 +175,6 @@ public class MainUtil {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,14 +412,11 @@ public abstract class SchematicHandler {
|
|||||||
}
|
}
|
||||||
MainUtil.upload(uuid, file, "schematic", new RunnableVal<OutputStream>() {
|
MainUtil.upload(uuid, file, "schematic", new RunnableVal<OutputStream>() {
|
||||||
@Override public void run(OutputStream output) {
|
@Override public void run(OutputStream output) {
|
||||||
try {
|
try (NBTOutputStream nos = new NBTOutputStream(
|
||||||
try (GZIPOutputStream gzip = new GZIPOutputStream(output, true)) {
|
new GZIPOutputStream(output, true))) {
|
||||||
try (NBTOutputStream nos = new NBTOutputStream(gzip)) {
|
|
||||||
nos.writeNamedTag("Schematic", tag);
|
nos.writeNamedTag("Schematic", tag);
|
||||||
}
|
} catch (IOException e1) {
|
||||||
}
|
e1.printStackTrace();
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, whenDone);
|
}, whenDone);
|
||||||
@ -476,6 +473,7 @@ public abstract class SchematicHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class UnsupportedFormatException extends Exception {
|
public class UnsupportedFormatException extends Exception {
|
||||||
/**
|
/**
|
||||||
* Throw with a message.
|
* Throw with a message.
|
||||||
|
Loading…
Reference in New Issue
Block a user