diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java index 0fc021268..ca6bf6867 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java @@ -518,7 +518,7 @@ public class BukkitUtil extends WorldUtil { } private static void ensureLoaded(final String world, final int x, final int z, final Consumer chunkConsumer) { - PaperLib.getChunkAtAsync(getWorld(world), x << 4, z << 4, true).thenAccept(chunk -> + PaperLib.getChunkAtAsync(getWorld(world), x >> 4, z >> 4, true).thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk)); } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java index b996a5a05..d27dce58d 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java @@ -142,13 +142,17 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { } private Chunk getChunk(final World world, final LocalChunk localChunk) { + Chunk chunk = null; if (this.getChunkObject() != null && this.getChunkObject() instanceof Chunk) { - final Chunk chunk = (Chunk) this.getChunkObject(); - if (chunk.getWorld().equals(world) && chunk.getX() == localChunk.getX() && chunk.getZ() == localChunk.getZ()) { - return chunk; - } + chunk = (Chunk) this.getChunkObject(); } - return world.getChunkAt(localChunk.getX(), localChunk.getZ()); + if (chunk == null) { + chunk = world.getChunkAt(localChunk.getX(), localChunk.getZ()); + } + if (!chunk.isLoaded()) { + chunk.load(true); + } + return chunk; } private void setMaterial(@NonNull final BlockState plotBlock, @NonNull final Block block) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java index a3cda56d0..97d5af43d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java @@ -11,8 +11,11 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import org.jetbrains.annotations.NotNull; @@ -121,6 +124,24 @@ public class AugmentedUtils { return false; } + @Override public boolean setBlock(int x, int y, int z, BaseBlock id) { + try { + if (canPlace[x - blockX][z - blockZ]) { + return super.setBlock(x, y, z, id); + } + } catch (final Exception e) { + PlotSquared.debug(String.format("Failed to set block at: %d;%d;%d (to = %s) with offset %d;%d." + + " Translated to: %d;%d", x, y, z, id, blockX, blockZ, x - blockX, z - blockZ)); + throw e; + } + return false; + } + + @Override public boolean setBlock(int x, int y, int z, Pattern pattern) { + final BlockVector3 blockVector3 = BlockVector3.at(x + blockX, y, z + blockZ); + return this.setBlock(x, y, z, pattern.apply(blockVector3)); + } + @Override public boolean setBiome(int x, int y, BiomeType biome) { return super.setBiome(x, y, biome); } @@ -141,9 +162,8 @@ public class AugmentedUtils { secondaryMask.setChunkObject(chunkObject); secondaryMask.setForceSync(true); - ScopedLocalBlockQueue scoped = new ScopedLocalBlockQueue(secondaryMask, - new Location(area.getWorldName(), blockX, 0, blockZ), - new Location(area.getWorldName(), blockX + 15, 255, blockZ + 15)); + ScopedLocalBlockQueue scoped = new ScopedLocalBlockQueue(secondaryMask, new Location(world, blockX, 0, blockZ), + new Location(world, blockX + 15, 255, blockZ + 15)); generator.generateChunk(scoped, area); generator.populateChunk(scoped, area); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java index 4aa308a95..b0b4e03ea 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java @@ -12,6 +12,11 @@ public class DelegateLocalBlockQueue extends LocalBlockQueue { public DelegateLocalBlockQueue(LocalBlockQueue parent) { super(parent == null ? null : parent.getWorld()); this.parent = parent; + + if (parent != null) { + this.setForceSync(parent.isForceSync()); + this.setChunkObject(parent.getChunkObject()); + } } public LocalBlockQueue getParent() { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java index 6a0e375c5..e349badd1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java @@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotManager; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; +import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -36,8 +37,10 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue { this.dx = maxX - minX; this.dy = maxY - minY; this.dz = maxZ - minZ; - } + this.setForceSync(parent.isForceSync()); + this.setChunkObject(parent.getChunkObject()); + } @Override public boolean setBiome(int x, int z, BiomeType biome) { return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBiome(x + minX, z + minZ, biome); @@ -61,6 +64,11 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue { .setBlock(x + minX, y + minY, z + minZ, id); } + @Override public boolean setBlock(int x, int y, int z, Pattern pattern) { + return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super + .setBlock(x + minX, y + minY, z + minZ, pattern); + } + public Location getMin() { return new Location(getWorld(), minX, minY, minZ); }