From 0eed26f6a3acced0787a7033071a3497a5f448cd Mon Sep 17 00:00:00 2001 From: wode490390 Date: Mon, 27 Jan 2020 19:31:03 +0800 Subject: [PATCH] 1.0.1 --- pom.xml | 2 +- .../ScatteredBuildingPopulator.java | 11 ++----- .../scheduler/ChunkPopulateTask.java | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 src/main/java/cn/wode490390/nukkit/scatteredbuilding/scheduler/ChunkPopulateTask.java diff --git a/pom.xml b/pom.xml index 9aa42ab..59191ec 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ cn.wode490390.nukkit scatteredbuildingpopulator jar - 1.0.0 + 1.0.1 ScatteredBuildingPopulator Scattered building populator plugin for Nukkit http://wode490390.cn/ diff --git a/src/main/java/cn/wode490390/nukkit/scatteredbuilding/ScatteredBuildingPopulator.java b/src/main/java/cn/wode490390/nukkit/scatteredbuilding/ScatteredBuildingPopulator.java index 27ec35c..39cc804 100644 --- a/src/main/java/cn/wode490390/nukkit/scatteredbuilding/ScatteredBuildingPopulator.java +++ b/src/main/java/cn/wode490390/nukkit/scatteredbuilding/ScatteredBuildingPopulator.java @@ -6,15 +6,14 @@ import cn.nukkit.event.level.LevelLoadEvent; import cn.nukkit.event.level.LevelUnloadEvent; import cn.nukkit.level.Level; -import cn.nukkit.level.format.FullChunk; import cn.nukkit.level.generator.Generator; import cn.nukkit.level.generator.populator.type.Populator; -import cn.nukkit.math.NukkitRandom; import cn.nukkit.plugin.PluginBase; import cn.nukkit.utils.Logger; import cn.wode490390.nukkit.scatteredbuilding.populator.PopulatorDesertPyramid; import cn.wode490390.nukkit.scatteredbuilding.populator.PopulatorJungleTemple; import cn.wode490390.nukkit.scatteredbuilding.populator.PopulatorSwampHut; +import cn.wode490390.nukkit.scatteredbuilding.scheduler.ChunkPopulateTask; import cn.wode490390.nukkit.scatteredbuilding.util.MetricsLite; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -67,13 +66,7 @@ public void onChunkPopulate(ChunkPopulateEvent event) { Level level = event.getLevel(); List populators = this.populators.get(level); if (populators != null) { - FullChunk chunk = event.getChunk(); - int chunkX = chunk.getX(); - int chunkZ = chunk.getZ(); - NukkitRandom random = new NukkitRandom(0xdeadbeef ^ (chunkX << 8) ^ chunkZ ^ level.getSeed()); - populators.forEach(populator -> { - populator.populate(level, chunkX, chunkZ, random, chunk); - }); + this.getServer().getScheduler().scheduleAsyncTask(this, new ChunkPopulateTask(level, event.getChunk(), populators)); } } diff --git a/src/main/java/cn/wode490390/nukkit/scatteredbuilding/scheduler/ChunkPopulateTask.java b/src/main/java/cn/wode490390/nukkit/scatteredbuilding/scheduler/ChunkPopulateTask.java new file mode 100644 index 0000000..d071598 --- /dev/null +++ b/src/main/java/cn/wode490390/nukkit/scatteredbuilding/scheduler/ChunkPopulateTask.java @@ -0,0 +1,31 @@ +package cn.wode490390.nukkit.scatteredbuilding.scheduler; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.format.FullChunk; +import cn.nukkit.level.generator.populator.type.Populator; +import cn.nukkit.math.NukkitRandom; +import cn.nukkit.scheduler.AsyncTask; +import java.util.Collection; + +public class ChunkPopulateTask extends AsyncTask { + + private final ChunkManager level; + private final FullChunk chunk; + private final Collection populators; + + public ChunkPopulateTask(ChunkManager level, FullChunk chunk, Collection populators) { + this.level = level; + this.chunk = chunk; + this.populators = populators; + } + + @Override + public void onRun() { + int chunkX = this.chunk.getX(); + int chunkZ = this.chunk.getZ(); + NukkitRandom random = new NukkitRandom(0xdeadbeef ^ (chunkX << 8) ^ chunkZ ^ this.level.getSeed()); + this.populators.forEach(populator -> { + populator.populate(this.level, chunkX, chunkZ, random, this.chunk); + }); + } +}