From 1f32707ec2a60f7ffb89488dae70fc688316daf8 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Tue, 5 Apr 2016 10:08:10 +1000 Subject: [PATCH] Fix populate offset for older versions --- .../bukkit/generator/BukkitPlotGenerator.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 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 18338b3dc..74f1c3332 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -4,6 +4,7 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; +import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; @@ -16,6 +17,7 @@ import com.intellectualcrafters.plot.util.SetQueue; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.block.GenChunk; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Random; import java.util.Set; @@ -35,16 +37,34 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap private final boolean full; private boolean loaded = false; + HashMap dataMap = new HashMap<>(); + public BukkitPlotGenerator(IndependentPlotGenerator generator) { this.plotGenerator = generator; this.platformGenerator = this; this.populators.add(new BlockPopulator() { @Override public void populate(World world, Random r, Chunk c) { - GenChunk result = (GenChunk) BukkitPlotGenerator.this.chunkSetter; - if (result.result_data != null) { - for (int i = 0; i < result.result_data.length; i++) { - byte[] section = result.result_data[i]; + ChunkLoc loc = new ChunkLoc(c.getX(), c.getZ()); + byte[][] resultData; + if (!dataMap.containsKey(loc)) { + GenChunk result = (GenChunk) chunkSetter; + // Set the chunk location + result.setChunkWrapper(SetQueue.IMP.new ChunkWrapper(world.getName(), loc.x, loc.z)); + // Set the result data + result.result = new short[16][]; + result.result_data = new byte[16][]; + result.grid = null; + result.cd = null; + // Catch any exceptions (as exceptions usually thrown) + generate(world, loc.x, loc.z, result); + resultData = result.result_data; + } else { + resultData = dataMap.remove(loc); + } + if (resultData != null) { + for (int i = 0; i < resultData.length; i++) { + byte[] section = resultData[i]; if (section == null) { continue; } @@ -250,7 +270,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap return result.cd; } - public void generate(World world, int cx, int cz, GenChunk result) { + public void generate(World world, int cx, int cz, PlotChunk result) { // Load if improperly loaded if (!this.loaded) { String name = world.getName(); @@ -285,6 +305,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap return this.platformGenerator.generateExtBlockSections(world, r, cx, cz, grid); } else { generate(world, cx, cz, result); + dataMap.put(new ChunkLoc(cx, cz), result.result_data); + } } catch (Throwable e) { e.printStackTrace();