mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-26 18:54:43 +02:00
Optimizations to schematic loading / pasting -> ~10,000,000 bps
The downside is it completely ignores entities and such, so WorldEdit is the way to go if you need precision but don't care for large sizes or speed.
This commit is contained in:
@ -27,6 +27,7 @@ import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
@ -72,7 +73,17 @@ public class Claim extends SubCommand {
|
||||
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
|
||||
}
|
||||
}
|
||||
SchematicHandler.manager.paste(sch, plot2, 0, 0);
|
||||
SchematicHandler.manager.paste(sch, plot2, 0, 0, new RunnableVal<Boolean>() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (value) {
|
||||
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_FAILED);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
PS.get().getPlotManager(world).claimPlot(plotworld, plot);
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
@ -89,69 +90,24 @@ public class SchematicCmd extends SubCommand {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final Schematic schematic = SchematicHandler.manager.getSchematic(file2);
|
||||
if (schematic == null) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
|
||||
SchematicCmd.this.running = false;
|
||||
return;
|
||||
}
|
||||
final int x;
|
||||
final int z;
|
||||
final Plot plot2 = MainUtil.getPlot(loc);
|
||||
final Dimension dem = schematic.getSchematicDimension();
|
||||
final Location bot = MainUtil.getPlotBottomLoc(loc.getWorld(), plot2.id).add(1, 0, 1);
|
||||
final int length2 = MainUtil.getPlotWidth(loc.getWorld(), plot2.id);
|
||||
if ((dem.getX() > length2) || (dem.getZ() > length2)) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", dem.getX(), dem.getZ(), length2));
|
||||
SchematicCmd.this.running = false;
|
||||
return;
|
||||
}
|
||||
if ((dem.getX() != length2) || (dem.getZ() != length2)) {
|
||||
final Location loc = plr.getLocation();
|
||||
x = Math.min(length2 - dem.getX(), loc.getX() - bot.getX());
|
||||
z = Math.min(length2 - dem.getZ(), loc.getZ() - bot.getZ());
|
||||
} else {
|
||||
x = 0;
|
||||
z = 0;
|
||||
}
|
||||
final DataCollection[] b = schematic.getBlockCollection();
|
||||
final int sy = BlockManager.manager.getHeighestBlock(bot);
|
||||
final int WIDTH = schematic.getSchematicDimension().getX();
|
||||
final int LENGTH = schematic.getSchematicDimension().getZ();
|
||||
final Location l1;
|
||||
if (!(schematic.getSchematicDimension().getY() == BukkitUtil.getMaxHeight(loc.getWorld()))) {
|
||||
l1 = bot.add(0, sy - 1, 0);
|
||||
}
|
||||
else {
|
||||
l1 = bot;
|
||||
}
|
||||
final int blen = b.length - 1;
|
||||
SchematicCmd.this.task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean result = false;
|
||||
while (!result) {
|
||||
final int start = SchematicCmd.this.counter * 5000;
|
||||
if (start > blen) {
|
||||
SchematicHandler.manager.pasteStates(schematic, plot, 0, 0);
|
||||
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
||||
SchematicCmd.this.running = false;
|
||||
PS.get().TASK.cancelTask(SchematicCmd.this.task);
|
||||
return;
|
||||
}
|
||||
final int end = Math.min(start + 5000, blen);
|
||||
result = SchematicHandler.manager.pastePart(loc.getWorld(), b, l1, x, z, start, end, WIDTH, LENGTH);
|
||||
SchematicCmd.this.counter++;
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
final Schematic schematic = SchematicHandler.manager.getSchematic(file2);
|
||||
if (schematic == null) {
|
||||
SchematicCmd.this.running = false;
|
||||
MainUtil.sendMessage(plr, "&cAn error occured, see console for more information");
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
|
||||
return;
|
||||
}
|
||||
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() {
|
||||
@Override
|
||||
public void run() {
|
||||
SchematicCmd.this.running = false;
|
||||
if (this.value) {
|
||||
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
||||
}
|
||||
else {
|
||||
sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
Reference in New Issue
Block a user