From f79f2ac29ebeafda13e7382eededa06e2ddb4fed Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 11 Feb 2020 16:13:03 -0500 Subject: [PATCH] Tweaks to the world generator --- .../bukkit/generator/BukkitPlotGenerator.java | 36 +++++++++++++------ .../generator/DelegatePlotGenerator.java | 24 ++++++++++--- .../bukkit/generator/PlotBlockPopulator.java | 10 +++--- .../plotsquared/bukkit/util/BukkitUtil.java | 8 ++++- .../plotsquared/plot/util/WorldUtil.java | 6 ++-- 5 files changed, 60 insertions(+), 24 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java index 1536afa3d..056df1d6e 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -129,7 +129,10 @@ public class BukkitPlotGenerator extends ChunkGenerator if (result.getChunkData() != null) { for (int chunkX = 0; chunkX < 16; chunkX++) { for (int chunkZ = 0; chunkZ < 16; chunkZ++) { - biome.setBiome(chunkX, chunkZ, Biome.PLAINS); + for (int y = 0; y < world.getMaxHeight(); y++) { + biome.setBiome(chunkX, y, chunkZ, Biome.PLAINS); + + } } } return result.getChunkData(); @@ -178,18 +181,31 @@ public class BukkitPlotGenerator extends ChunkGenerator ChunkManager.postProcessChunk(loc, result); } - /** - * Allow spawning everywhere. - * - * @param world Ignored - * @param x Ignored - * @param z Ignored - * @return always true - */ - @Override public boolean canSpawn(@NotNull final World world, final int x, final int z) { + @Override + public boolean canSpawn(@NotNull final World world, final int x, final int z) { return true; } + public boolean shouldGenerateCaves() { + return false; + } + + public boolean shouldGenerateDecorations() { + return false; + } + + public boolean isParallelCapable() { + return true; + } + + public boolean shouldGenerateMobs() { + return false; + } + + public boolean shouldGenerateStructures() { + return false; + } + @Override public String toString() { if (this.platformGenerator == this) { return this.plotGenerator.getName(); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/DelegatePlotGenerator.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/DelegatePlotGenerator.java index ed4df3714..30166218c 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/DelegatePlotGenerator.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/DelegatePlotGenerator.java @@ -9,7 +9,7 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; import com.sk89q.worldedit.bukkit.BukkitAdapter; -import lombok.RequiredArgsConstructor; +import java.util.Random; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; @@ -17,13 +17,16 @@ import org.bukkit.generator.ChunkGenerator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Range; -import java.util.Random; - -@RequiredArgsConstructor final class DelegatePlotGenerator extends IndependentPlotGenerator { +final class DelegatePlotGenerator extends IndependentPlotGenerator { private final ChunkGenerator chunkGenerator; private final String world; + public DelegatePlotGenerator(ChunkGenerator chunkGenerator, String world) { + this.chunkGenerator = chunkGenerator; + this.world = world; + } + @Override public void initialize(PlotArea area) { } @@ -44,13 +47,24 @@ import java.util.Random; try { ChunkGenerator.BiomeGrid grid = new ChunkGenerator.BiomeGrid() { @Override public void setBiome(@Range(from = 0, to = 15) int x, - @Range(from = 0, to = 15) int z, Biome biome) { + @Range(from = 0, to = 15) int z, @NotNull Biome biome) { result.setBiome(x, z, BukkitAdapter.adapt(biome)); } + //do not annotate with Override until we discontinue support for 1.4.4 + public void setBiome(int x, int y, int z, @NotNull Biome biome) { + result.setBiome(x, z, BukkitAdapter.adapt(biome)); + + } + @Override @NotNull public Biome getBiome(int x, int z) { return Biome.FOREST; } + + @Override + public @NotNull Biome getBiome(int x, int y, int z) { + return Biome.FOREST; + } }; chunkGenerator.generateChunkData(world, random, chunkX, chunkZ, grid); return; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/PlotBlockPopulator.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/PlotBlockPopulator.java index de06df5a3..2af7b7e45 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/PlotBlockPopulator.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/PlotBlockPopulator.java @@ -7,19 +7,21 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; -import lombok.RequiredArgsConstructor; +import java.util.Random; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; import org.jetbrains.annotations.NotNull; -import java.util.Random; - -@RequiredArgsConstructor final class BlockStatePopulator extends BlockPopulator { +final class BlockStatePopulator extends BlockPopulator { private final IndependentPlotGenerator plotGenerator; private LocalBlockQueue queue; + public BlockStatePopulator(IndependentPlotGenerator plotGenerator) { + this.plotGenerator = plotGenerator; + } + @Override public void populate(@NotNull final World world, @NotNull final Random random, @NotNull final Chunk source) { if (this.queue == null) { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java index 23ed71550..b27c7564b 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java @@ -417,10 +417,16 @@ import java.util.Set; public void setBiomes(@NonNull final String worldName, @NonNull final CuboidRegion region, @NonNull final BiomeType biomeType) { final World world = getWorld(worldName); + if (world == null) { + PlotSquared.log("An error occurred setting the biome because the world was null."); + return; + } final Biome biome = BukkitAdapter.adapt(biomeType); for (int x = region.getMinimumPoint().getX(); x <= region.getMaximumPoint().getX(); x++) { for (int z = region.getMinimumPoint().getZ(); z <= region.getMaximumPoint().getZ(); z++) { - world.setBiome(x, z, biome); + for (int y = 0; y < world.getMaxHeight(); y++) { + world.setBiome(x, y, z, biome); + } } } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java index f2a37512f..57fb95afa 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java @@ -29,6 +29,7 @@ import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import org.jetbrains.annotations.NotNull; public abstract class WorldUtil { public static WorldUtil IMP; @@ -65,10 +66,7 @@ public abstract class WorldUtil { public abstract com.sk89q.worldedit.world.World getWeWorld(String world); - public void upload(final Plot plot, UUID uuid, String file, RunnableVal whenDone) { - if (plot == null) { - throw new IllegalArgumentException("Plot may not be null!"); - } + public void upload(@NotNull final Plot plot, UUID uuid, String file, RunnableVal whenDone) { final Location home = plot.getHome(); MainUtil.upload(uuid, file, "zip", new RunnableVal() { @Override public void run(OutputStream output) {