From 5402516db02e0930dc982f7d158bb94e1d4b8bdb Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 9 Jun 2022 20:50:30 +0100 Subject: [PATCH] Only load world cofigurations if WorldEdit has fully enabled (safe to do) - Fixes #3664 (cherry picked from commit f2e1e99be3b4f1fd5ce00e32ea7773dd4d1855aa) --- .../bukkit/generator/BukkitPlotGenerator.java | 64 +++++++++++-------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java index baaf95dfc..4afec95e1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -112,30 +112,7 @@ public class BukkitPlotGenerator extends ChunkGenerator @Override public @NonNull List getDefaultPopulators(@NonNull World world) { try { - if (!this.loaded) { - String name = world.getName(); - PlotSquared.get().loadWorld(name, this); - final Set areas = this.plotAreaManager.getPlotAreasSet(name); - if (!areas.isEmpty()) { - PlotArea area = areas.iterator().next(); - if (!area.isMobSpawning()) { - if (!area.isSpawnEggs()) { - world.setSpawnFlags(false, false); - } - world.setAmbientSpawnLimit(0); - world.setAnimalSpawnLimit(0); - world.setMonsterSpawnLimit(0); - world.setWaterAnimalSpawnLimit(0); - } else { - world.setSpawnFlags(true, true); - world.setAmbientSpawnLimit(-1); - world.setAnimalSpawnLimit(-1); - world.setMonsterSpawnLimit(-1); - world.setWaterAnimalSpawnLimit(-1); - } - } - this.loaded = true; - } + checkLoaded(world); } catch (Exception e) { e.printStackTrace(); } @@ -154,6 +131,41 @@ public class BukkitPlotGenerator extends ChunkGenerator return toAdd; } + private synchronized void checkLoaded(@NonNull World world) { + // Do not attempt to load configurations until WorldEdit has a platform ready. + try { + WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING); + } catch (Throwable t) { + return; + } + if (!this.loaded) { + String name = world.getName(); + PlotSquared.get().loadWorld(name, this); + final Set areas = this.plotAreaManager.getPlotAreasSet(name); + if (!areas.isEmpty()) { + PlotArea area = areas.iterator().next(); + if (!area.isMobSpawning()) { + if (!area.isSpawnEggs()) { + world.setSpawnFlags(false, false); + } + setSpawnLimits(world, 0); + } else { + world.setSpawnFlags(true, true); + setSpawnLimits(world, -1); + } + } + this.loaded = true; + } + } + + @SuppressWarnings("deprecation") + private void setSpawnLimits(@NonNull World world, int limit) { + world.setAmbientSpawnLimit(limit); + world.setAnimalSpawnLimit(limit); + world.setMonsterSpawnLimit(limit); + world.setWaterAnimalSpawnLimit(limit); + } + @Override public @NonNull ChunkData generateChunkData( @NonNull World world, @NonNull Random random, int x, int z, @@ -201,9 +213,7 @@ public class BukkitPlotGenerator extends ChunkGenerator private void generate(BlockVector2 loc, World world, ScopedQueueCoordinator result) { // Load if improperly loaded if (!this.loaded) { - String name = world.getName(); - PlotSquared.get().loadWorld(name, this); - this.loaded = true; + checkLoaded(world); } // Process the chunk if (ChunkManager.preProcessChunk(loc, result)) {