Recover from third party generator error

This commit is contained in:
Jesse Boyd 2016-09-04 14:22:01 +10:00
parent d75ab130da
commit 0557671b80
2 changed files with 21 additions and 15 deletions

View File

@ -37,7 +37,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
private final GenChunk chunkSetter; private final GenChunk chunkSetter;
private final PseudoRandom random = new PseudoRandom(); private final PseudoRandom random = new PseudoRandom();
private final IndependentPlotGenerator plotGenerator; private final IndependentPlotGenerator plotGenerator;
private final List<BlockPopulator> populators = new ArrayList<>(); private List<BlockPopulator> populators;
private final ChunkGenerator platformGenerator; private final ChunkGenerator platformGenerator;
private final boolean full; private final boolean full;
private final HashMap<ChunkLoc, byte[][]> dataMap = new HashMap<>(); private final HashMap<ChunkLoc, byte[][]> dataMap = new HashMap<>();
@ -49,6 +49,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
} }
this.plotGenerator = generator; this.plotGenerator = generator;
this.platformGenerator = this; this.platformGenerator = this;
populators = new ArrayList<>();
this.populators.add(new BlockPopulator() { this.populators.add(new BlockPopulator() {
private LocalBlockQueue queue; private LocalBlockQueue queue;
@ -188,9 +189,6 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
} }
}; };
this.chunkSetter = new GenChunk(null, new ChunkWrapper(world, 0, 0)); this.chunkSetter = new GenChunk(null, new ChunkWrapper(world, 0, 0));
if (cg != null) {
this.populators.addAll(cg.getDefaultPopulators(BukkitUtil.getWorld(world)));
}
MainUtil.initCache(); MainUtil.initCache();
} }
@ -246,6 +244,10 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
} }
ArrayList<BlockPopulator> toAdd = new ArrayList<>(); ArrayList<BlockPopulator> toAdd = new ArrayList<>();
List<BlockPopulator> existing = world.getPopulators(); List<BlockPopulator> existing = world.getPopulators();
if (populators == null && platformGenerator != null) {
populators = new ArrayList<>();
this.populators.addAll(platformGenerator.getDefaultPopulators(world));
}
for (BlockPopulator populator : this.populators) { for (BlockPopulator populator : this.populators) {
if (!existing.contains(populator)) { if (!existing.contains(populator)) {
toAdd.add(populator); toAdd.add(populator);

View File

@ -31,6 +31,7 @@ public class BukkitSetupUtils extends SetupUtils {
} }
String testWorld = "CheckingPlotSquaredGenerator"; String testWorld = "CheckingPlotSquaredGenerator";
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
try {
if (plugin.isEnabled()) { if (plugin.isEnabled()) {
ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, ""); ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
if (generator != null) { if (generator != null) {
@ -45,6 +46,9 @@ public class BukkitSetupUtils extends SetupUtils {
SetupUtils.generators.put(name, wrapped); SetupUtils.generators.put(name, wrapped);
} }
} }
} catch (Throwable e) { // Recover from third party generator error
e.printStackTrace();
}
} }
} }