Fix crashing on chunk load (chunks are still empty though)

This commit is contained in:
dordsor21 2018-12-20 12:23:49 +00:00
parent 568b4c8e85
commit b35221bf4f
2 changed files with 14 additions and 12 deletions

View file

@ -50,8 +50,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null); PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
ChunkWrapper wrap = new ChunkWrapper(area.worldname, c.getX(), c.getZ()); ChunkWrapper wrap = new ChunkWrapper(area.worldname, c.getX(), c.getZ());
ScopedLocalBlockQueue chunk = queue.getForChunk(wrap.x, wrap.z); ScopedLocalBlockQueue chunk = queue.getForChunk(wrap.x, wrap.z);
if (BukkitPlotGenerator.this.plotGenerator if (BukkitPlotGenerator.this.plotGenerator.populateChunk(chunk, area)) {
.populateChunk(chunk, area)) {
queue.flush(); queue.flush();
} }
} }
@ -218,15 +217,16 @@ public class BukkitPlotGenerator extends ChunkGenerator
grid.setBiome(x, z, Biome.PLAINS); grid.setBiome(x, z, Biome.PLAINS);
} }
} }
return result.cd; return result.getCd();
} }
} }
// Set the chunk location // Set the chunk location
result.setChunk(new ChunkWrapper(world.getName(), cx, cz)); result.setChunk(new ChunkWrapper(world.getName(), cx, cz));
// Set the result data // Set the result data
result.cd = createChunkData(world); result.setCd(createChunkData(world));
result.grid = grid; result.grid = grid;
result.result = generateExtBlockSections(world, random, cx, cz, grid); result.result = generateExtBlockSections(world, random, cx, cz, grid);
// Catch any exceptions (as exceptions usually thrown) // Catch any exceptions (as exceptions usually thrown)
try { try {
// Fill the result data if necessary // Fill the result data if necessary
@ -239,7 +239,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
e.printStackTrace(); e.printStackTrace();
} }
// Return the result data // Return the result data
return result.cd; return result.getCd();
} }
public void generate(World world, ScopedLocalBlockQueue result) { public void generate(World world, ScopedLocalBlockQueue result) {
@ -272,11 +272,11 @@ public class BukkitPlotGenerator extends ChunkGenerator
// Set the result data // Set the result data
result.result = new PlotBlock[16][]; result.result = new PlotBlock[16][];
result.grid = grid; result.grid = grid;
result.cd = null;
// Catch any exceptions (as exceptions usually thrown) // Catch any exceptions (as exceptions usually thrown)
try { try {
if (this.platformGenerator != this) { if (this.platformGenerator != this) {
final ChunkData chunkData = this.platformGenerator.generateChunkData(world, r, cx, cz, grid); final ChunkData chunkData =
this.platformGenerator.generateChunkData(world, r, cx, cz, grid);
final PlotBlock[][] blocks = new PlotBlock[world.getMaxHeight() / 16][]; final PlotBlock[][] blocks = new PlotBlock[world.getMaxHeight() / 16][];
// section ID = Y >> 4 // section ID = Y >> 4
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
@ -285,7 +285,8 @@ public class BukkitPlotGenerator extends ChunkGenerator
if (blocks[y >> 4] == null) { if (blocks[y >> 4] == null) {
blocks[y >> 4] = new PlotBlock[4096]; blocks[y >> 4] = new PlotBlock[4096];
} }
blocks[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = PlotBlock.get(chunkData.getType(x, y, z)); blocks[y >> 4][((y & 0xF) << 8) | (z << 4) | x] =
PlotBlock.get(chunkData.getType(x, y, z));
} }
} }
} }

View file

@ -6,6 +6,8 @@ import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
@ -19,13 +21,12 @@ public class GenChunk extends ScopedLocalBlockQueue {
public final Biome[] biomes; public final Biome[] biomes;
public PlotBlock[][] result; public PlotBlock[][] result;
public ChunkData cd;
public BiomeGrid grid; public BiomeGrid grid;
public Chunk chunk; public Chunk chunk;
public String world; public String world;
public int cx; public int cx;
public int cz; public int cz;
@Getter @Setter private ChunkData cd = null;
public GenChunk(Chunk chunk, ChunkWrapper wrap) { public GenChunk(Chunk chunk, ChunkWrapper wrap) {
super(null, new Location(null, 0, 0, 0), new Location(null, 15, 255, 15)); super(null, new Location(null, 0, 0, 0), new Location(null, 15, 255, 15));
@ -66,8 +67,8 @@ public class GenChunk extends ScopedLocalBlockQueue {
} }
@Override public void setCuboid(Location pos1, Location pos2, PlotBlock block) { @Override public void setCuboid(Location pos1, Location pos2, PlotBlock block) {
if (result != null && pos1.getX() == 0 && pos1.getZ() == 0 if (result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15
&& pos2.getX() == 15 && pos2.getZ() == 15) { && pos2.getZ() == 15) {
for (int y = pos1.getY(); y <= pos2.getY(); y++) { for (int y = pos1.getY(); y <= pos2.getY(); y++) {
int layer = y >> 4; int layer = y >> 4;
PlotBlock[] data = result[layer]; PlotBlock[] data = result[layer];