From 3d47d7e73fad648ca50cb774af9da738d1609c8e Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 20 Mar 2020 12:05:13 +0000 Subject: [PATCH] Use worldedit to regenerate chunks. (#2708) * Use worldedit to regeneration chunks. It's very slow, but it works. * Use the AutoClose-ness of EditSession --- .../bukkit/util/BukkitChunkManager.java | 7 +++---- .../bukkit/util/block/BukkitLocalQueue.java | 19 ++++++++++++++++++- .../plot/generator/HybridPlotManager.java | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java index 4fb6f5db4..fe801a15f 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java @@ -290,10 +290,9 @@ public class BukkitChunkManager extends ChunkManager { continue; } final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); - if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z - && PlotSquared.imp().getServerVersion()[1] == 13) { - AugmentedUtils - .bypass(ignoreAugment, () -> queue.regenChunkSafe(chunk.getX(), chunk.getZ())); + if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) { + AugmentedUtils.bypass(ignoreAugment, + () -> queue.regenChunkSafe(chunk.getX(), chunk.getZ())); continue; } boolean checkX1 = false; 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 82f5c4282..2af0bf69b 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 @@ -7,7 +7,13 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.function.operation.Operations; +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; @@ -64,7 +70,18 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { @Override public final void regenChunk(int x, int z) { World worldObj = Bukkit.getWorld(getWorld()); if (worldObj != null) { - worldObj.regenerateChunk(x, z); + try { + worldObj.regenerateChunk(x, z); + } catch (UnsupportedOperationException e) { + com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(worldObj); + try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory() + .getEditSession(world, -1);) { + CuboidRegion region = + new CuboidRegion(world, BlockVector3.at((x << 4), 0, (z << 4)), + BlockVector3.at((x << 4) + 15, 255, (z << 4) + 15)); + world.regenerate(region, editSession); + } + } } else { PlotSquared.debug("Error Regenerating Chunk"); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java index 457858e08..d3e4fbe46 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java @@ -187,7 +187,7 @@ public class HybridPlotManager extends ClassicPlotManager { ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override public void run(int[] value) { // If the chunk isn't near the edge and it isn't an augmented world we can just regen the whole chunk - if (canRegen && (value[6] == 0) && PlotSquared.imp().getServerVersion()[1] == 13) { + if (canRegen && (value[6] == 0)) { queue.regenChunk(value[0], value[1]); return; }