- Some minor cleanup
 - Test for null id, not for null PlotBlock
 - Small fixes to schematic saving (still broken)
This commit is contained in:
dordsor21
2018-12-20 23:33:24 +00:00
parent 341e386df8
commit 90682e9f8b
8 changed files with 187 additions and 213 deletions

View File

@ -124,7 +124,6 @@ public class BukkitChunkManager extends ChunkManager {
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
final World newWorld = Bukkit.getWorld(newPos.getWorld());
final String newWorldName = newWorld.getName();
List<ChunkLoc> chunks = new ArrayList<>();
final ContentMap map = new ContentMap();
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(newWorldName, false);
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
@ -144,27 +143,23 @@ public class BukkitChunkManager extends ChunkManager {
}
}
}
}, new Runnable() {
@Override public void run() {
for (Entry<PlotLoc, PlotBlock[]> entry : map.allBlocks.entrySet()) {
PlotLoc loc = entry.getKey();
PlotBlock[] blocks = entry.getValue();
for (int y = 0; y < blocks.length; y++) {
}, () -> {
for (Entry<PlotLoc, PlotBlock[]> entry : map.allBlocks.entrySet()) {
PlotLoc loc = entry.getKey();
PlotBlock[] blocks = entry.getValue();
for (int y = 0; y < blocks.length; y++) {
if (blocks[y] != null) {
PlotBlock block = blocks[y];
if (block != null) {
queue.setBlock(loc.x, y, loc.z, block);
}
queue.setBlock(loc.x, y, loc.z, block);
}
}
queue.enqueue();
GlobalBlockQueue.IMP.addTask(new Runnable() {
@Override public void run() {
map.restoreBlocks(newWorld, 0, 0);
map.restoreEntities(newWorld, relX, relZ);
TaskManager.runTask(whenDone);
}
});
}
queue.enqueue();
GlobalBlockQueue.IMP.addTask(() -> {
map.restoreBlocks(newWorld, 0, 0);
map.restoreEntities(newWorld, relX, relZ);
TaskManager.runTask(whenDone);
});
}, 5);
return true;
}
@ -211,11 +206,8 @@ public class BukkitChunkManager extends ChunkManager {
RegionWrapper currentPlotClear =
new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
AugmentedUtils.bypass(ignoreAugment, new Runnable() {
@Override public void run() {
queue.regenChunkSafe(chunk.x, chunk.z);
}
});
AugmentedUtils.bypass(ignoreAugment,
() -> queue.regenChunkSafe(chunk.x, chunk.z));
continue;
}
boolean checkX1 = false;
@ -278,43 +270,39 @@ public class BukkitChunkManager extends ChunkManager {
map.saveRegion(worldObj, xxt2, xxt, zzt2, zzt); //
}
map.saveEntitiesOut(chunkObj, currentPlotClear);
AugmentedUtils.bypass(ignoreAugment, new Runnable() {
@Override public void run() {
setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
@Override public void run(ScopedLocalBlockQueue value) {
com.github.intellectualsites.plotsquared.plot.object.Location
min = value.getMin();
int bx = min.getX();
int bz = min.getZ();
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
PlotLoc loc = new PlotLoc(bx + x, bz + z);
PlotBlock[] ids = map.allBlocks.get(loc);
if (ids != null) {
for (int y = 0;
y < Math.min(128, ids.length); y++) {
PlotBlock id = ids[y];
if (id != null) {
value.setBlock(x, y, z, id);
} else {
value.setBlock(x, y, z,
PlotBlock.get("air"));
}
}
for (int y = Math.min(128, ids.length);
y < ids.length; y++) {
PlotBlock id = ids[y];
if (id != null) {
value.setBlock(x, y, z, id);
}
}
AugmentedUtils.bypass(ignoreAugment, () -> setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
@Override public void run(ScopedLocalBlockQueue value) {
com.github.intellectualsites.plotsquared.plot.object.Location
min = value.getMin();
int bx = min.getX();
int bz = min.getZ();
for (int x1 = 0; x1 < 16; x1++) {
for (int z1 = 0; z1 < 16; z1++) {
PlotLoc loc = new PlotLoc(bx + x1, bz + z1);
PlotBlock[] ids = map.allBlocks.get(loc);
if (ids != null) {
for (int y = 0;
y < Math.min(128, ids.length); y++) {
PlotBlock id = ids[y];
if (id != null) {
value.setBlock(x1, y, z1, id);
} else {
value.setBlock(x1, y, z1,
PlotBlock.get("air"));
}
}
for (int y = Math.min(128, ids.length);
y < ids.length; y++) {
PlotBlock id = ids[y];
if (id != null) {
value.setBlock(x1, y, z1, id);
}
}
}
}
}, world, chunk);
}
}
});
}, world, chunk));
map.restoreBlocks(worldObj, 0, 0);
map.restoreEntities(worldObj, 0, 0);
}
@ -359,11 +347,8 @@ public class BukkitChunkManager extends ChunkManager {
public void unloadChunk(final String world, final ChunkLoc loc, final boolean save,
final boolean safe) {
if (!PlotSquared.get().isMainThread(Thread.currentThread())) {
TaskManager.runTask(new Runnable() {
@SuppressWarnings("deprecation") @Override public void run() {
BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe);
}
});
TaskManager.runTask(
() -> BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe));
} else {
BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe);
}

View File

@ -33,7 +33,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
// Main positions
Location[] corners = MainUtil.getCorners(world, regions);
final Location bot = corners[0];
Location top = corners[1];
final Location top = corners[1];
CuboidRegion cuboidRegion =
new CuboidRegion(BukkitUtil.IMP.getWeWorld(world), bot.getBlockVector3(),
@ -59,7 +59,6 @@ public class BukkitSchematicHandler extends SchematicHandler {
// The Sponge format Offset refers to the 'min' points location in the world. That's our 'Origin'
schematic.put("Offset", new IntArrayTag(new int[] {0, 0, 0,}));
final int[] paletteMax = {0};
Map<String, Integer> palette = new HashMap<>();
List<CompoundTag> tileEntities = new ArrayList<>();
@ -69,24 +68,20 @@ public class BukkitSchematicHandler extends SchematicHandler {
TaskManager.runTask(new Runnable() {
@Override public void run() {
if (queue.isEmpty()) {
TaskManager.runTaskAsync(new Runnable() {
@Override public void run() {
schematic.put("PaletteMax", new IntTag(paletteMax[0]));
TaskManager.runTaskAsync(() -> {
schematic.put("PaletteMax", new IntTag(palette.size()));
Map<String, Tag> paletteTag = new HashMap<>();
palette.forEach(
(key, value) -> paletteTag.put(key, new IntTag(value)));
Map<String, Tag> paletteTag = new HashMap<>();
palette.forEach(
(key, value) -> paletteTag.put(key, new IntTag(value)));
schematic.put("Palette", new CompoundTag(paletteTag));
schematic
.put("BlockData", new ByteArrayTag(buffer.toByteArray()));
schematic.put("TileEntities",
new ListTag(CompoundTag.class, tileEntities));
whenDone.value = new CompoundTag(schematic);
TaskManager.runTask(whenDone);
System.gc();
System.gc();
}
schematic.put("Palette", new CompoundTag(paletteTag));
schematic.put("BlockData", new ByteArrayTag(buffer.toByteArray()));
schematic.put("TileEntities",
new ListTag(CompoundTag.class, tileEntities));
whenDone.value = new CompoundTag(schematic);
TaskManager.runTask(whenDone);
System.gc();
});
return;
}
@ -147,13 +142,10 @@ public class BukkitSchematicHandler extends SchematicHandler {
}
for (int y = sy; y <= Math.min(255, ey); y++) {
int ry = y - sy;
int i1 = ry * width * length;
for (int z = zzb; z <= zzt; z++) {
int rz = z - bz;
int i2 = i1 + rz * width;
for (int x = xxb; x <= xxt; x++) {
int rx = x - bx;
int index = i2 + rx;
BlockVector3 point = BlockVector3.at(x, y, z);
BaseBlock block =
cuboidRegion.getWorld().getFullBlock(point);
@ -164,9 +156,8 @@ public class BukkitSchematicHandler extends SchematicHandler {
values
.put(entry.getKey(), entry.getValue());
}
values.remove(
"id"); // Remove 'id' if it exists. We want 'Id'
// Remove 'id' if it exists. We want 'Id'
values.remove("id");
// Positions are kept in NBT, we don't want that.
values.remove("x");
@ -176,7 +167,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
values
.put("Id", new StringTag(block.getNbtId()));
values.put("Pos",
new IntArrayTag(new int[] {x, y, z}));
new IntArrayTag(new int[] {rx, ry, rz}));
tileEntities.add(new CompoundTag(values));
}
@ -186,9 +177,8 @@ public class BukkitSchematicHandler extends SchematicHandler {
if (palette.containsKey(blockKey)) {
blockId = palette.get(blockKey);
} else {
blockId = paletteMax[0];
palette.put(blockKey, blockId);
paletteMax[0]++;
blockId = palette.size();
palette.put(blockKey, palette.size());
}
while ((blockId & -128) != 0) {

View File

@ -87,8 +87,8 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
PlotBlock[] blocksLayer = (PlotBlock[]) lc.blocks[layer];
if (blocksLayer != null) {
for (int j = 0; j < blocksLayer.length; j++) {
PlotBlock block = blocksLayer[j];
if (block != null) {
if (blocksLayer[j] != null) {
PlotBlock block = blocksLayer[j];
int x = MainUtil.x_loc[layer][j];
int y = MainUtil.y_loc[layer][j];
int z = MainUtil.z_loc[layer][j];