From ea422b5561721562ae0273778c2f4bc99742f1cb Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 17 Jan 2019 13:19:24 +0000 Subject: [PATCH] Fix NPE on world initialise --- .../plotsquared/plot/generator/HybridGen.java | 12 ++++++++++-- .../object/worlds/SingleWorldGenerator.java | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java index d24fef465..886dd1125 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java @@ -42,9 +42,17 @@ public class HybridGen extends IndependentPlotGenerator { for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { for (int y = 1; y < hpw.PLOT_HEIGHT; y++) { - blockBuckets[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = hpw.MAIN_BLOCK; + int layer = y >> 4; + if (blockBuckets[layer] == null) { + blockBuckets[layer] = new BlockBucket[4096]; + } + blockBuckets[layer][((y & 0xF) << 8) | (z << 4) | x] = hpw.MAIN_BLOCK; } - blockBuckets[hpw.PLOT_HEIGHT >> 4][((hpw.PLOT_HEIGHT & 0xF) << 8) | (z << 4) | x] = + int layer = hpw.PLOT_HEIGHT >> 4; + if (blockBuckets[layer] == null) { + blockBuckets[layer] = new BlockBucket[4096]; + } + blockBuckets[layer][((hpw.PLOT_HEIGHT & 0xF) << 8) | (z << 4) | x] = hpw.MAIN_BLOCK; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java index 11315266c..ba498f971 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java @@ -26,7 +26,11 @@ public class SingleWorldGenerator extends IndependentPlotGenerator { for (int x = bedrock1.getX(); x <= bedrock2.getX(); x++) { for (int z = bedrock1.getZ(); z <= bedrock2.getZ(); z++) { for (int y = bedrock1.getY(); y <= bedrock2.getY(); y++) { - blockBuckets[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = + int layer = y >> 4; + if (blockBuckets[layer] == null) { + blockBuckets[layer] = new BlockBucket[4096]; + } + blockBuckets[layer][((y & 0xF) << 8) | (z << 4) | x] = BlockBucket.withSingle(PlotBlock.get("bedrock")); } } @@ -34,7 +38,11 @@ public class SingleWorldGenerator extends IndependentPlotGenerator { for (int x = dirt1.getX(); x <= dirt2.getX(); x++) { for (int z = dirt1.getZ(); z <= dirt2.getZ(); z++) { for (int y = dirt1.getY(); y <= dirt2.getY(); y++) { - blockBuckets[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = + int layer = y >> 4; + if (blockBuckets[layer] == null) { + blockBuckets[layer] = new BlockBucket[4096]; + } + blockBuckets[layer][((y & 0xF) << 8) | (z << 4) | x] = BlockBucket.withSingle(PlotBlock.get("dirt")); } } @@ -42,7 +50,11 @@ public class SingleWorldGenerator extends IndependentPlotGenerator { for (int x = grass1.getX(); x <= grass2.getX(); x++) { for (int z = grass1.getZ(); z <= grass2.getZ(); z++) { for (int y = grass1.getY(); y <= grass2.getY(); y++) { - blockBuckets[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = + int layer = y >> 4; + if (blockBuckets[layer] == null) { + blockBuckets[layer] = new BlockBucket[4096]; + } + blockBuckets[layer][((y & 0xF) << 8) | (z << 4) | x] = BlockBucket.withSingle(PlotBlock.get("grass_block")); } }