From 0557671b8036d57ce9e7d28993d998ba70ec17f2 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 4 Sep 2016 14:22:01 +1000 Subject: [PATCH] Recover from third party generator error --- .../bukkit/generator/BukkitPlotGenerator.java | 10 ++++--- .../bukkit/util/BukkitSetupUtils.java | 26 +++++++++++-------- 2 files changed, 21 insertions(+), 15 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 fc4087c81..579acc44c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -37,7 +37,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap private final GenChunk chunkSetter; private final PseudoRandom random = new PseudoRandom(); private final IndependentPlotGenerator plotGenerator; - private final List populators = new ArrayList<>(); + private List populators; private final ChunkGenerator platformGenerator; private final boolean full; private final HashMap dataMap = new HashMap<>(); @@ -49,6 +49,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap } this.plotGenerator = generator; this.platformGenerator = this; + populators = new ArrayList<>(); this.populators.add(new BlockPopulator() { private LocalBlockQueue queue; @@ -188,9 +189,6 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap } }; this.chunkSetter = new GenChunk(null, new ChunkWrapper(world, 0, 0)); - if (cg != null) { - this.populators.addAll(cg.getDefaultPopulators(BukkitUtil.getWorld(world))); - } MainUtil.initCache(); } @@ -246,6 +244,10 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap } ArrayList toAdd = new ArrayList<>(); List existing = world.getPopulators(); + if (populators == null && platformGenerator != null) { + populators = new ArrayList<>(); + this.populators.addAll(platformGenerator.getDefaultPopulators(world)); + } for (BlockPopulator populator : this.populators) { if (!existing.contains(populator)) { toAdd.add(populator); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java index e31310996..4056103f8 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java @@ -31,19 +31,23 @@ public class BukkitSetupUtils extends SetupUtils { } String testWorld = "CheckingPlotSquaredGenerator"; for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { - if (plugin.isEnabled()) { - ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, ""); - if (generator != null) { - PS.get().removePlotAreas(testWorld); - String name = plugin.getDescription().getName(); - GeneratorWrapper wrapped; - if (generator instanceof GeneratorWrapper) { - wrapped = (GeneratorWrapper) generator; - } else { - wrapped = new BukkitPlotGenerator(testWorld, generator); + try { + if (plugin.isEnabled()) { + ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, ""); + if (generator != null) { + PS.get().removePlotAreas(testWorld); + String name = plugin.getDescription().getName(); + GeneratorWrapper wrapped; + if (generator instanceof GeneratorWrapper) { + wrapped = (GeneratorWrapper) generator; + } else { + wrapped = new BukkitPlotGenerator(testWorld, generator); + } + SetupUtils.generators.put(name, wrapped); } - SetupUtils.generators.put(name, wrapped); } + } catch (Throwable e) { // Recover from third party generator error + e.printStackTrace(); } } }