From 0609b3d7f63570e5364d9a65b6eaac40e3c07da2 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 19 Jan 2019 16:28:49 +0000 Subject: [PATCH] Safer generation of the BlockBucketChunk --- .../bukkit/util/BukkitHybridUtils.java | 6 +++++- .../plotsquared/plot/object/PlotArea.java | 20 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java index b58edc5e5..b7eebcc04 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java @@ -74,6 +74,10 @@ public class BukkitHybridUtils extends HybridUtils { HybridPlotWorld hpw = (HybridPlotWorld) area; final BlockBucket[][] result = hpw.getBlockBucketChunk(); + if (result == null) { + return; + } + if (hpw.PLOT_SCHEMATIC) { short[] rx = new short[16]; short[] rz = new short[16]; @@ -218,7 +222,7 @@ public class BukkitHybridUtils extends HybridUtils { types.add(now); } } catch (NullPointerException e) { - PlotSquared.log(old.toString()); + PlotSquared.log(old != null ? old.toString() : "old null"); PlotSquared.log(x); PlotSquared.log(y); PlotSquared.log(z); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java index 7c00231c7..48ebb759a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java @@ -14,7 +14,6 @@ import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.area.QuadMap; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; -import lombok.Getter; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -35,7 +34,7 @@ public abstract class PlotArea { private final PlotId min; private final PlotId max; private final IndependentPlotGenerator generator; - @Getter private final BlockBucket[][] blockBucketChunk; + private final BlockBucket[][] blockBucketChunk; public int MAX_PLOT_MEMBERS = 128; public boolean AUTO_MERGE = false; public boolean ALLOW_SIGNS = true; @@ -87,7 +86,7 @@ public abstract class PlotArea { this.max = max; } this.worldhash = worldName.hashCode(); - if (Settings.Enabled_Components.PLOT_EXPIRY) { + if (Settings.Enabled_Components.PLOT_EXPIRY && generator != null) { blockBucketChunk = generator.generateBlockBucketChunk(this); } else { blockBucketChunk = null; @@ -113,6 +112,21 @@ public abstract class PlotArea { return GlobalBlockQueue.IMP.getNewQueue(worldname, autoQueue); } + /** + * Get an array of BlockBuckets corresponding to a chunk of a plot + * + * @return BlockBucket[][] + */ + public BlockBucket[][] getBlockBucketChunk() { + if (blockBucketChunk != null) { + return blockBucketChunk; + } + if (generator != null) { + return generator.generateBlockBucketChunk(this); + } + return null; + } + /** * Returns the region for this PlotArea or a RegionWrapper encompassing * the whole world if none exists.