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,19 +31,23 @@ public class BukkitSetupUtils extends SetupUtils {
} }
String testWorld = "CheckingPlotSquaredGenerator"; String testWorld = "CheckingPlotSquaredGenerator";
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (plugin.isEnabled()) { try {
ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, ""); if (plugin.isEnabled()) {
if (generator != null) { ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
PS.get().removePlotAreas(testWorld); if (generator != null) {
String name = plugin.getDescription().getName(); PS.get().removePlotAreas(testWorld);
GeneratorWrapper<?> wrapped; String name = plugin.getDescription().getName();
if (generator instanceof GeneratorWrapper<?>) { GeneratorWrapper<?> wrapped;
wrapped = (GeneratorWrapper<?>) generator; if (generator instanceof GeneratorWrapper<?>) {
} else { wrapped = (GeneratorWrapper<?>) generator;
wrapped = new BukkitPlotGenerator(testWorld, 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();
} }
} }
} }