From d254633b77cf9cb04b87cdf35579d43fefd33606 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 10 Nov 2019 17:47:37 +0000 Subject: [PATCH] Use patterns instead of BlockBucket Still use BlockBucket for loading/saving from config --- .../plotsquared/bukkit/BukkitMain.java | 2 - .../generator/DelegatePlotGenerator.java | 30 +- .../bukkit/object/BukkitPlayer.java | 1 - .../bukkit/util/BukkitChunkManager.java | 8 +- .../bukkit/util/BukkitHybridUtils.java | 313 ------------------ .../bukkit/util/BukkitSchematicHandler.java | 1 - .../bukkit/util/BukkitTaskManager.java | 2 - .../plotsquared/bukkit/util/BukkitUtil.java | 28 +- .../bukkit/util/block/BukkitLocalQueue.java | 7 +- .../bukkit/util/block/GenChunk.java | 21 +- .../plotsquared/api/PlotAPI.java | 1 - .../plotsquared/plot/PlotSquared.java | 2 +- .../plotsquared/plot/commands/Area.java | 12 +- .../plotsquared/plot/commands/Biome.java | 32 +- .../plotsquared/plot/commands/Info.java | 2 +- .../plotsquared/plot/commands/Set.java | 52 +-- .../plotsquared/plot/commands/Trim.java | 4 +- .../plotsquared/plot/config/Config.java | 1 - .../plot/config/Configuration.java | 16 +- .../plot/generator/AugmentedUtils.java | 9 +- .../plot/generator/ClassicPlotManager.java | 68 ++-- .../plot/generator/ClassicPlotWorld.java | 28 +- .../plotsquared/plot/generator/HybridGen.java | 54 +-- .../plot/generator/HybridPlotManager.java | 11 +- .../plot/generator/HybridUtils.java | 195 ++++++++++- .../generator/IndependentPlotGenerator.java | 9 - .../plot/generator/SquarePlotManager.java | 3 +- .../plot/listener/PlotListener.java | 2 +- .../plot/listener/ProcessedWEExtent.java | 3 +- .../plotsquared/plot/listener/WEExtent.java | 3 +- .../plot/listener/WESubscriber.java | 3 +- .../plotsquared/plot/object/BlockBucket.java | 37 ++- .../plot/object/ConsolePlayer.java | 1 - .../plotsquared/plot/object/Plot.java | 19 +- .../plotsquared/plot/object/PlotArea.java | 22 +- .../plotsquared/plot/object/PlotManager.java | 3 +- .../object/worlds/DefaultPlotAreaManager.java | 2 +- .../plot/object/worlds/SinglePlot.java | 1 - .../object/worlds/SinglePlotAreaManager.java | 2 +- .../plot/object/worlds/SinglePlotManager.java | 4 +- .../object/worlds/SingleWorldGenerator.java | 59 +--- .../plotsquared/plot/util/ChunkManager.java | 2 +- .../plotsquared/plot/util/MainUtil.java | 21 +- .../plot/util/SchematicHandler.java | 2 +- .../plotsquared/plot/util/WorldUtil.java | 11 +- .../plot/util/block/BasicLocalBlockQueue.java | 23 +- .../plot/util/block/ChunkBlockQueue.java | 95 ++++++ .../util/block/DelegateLocalBlockQueue.java | 8 +- .../plot/util/block/LocalBlockQueue.java | 14 +- .../util/block/OffsetLocalBlockQueue.java | 3 +- .../util/block/ScopedLocalBlockQueue.java | 5 +- .../plot/util/world/OperationUtil.java | 3 - .../plot/util/world/PatternUtil.java | 66 ++++ 53 files changed, 618 insertions(+), 708 deletions(-) create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ChunkBlockQueue.java create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/PatternUtil.java diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java index 7d4c8bf4b..8474d5c8a 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java @@ -65,8 +65,6 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.bukkit.BukkitCommandSender; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.extension.platform.Actor; import io.papermc.lib.PaperLib; 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 aab23d804..ed4df3714 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 @@ -2,15 +2,13 @@ package com.github.intellectualsites.plotsquared.bukkit.generator; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotWorld; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; -import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.util.MathMan; -import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import lombok.RequiredArgsConstructor; import org.bukkit.World; import org.bukkit.block.Biome; @@ -37,30 +35,6 @@ import java.util.Random; return PlotSquared.get().IMP.getDefaultGenerator().getNewPlotArea(world, id, min, max); } - @Override public BlockBucket[][] generateBlockBucketChunk(PlotArea settings) { - BlockBucket[][] blockBuckets = new BlockBucket[16][]; - HybridPlotWorld hpw = (HybridPlotWorld) settings; - // Bedrock - if (hpw.PLOT_BEDROCK) { - for (short x = 0; x < 16; x++) { - for (short z = 0; z < 16; z++) { - blockBuckets[0][(z << 4) | x] = - BlockBucket.withSingle(BlockUtil.get("bedrock")); - } - } - } - for (short x = 0; x < 16; x++) { - for (short z = 0; z < 16; z++) { - for (int y = 1; y < hpw.PLOT_HEIGHT; y++) { - blockBuckets[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = hpw.MAIN_BLOCK; - } - blockBuckets[hpw.PLOT_HEIGHT >> 4][((hpw.PLOT_HEIGHT & 0xF) << 8) | (z << 4) | x] = - hpw.MAIN_BLOCK; - } - } - return blockBuckets; - } - @Override public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings) { World world = BukkitUtil.getWorld(this.world); Location min = result.getMin(); @@ -71,7 +45,7 @@ import java.util.Random; 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) { - result.setBiome(x, z, biome.name()); + result.setBiome(x, z, BukkitAdapter.adapt(biome)); } @Override @NotNull public Biome getBiome(int x, int z) { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java index 9ca1bbbae..f09ecb968 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java @@ -12,7 +12,6 @@ import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.world.item.ItemType; import io.papermc.lib.PaperLib; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java index 44bad9589..0209058c5 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java @@ -9,19 +9,19 @@ import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotLoc; -import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; -import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; 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 com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockTypes; import io.papermc.lib.PaperLib; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -370,7 +370,7 @@ public class BukkitChunkManager extends ChunkManager { if (id != null) { value.setBlock(x1, y, z1, id); } else { - value.setBlock(x1, y, z1, BlockUtil.get("air")); + value.setBlock(x1, y, z1, BlockTypes.AIR.getDefaultState()); } } for (int y = Math.min(128, ids.length); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java index 95f4b2ebc..c13a656f8 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java @@ -1,321 +1,8 @@ package com.github.intellectualsites.plotsquared.bukkit.util; -import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator; -import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotWorld; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; -import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; -import com.github.intellectualsites.plotsquared.plot.object.Location; -import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.sk89q.worldedit.regions.CuboidRegion; -import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; -import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; -import com.github.intellectualsites.plotsquared.plot.util.MainUtil; -import com.github.intellectualsites.plotsquared.plot.util.MathMan; -import com.github.intellectualsites.plotsquared.plot.util.TaskManager; -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.expiry.PlotAnalysis; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.block.BlockTypes; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Directional; -import org.bukkit.generator.ChunkGenerator; - -import java.util.HashSet; -import java.util.Set; public class BukkitHybridUtils extends HybridUtils { - @Override public void analyzeRegion(final String world, final CuboidRegion region, - final RunnableVal whenDone) { - // int diff, int variety, int vertices, int rotation, int height_sd - /* - * diff: compare to base by looping through all blocks - * variety: add to HashSet for each BlockState - * height_sd: loop over all blocks and get top block - * - * vertices: store air map and compare with neighbours - * for each block check the adjacent - * - Store all blocks then go through in second loop - * - recheck each block - * - */ - TaskManager.runTaskAsync(() -> { - final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); - final World worldObj = Bukkit.getWorld(world); - final ChunkGenerator chunkGenerator = worldObj.getGenerator(); - if (!(chunkGenerator instanceof BukkitPlotGenerator)) { - return; - } - final Location bot = new Location(world, region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ()); - final Location top = new Location(world, region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ()); - - final int bx = bot.getX(); - final int bz = bot.getZ(); - final int tx = top.getX(); - final int tz = top.getZ(); - final int cbx = bx >> 4; - final int cbz = bz >> 4; - final int ctx = tx >> 4; - final int ctz = tz >> 4; - MainUtil.initCache(); - final int width = tx - bx + 1; - final int length = tz - bz + 1; - - System.gc(); - System.gc(); - final BlockBucket[][][] oldBlocks = new BlockBucket[256][width][length]; - final BlockState[][][] newBlocks = new BlockState[256][width][length]; - final BlockBucket airBucket = BlockBucket.withSingle(BlockTypes.AIR.getDefaultState()); - - PlotArea area = PlotSquared.get().getPlotArea(world, null); - - if (!(area instanceof HybridPlotWorld)) { - return; - } - - HybridPlotWorld hpw = (HybridPlotWorld) area; - final BlockBucket[][] result = hpw.getBlockBucketChunk(); - - if (result == null) { - return; - } - - if (hpw.PLOT_SCHEMATIC) { - short[] rx = new short[16]; - short[] rz = new short[16]; - short rbx; - short rbz; - if (bx < 0) { - rbx = (short) (hpw.SIZE + (bx % hpw.SIZE)); - } else { - rbx = (short) (bx % hpw.SIZE); - } - if (bz < 0) { - rbz = (short) (hpw.SIZE + (bz % hpw.SIZE)); - } else { - rbz = (short) (bz % hpw.SIZE); - } - for (short i = 0; i < 16; i++) { - short v = (short) (rbx + i); - if (v >= hpw.SIZE) { - v -= hpw.SIZE; - } - rx[i] = v; - } - for (short i = 0; i < 16; i++) { - short v = (short) (rbz + i); - if (v >= hpw.SIZE) { - v -= hpw.SIZE; - } - rz[i] = v; - } - int minY; - if (Settings.Schematics.PASTE_ON_TOP) { - minY = hpw.SCHEM_Y; - } else { - minY = 1; - } - for (short x = 0; x < 16; x++) { - for (short z = 0; z < 16; z++) { - BaseBlock[] blocks = hpw.G_SCH.get(MathMan.pair(rx[x], rz[z])); - for (int y = 0; y < blocks.length; y++) { - if (blocks[y] != null) { - result[(minY + y) >> 4][(((minY + y) & 0xF) << 8) | (z << 4) | x] = - BlockBucket.withSingle(blocks[y].toImmutableState()); - } - } - } - } - } - - final Runnable run = () -> ChunkManager.chunkTask(bot, top, new RunnableVal() { - @Override public void run(int[] value) { - // [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge] - int X = value[0]; - int Z = value[1]; - int xb = (X << 4) - bx; - int zb = (Z << 4) - bz; - for (int i = 0; i < result.length; i++) { - if (result[i] == null) { - for (int j = 0; j < 4096; j++) { - int x = MainUtil.x_loc[i][j] + xb; - if (x < 0 || x >= width) { - continue; - } - int z = MainUtil.z_loc[i][j] + zb; - if (z < 0 || z >= length) { - continue; - } - int y = MainUtil.y_loc[i][j]; - oldBlocks[y][x][z] = airBucket; - } - continue; - } - for (int j = 0; j < result[i].length; j++) { - int x = MainUtil.x_loc[i][j] + xb; - if (x < 0 || x >= width) { - continue; - } - int z = MainUtil.z_loc[i][j] + zb; - if (z < 0 || z >= length) { - continue; - } - int y = MainUtil.y_loc[i][j]; - oldBlocks[y][x][z] = result[i][j] != null ? result[i][j] : airBucket; - } - } - - } - }, () -> TaskManager.runTaskAsync(() -> { - int size = width * length; - int[] changes = new int[size]; - int[] faces = new int[size]; - int[] data = new int[size]; - int[] air = new int[size]; - int[] variety = new int[size]; - int i = 0; - for (int x = 0; x < width; x++) { - for (int z = 0; z < length; z++) { - Set types = new HashSet<>(); - for (int y = 0; y < 256; y++) { - BlockBucket old = oldBlocks[y][x][z]; - try { - if (old == null) { - old = airBucket; - } - BlockState now = newBlocks[y][x][z]; - if (!old.getBlocks().contains(now)) { - changes[i]++; - } - if (now.getBlockType().getMaterial().isAir()) { - air[i]++; - } else { - // check vertices - // modifications_adjacent - if (x > 0 && z > 0 && y > 0 && x < width - 1 && z < length - 1 - && y < 255) { - if (newBlocks[y - 1][x][z].getBlockType().getMaterial().isAir()) { - faces[i]++; - } - if (newBlocks[y][x - 1][z].getBlockType().getMaterial().isAir()) { - faces[i]++; - } - if (newBlocks[y][x][z - 1].getBlockType().getMaterial().isAir()) { - faces[i]++; - } - if (newBlocks[y + 1][x][z].getBlockType().getMaterial().isAir()) { - faces[i]++; - } - if (newBlocks[y][x + 1][z].getBlockType().getMaterial().isAir()) { - faces[i]++; - } - if (newBlocks[y][x][z + 1].getBlockType().getMaterial().isAir()) { - faces[i]++; - } - } - - Material material = BukkitAdapter.adapt(now.getBlockType()); - if (material != null) { - BlockData blockData = material.createBlockData(); - if (blockData instanceof Directional) { - data[i] += 8; - } else if (!blockData.getClass().equals(BlockData.class)) { - data[i]++; - } - } - types.add(now.getBlockType()); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - } - variety[i] = types.size(); - i++; - } - } - // analyze plot - // put in analysis obj - - // run whenDone - PlotAnalysis analysis = new PlotAnalysis(); - analysis.changes = (int) (MathMan.getMean(changes) * 100); - analysis.faces = (int) (MathMan.getMean(faces) * 100); - analysis.data = (int) (MathMan.getMean(data) * 100); - analysis.air = (int) (MathMan.getMean(air) * 100); - analysis.variety = (int) (MathMan.getMean(variety) * 100); - - analysis.changes_sd = (int) (MathMan.getSD(changes, analysis.changes) * 100); - analysis.faces_sd = (int) (MathMan.getSD(faces, analysis.faces) * 100); - analysis.data_sd = (int) (MathMan.getSD(data, analysis.data) * 100); - analysis.air_sd = (int) (MathMan.getSD(air, analysis.air) * 100); - analysis.variety_sd = (int) (MathMan.getSD(variety, analysis.variety) * 100); - System.gc(); - System.gc(); - whenDone.value = analysis; - whenDone.run(); - }), 5); - System.gc(); - MainUtil.initCache(); - ChunkManager.chunkTask(bot, top, new RunnableVal() { - @Override public void run(int[] value) { - int X = value[0]; - int Z = value[1]; - worldObj.loadChunk(X, Z); - int minX; - if (X == cbx) { - minX = bx & 15; - } else { - minX = 0; - } - int minZ; - if (Z == cbz) { - minZ = bz & 15; - } else { - minZ = 0; - } - int maxX; - if (X == ctx) { - maxX = tx & 15; - } else { - maxX = 16; - } - int maxZ; - if (Z == ctz) { - maxZ = tz & 15; - } else { - maxZ = 16; - } - - int cbx = X << 4; - int cbz = Z << 4; - - int xb = cbx - bx; - int zb = cbz - bz; - for (int x = minX; x <= maxX; x++) { - int xx = cbx + x; - for (int z = minZ; z <= maxZ; z++) { - int zz = cbz + z; - for (int y = 0; y < 256; y++) { - BlockState block = queue.getBlock(xx, y, zz); - int xr = xb + x; - int zr = zb + z; - newBlocks[y][xr][zr] = block; - } - } - } - worldObj.unloadChunkRequest(X, Z); - } - }, () -> TaskManager.runTaskAsync(run), 5); - }); - } } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java index ed0a8cfcc..4139d2191 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java @@ -2,7 +2,6 @@ package com.github.intellectualsites.plotsquared.bukkit.util; import com.github.intellectualsites.plotsquared.bukkit.object.schematic.StateWrapper; import com.github.intellectualsites.plotsquared.plot.object.Location; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitTaskManager.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitTaskManager.java index dcb562166..0989ccf1a 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitTaskManager.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitTaskManager.java @@ -3,8 +3,6 @@ package com.github.intellectualsites.plotsquared.bukkit.util; import com.github.intellectualsites.plotsquared.bukkit.BukkitMain; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import org.bukkit.Bukkit; -import org.bukkit.scheduler.BukkitTask; -import org.jetbrains.annotations.NotNull; public class BukkitTaskManager extends TaskManager { 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 026689c2d..b4e74b74d 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 @@ -7,7 +7,6 @@ import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; @@ -18,6 +17,8 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockState; import lombok.NonNull; import org.bukkit.Bukkit; @@ -39,7 +40,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -279,8 +279,8 @@ import java.util.Set; return getWorld(worldName) != null; } - @Override public String getBiome(String world, int x, int z) { - return getWorld(world).getBiome(x, z).name(); + @Override public BiomeType getBiome(String world, int x, int z) { + return BukkitAdapter.adapt(getWorld(world).getBiome(x, z)); } @Override public int getHighestBlock(@NonNull final String world, final int x, final int z) { @@ -380,20 +380,6 @@ import java.util.Set; } } - @Override public int getBiomeFromString(@NonNull final String biomeString) { - try { - final Biome biome = Biome.valueOf(biomeString.toUpperCase()); - return Arrays.asList(Biome.values()).indexOf(biome); - } catch (IllegalArgumentException ignored) { - return -1; - } - } - - @Override public String[] getBiomeList() { - final Biome[] biomes = Biome.values(); - return Arrays.stream(biomes).map(Enum::name).toArray(String[]::new); - } - @Override public boolean addItems(@NonNull final String worldName, @NonNull final PlotItem items) { final World world = getWorld(worldName); @@ -433,9 +419,9 @@ import java.util.Set; @Override public void setBiomes(@NonNull final String worldName, @NonNull final CuboidRegion region, - @NonNull final String biomeString) { + @NonNull final BiomeType biomeType) { final World world = getWorld(worldName); - final Biome biome = Biome.valueOf(biomeString.toUpperCase()); + 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); @@ -450,7 +436,7 @@ import java.util.Set; @Override public BlockState getBlock(@NonNull final Location location) { final World world = getWorld(location.getWorld()); final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ()); - return BlockUtil.get(block.getType().name()); + return BukkitAdapter.asBlockType(block.getType()).getDefaultState(); } @Override public String getMainWorld() { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java index 9f5dc4e7f..82f5c4282 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java @@ -8,6 +8,7 @@ import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQ import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import io.papermc.lib.PaperLib; @@ -130,11 +131,11 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { int bx = lc.getX() << 4; int bz = lc.getX() << 4; for (int x = 0; x < lc.biomes.length; x++) { - String[] biomes2 = lc.biomes[x]; + BiomeType[] biomes2 = lc.biomes[x]; if (biomes2 != null) { - for (String biomeStr : biomes2) { + for (BiomeType biomeStr : biomes2) { if (biomeStr != null) { - Biome biome = Biome.valueOf(biomeStr.toUpperCase()); + Biome biome = BukkitAdapter.adapt(biomeStr); worldObj.setBiome(bx, bz, biome); } } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java index a93c22679..72c570df5 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java @@ -5,11 +5,14 @@ import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; import com.github.intellectualsites.plotsquared.plot.object.ChunkWrapper; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; -import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; +import com.github.intellectualsites.plotsquared.plot.util.world.PatternUtil; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockTypes; import lombok.Getter; import lombok.Setter; import org.bukkit.Chunk; @@ -57,11 +60,11 @@ public class GenChunk extends ScopedLocalBlockQueue { chunkZ = wrap.z; } - @Override public void fillBiome(String biomeName) { + @Override public void fillBiome(BiomeType biomeType) { if (biomeGrid == null) { return; } - Biome biome = Biome.valueOf(biomeName.toUpperCase()); + Biome biome = BukkitAdapter.adapt(biomeType); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { this.biomeGrid.setBiome(x, z, biome); @@ -92,8 +95,8 @@ public class GenChunk extends ScopedLocalBlockQueue { chunkData.setRegion(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1, BukkitAdapter.adapt(block)); } - @Override public boolean setBiome(int x, int z, String biome) { - return setBiome(x, z, Biome.valueOf(biome.toUpperCase())); + @Override public boolean setBiome(int x, int z, BiomeType biomeType) { + return setBiome(x, z, BukkitAdapter.adapt(biomeType)); } public boolean setBiome(int x, int z, Biome biome) { @@ -104,6 +107,10 @@ public class GenChunk extends ScopedLocalBlockQueue { return false; } + @Override public boolean setBlock(int x, int y, int z, Pattern pattern) { + return setBlock(x, y, z, PatternUtil.apply(pattern, x, y, z)); + } + @Override public boolean setBlock(int x, int y, int z, BlockState id) { if (this.result == null) { this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id)); @@ -130,7 +137,7 @@ public class GenChunk extends ScopedLocalBlockQueue { return true; } this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id)); - this.storeCache(x, y, z, BlockUtil.get(id.getBlockType().getId())); + this.storeCache(x, y, z, id.toImmutableState()); return true; } @@ -141,7 +148,7 @@ public class GenChunk extends ScopedLocalBlockQueue { } BlockState[] array = result[i]; if (array == null) { - return BlockUtil.get(""); + return BlockTypes.AIR.getDefaultState(); } int j = MainUtil.CACHE_J[y][x][z]; return array[j]; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java index 740db8fca..610362953 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java @@ -14,7 +14,6 @@ import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; -import com.sk89q.worldedit.extension.platform.Actor; import lombok.NoArgsConstructor; import java.util.Collections; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index fd57be3d8..86b8c7a92 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -29,7 +29,6 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotFilter; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.object.PlotManager; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.StringWrapper; import com.github.intellectualsites.plotsquared.plot.object.worlds.DefaultPlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager; @@ -56,6 +55,7 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpiryTask; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.regions.CuboidRegion; import lombok.Getter; import lombok.NonNull; import lombok.Setter; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java index f773c1e1c..11134d2ca 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Area.java @@ -12,8 +12,6 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.github.intellectualsites.plotsquared.plot.object.SetupObject; @@ -25,7 +23,9 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.regions.CuboidRegion; import java.io.IOException; import java.util.ArrayList; @@ -209,20 +209,20 @@ import java.util.Set; break; case "f": case "floor": - pa.TOP_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]); + pa.TOP_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]).getPattern(); break; case "m": case "main": - pa.MAIN_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]); + pa.MAIN_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]).getPattern(); break; case "w": case "wall": pa.WALL_FILLING = - Configuration.BLOCK_BUCKET.parseString(pair[1]); + Configuration.BLOCK_BUCKET.parseString(pair[1]).getPattern(); break; case "b": case "border": - pa.WALL_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]); + pa.WALL_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]).getPattern(); break; case "terrain": pa.TERRAIN = Integer.parseInt(pair[1]); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Biome.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Biome.java index 8b9ecb790..d377acd15 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Biome.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Biome.java @@ -6,7 +6,8 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.StringMan; -import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; @CommandDeclaration(command = "setbiome", permission = "plots.set.biome", description = "Set the plot biome", usage = "/plot biome [biome]", @@ -14,25 +15,26 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; requiredType = RequiredType.NONE) public class Biome extends SetCommand { @Override public boolean set(final PlotPlayer player, final Plot plot, final String value) { - int biome = WorldUtil.IMP.getBiomeFromString(value); - if (biome == -1) { + try { + BiomeType biome = BiomeTypes.get(value); + if (plot.getRunning() > 0) { + MainUtil.sendMessage(player, Captions.WAIT_FOR_TIMER); + return false; + } + plot.addRunning(); + plot.setBiome(biome, () -> { + plot.removeRunning(); + MainUtil + .sendMessage(player, Captions.BIOME_SET_TO.getTranslated() + value.toLowerCase()); + }); + return true; + } catch (IllegalStateException ignore) { String biomes = StringMan - .join(WorldUtil.IMP.getBiomeList(), Captions.BLOCK_LIST_SEPARATOR.getTranslated()); + .join(BiomeType.REGISTRY.values(), Captions.BLOCK_LIST_SEPARATOR.getTranslated()); Captions.NEED_BIOME.send(player); MainUtil.sendMessage(player, Captions.SUBCOMMAND_SET_OPTIONS_HEADER.getTranslated() + biomes); return false; } - if (plot.getRunning() > 0) { - MainUtil.sendMessage(player, Captions.WAIT_FOR_TIMER); - return false; - } - plot.addRunning(); - plot.setBiome(value.toUpperCase(), () -> { - plot.removeRunning(); - MainUtil - .sendMessage(player, Captions.BIOME_SET_TO.getTranslated() + value.toLowerCase()); - }); - return true; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Info.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Info.java index fe42e5dd4..b4e46daea 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Info.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Info.java @@ -102,7 +102,7 @@ public class Info extends SubCommand { inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cPlot Info", "&cID: &6" + plot.getId().toString(), "&cOwner: &6" + name, "&cAlias: &6" + plot.getAlias(), - "&cBiome: &6" + plot.getBiome().replaceAll("_", "").toLowerCase(), + "&cBiome: &6" + plot.getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + plot.isAdded(uuid), "&cSeen: &6" + MainUtil.secToTime((int) (ExpireManager.IMP.getAge(plot) / 1000)), "&cIs Denied: &6" + plot.isDenied(uuid))); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java index 771063217..8106b81b9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Set.java @@ -3,22 +3,18 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.Command; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.config.Configuration; -import com.github.intellectualsites.plotsquared.plot.config.Configuration.UnknownBlockException; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; import com.github.intellectualsites.plotsquared.plot.flag.Flags; -import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotManager; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; -import com.github.intellectualsites.plotsquared.plot.util.StringComparison; import com.github.intellectualsites.plotsquared.plot.util.StringMan; -import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; -import com.sk89q.worldedit.world.block.BlockState; +import com.github.intellectualsites.plotsquared.plot.util.world.PatternUtil; +import com.sk89q.worldedit.function.pattern.Pattern; import java.util.ArrayList; import java.util.Arrays; @@ -60,51 +56,19 @@ import java.util.stream.IntStream; Captions.PERMISSION_SET_COMPONENT.f(component)); return false; } - // BlockState[] blocks; - BlockBucket bucket; - try { - if (args.length < 2) { - MainUtil.sendMessage(player, Captions.NEED_BLOCK); - return true; - } - - try { - bucket = Configuration.BLOCK_BUCKET.parseString(material); - } catch (final UnknownBlockException unknownBlockException) { - final String unknownBlock = unknownBlockException.getUnknownValue(); - Captions.NOT_VALID_BLOCK.send(player, unknownBlock); - StringComparison.ComparisonResult match = - WorldUtil.IMP.getClosestBlock(unknownBlock); - if (match != null) { - final String found = - WorldUtil.IMP.getClosestMatchingName(match.best); - if (found != null) { - MainUtil.sendMessage(player, Captions.DID_YOU_MEAN, - found.toLowerCase()); - } - } - return false; - } - - if (!allowUnsafe) { - for (final BlockState block : bucket.getBlocks()) { - if (!block.getBlockType().getMaterial().isAir() && !WorldUtil.IMP.isBlockSolid(block)) { - Captions.NOT_ALLOWED_BLOCK.send(player, block.toString()); - return false; - } - } - } - } catch (Exception ignored) { - MainUtil.sendMessage(player, Captions.NOT_VALID_BLOCK, material); - return false; + if (args.length < 2) { + MainUtil.sendMessage(player, Captions.NEED_BLOCK); + return true; } + + Pattern pattern = PatternUtil.parse(player, material); if (plot.getRunning() > 0) { MainUtil.sendMessage(player, Captions.WAIT_FOR_TIMER); return false; } plot.addRunning(); for (Plot current : plot.getConnectedPlots()) { - current.setComponent(component, bucket); + current.setComponent(component, pattern); } MainUtil.sendMessage(player, Captions.GENERATING_COMPONENT); GlobalBlockQueue.IMP.addEmptyTask(plot::removeRunning); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trim.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trim.java index 66a024ec4..fcdce4898 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trim.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trim.java @@ -6,8 +6,6 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; @@ -17,7 +15,9 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; 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.expiry.ExpireManager; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.regions.CuboidRegion; import java.io.File; import java.io.IOException; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java index f7bd5118e..26c5050ce 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java @@ -13,7 +13,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.invoke.MethodHandles; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java index 94188b35b..a1aedc478 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java @@ -1,15 +1,14 @@ package com.github.intellectualsites.plotsquared.plot.config; import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; -import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.StringComparison; -import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockState; import lombok.Getter; import lombok.NonNull; -import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -43,21 +42,20 @@ public class Configuration { return Boolean.parseBoolean(string); } }; - public static final SettingValue BIOME = new SettingValue("BIOME") { + public static final SettingValue BIOME = new SettingValue("BIOME") { @Override public boolean validateValue(String string) { try { - int biome = WorldUtil.IMP.getBiomeFromString(string.toUpperCase()); - return biome != -1; + return BiomeTypes.get(string) != null; } catch (Exception ignored) { return false; } } - @Override public String parseString(String string) { + @Override public BiomeType parseString(String string) { if (validateValue(string)) { - return string.toUpperCase(); + return BiomeTypes.get(string.toUpperCase()); } - return "FOREST"; + return BiomeTypes.FOREST; } }; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java index f5aa2e440..f1bf833b6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java @@ -4,12 +4,13 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotManager; -import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.block.DelegateLocalBlockQueue; 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 com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import org.jetbrains.annotations.NotNull; @@ -72,7 +73,7 @@ public class AugmentedUtils { return false; } - @Override public boolean setBiome(int x, int z, String biome) { + @Override public boolean setBiome(int x, int z, BiomeType biome) { if (area.contains(x, z)) { return super.setBiome(x, z, biome); } @@ -116,7 +117,7 @@ public class AugmentedUtils { return false; } - @Override public boolean setBiome(int x, int y, String biome) { + @Override public boolean setBiome(int x, int y, BiomeType biome) { return super.setBiome(x, y, biome); } }; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java index 640ee389c..a06fbceca 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java @@ -1,19 +1,21 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.Direction; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotId; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.MathMan; -import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; 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.world.BlockUtil; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.regions.CuboidRegion; import java.util.List; +import static com.github.intellectualsites.plotsquared.plot.util.world.PatternUtil.isAir; + /** * A plot manager with square plots which tessellate on a square grid with the following sections: ROAD, WALL, BORDER (wall), PLOT, FLOOR (plot). */ @@ -27,7 +29,7 @@ public class ClassicPlotManager extends SquarePlotManager { } @Override public boolean setComponent(PlotId plotId, String component, - BlockBucket blocks) { + Pattern blocks) { switch (component) { case "floor": return setFloor(plotId, blocks); @@ -51,13 +53,13 @@ public class ClassicPlotManager extends SquarePlotManager { @Override public boolean unClaimPlot(Plot plot, Runnable whenDone) { setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING); - if (!classicPlotWorld.WALL_BLOCK.isAir() || !classicPlotWorld.WALL_BLOCK.equals(classicPlotWorld.CLAIMED_WALL_BLOCK)) { + if (!isAir(classicPlotWorld.WALL_BLOCK) || !classicPlotWorld.WALL_BLOCK.equals(classicPlotWorld.CLAIMED_WALL_BLOCK)) { setWall(plot.getId(), classicPlotWorld.WALL_BLOCK); } return GlobalBlockQueue.IMP.addEmptyTask(whenDone); } - public boolean setFloor(PlotId plotId, BlockBucket blocks) { + public boolean setFloor(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); LocalBlockQueue queue = classicPlotWorld.getQueue(false); if (plot.isBasePlot()) { @@ -72,7 +74,7 @@ public class ClassicPlotManager extends SquarePlotManager { return queue.enqueue(); } - public boolean setAll(PlotId plotId, BlockBucket blocks) { + public boolean setAll(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); if (!plot.isBasePlot()) { return false; @@ -87,7 +89,7 @@ public class ClassicPlotManager extends SquarePlotManager { return queue.enqueue(); } - public boolean setAir(PlotId plotId, BlockBucket blocks) { + public boolean setAir(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); if (!plot.isBasePlot()) { return false; @@ -103,7 +105,7 @@ public class ClassicPlotManager extends SquarePlotManager { return queue.enqueue(); } - public boolean setMain(PlotId plotId, BlockBucket blocks) { + public boolean setMain(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); if (!plot.isBasePlot()) { return false; @@ -118,7 +120,7 @@ public class ClassicPlotManager extends SquarePlotManager { return queue.enqueue(); } - public boolean setMiddle(PlotId plotId, BlockBucket blocks) { + public boolean setMiddle(PlotId plotId, Pattern blocks) { Plot plot = classicPlotWorld.getPlotAbs(plotId); if (!plot.isBasePlot()) { return false; @@ -128,11 +130,11 @@ public class ClassicPlotManager extends SquarePlotManager { int x = MathMan.average(corners[0].getX(), corners[1].getX()); int z = MathMan.average(corners[0].getZ(), corners[1].getZ()); - queue.setBlock(x, classicPlotWorld.PLOT_HEIGHT, z, blocks.getBlock()); + queue.setBlock(x, classicPlotWorld.PLOT_HEIGHT, z, blocks); return queue.enqueue(); } - public boolean setOutline(PlotId plotId, BlockBucket blocks) { + public boolean setOutline(PlotId plotId, Pattern blocks) { if (classicPlotWorld.ROAD_WIDTH == 0) { return false; } @@ -145,7 +147,7 @@ public class ClassicPlotManager extends SquarePlotManager { int z = bottom.getZ(); for (int x = bottom.getX(); x <= top.getX(); x++) { for (int y = classicPlotWorld.PLOT_HEIGHT; y <= maxY; y++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } } @@ -153,7 +155,7 @@ public class ClassicPlotManager extends SquarePlotManager { int x = bottom.getX(); for (int z = bottom.getZ(); z <= top.getZ(); z++) { for (int y = classicPlotWorld.PLOT_HEIGHT; y <= maxY; y++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } } @@ -162,7 +164,7 @@ public class ClassicPlotManager extends SquarePlotManager { int z = top.getZ(); for (int x = bottom.getX(); x <= top.getX(); x++) { for (int y = classicPlotWorld.PLOT_HEIGHT; y <= maxY; y++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } } @@ -170,7 +172,7 @@ public class ClassicPlotManager extends SquarePlotManager { int x = top.getX(); for (int z = bottom.getZ(); z <= top.getZ(); z++) { for (int y = classicPlotWorld.PLOT_HEIGHT; y <= maxY; y++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } } @@ -184,7 +186,7 @@ public class ClassicPlotManager extends SquarePlotManager { return queue.enqueue(); } - public boolean setWallFilling(PlotId plotId, BlockBucket blocks) { + public boolean setWallFilling(PlotId plotId, Pattern blocks) { if (classicPlotWorld.ROAD_WIDTH == 0) { return false; } @@ -198,7 +200,7 @@ public class ClassicPlotManager extends SquarePlotManager { int z = bot.getZ(); for (int x = bot.getX(); x < top.getX(); x++) { for (int y = 1; y <= classicPlotWorld.WALL_HEIGHT; y++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } } @@ -206,7 +208,7 @@ public class ClassicPlotManager extends SquarePlotManager { int x = bot.getX(); for (int z = bot.getZ(); z < top.getZ(); z++) { for (int y = 1; y <= classicPlotWorld.WALL_HEIGHT; y++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } } @@ -215,7 +217,7 @@ public class ClassicPlotManager extends SquarePlotManager { for (int x = bot.getX(); x < top.getX() + (plot.getMerged(Direction.EAST) ? 0 : 1); x++) { for (int y = 1; y <= classicPlotWorld.WALL_HEIGHT; y++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } } @@ -224,14 +226,14 @@ public class ClassicPlotManager extends SquarePlotManager { for (int z = bot.getZ(); z < top.getZ() + (plot.getMerged(Direction.SOUTH) ? 0 : 1); z++) { for (int y = 1; y <= classicPlotWorld.WALL_HEIGHT; y++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } } return queue.enqueue(); } - public boolean setWall(PlotId plotId, BlockBucket blocks) { + public boolean setWall(PlotId plotId, Pattern blocks) { if (classicPlotWorld.ROAD_WIDTH == 0) { return false; } @@ -245,27 +247,27 @@ public class ClassicPlotManager extends SquarePlotManager { if (!plot.getMerged(Direction.NORTH)) { int z = bot.getZ(); for (int x = bot.getX(); x < top.getX(); x++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } if (!plot.getMerged(Direction.WEST)) { int x = bot.getX(); for (int z = bot.getZ(); z < top.getZ(); z++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } if (!plot.getMerged(Direction.SOUTH)) { int z = top.getZ(); for (int x = bot.getX(); x < top.getX() + (plot.getMerged(Direction.EAST) ? 0 : 1); x++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } if (!plot.getMerged(Direction.EAST)) { int x = top.getX(); for (int z = bot.getZ(); z < top.getZ() + (plot.getMerged(Direction.SOUTH) ? 0 : 1); z++) { - queue.setBlock(x, y, z, blocks.getBlock()); + queue.setBlock(x, y, z, blocks); } } return queue.enqueue(); @@ -411,14 +413,14 @@ public class ClassicPlotManager extends SquarePlotManager { * @return false if part of the merge failed, otherwise true if successful. */ @Override public boolean finishPlotMerge(List plotIds) { - final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK; - if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) { + final Pattern claim = classicPlotWorld.CLAIMED_WALL_BLOCK; + if (!isAir(claim) || !claim.equals(classicPlotWorld.WALL_BLOCK)) { for (PlotId plotId : plotIds) { setWall(plotId, claim); } } if (Settings.General.MERGE_REPLACE_WALL) { - final BlockBucket wallBlock = classicPlotWorld.WALL_FILLING; + final Pattern wallBlock = classicPlotWorld.WALL_FILLING; for (PlotId id : plotIds) { setWallFilling(id, wallBlock); } @@ -427,8 +429,8 @@ public class ClassicPlotManager extends SquarePlotManager { } @Override public boolean finishPlotUnlink(List plotIds) { - final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK; - if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) { + final Pattern claim = classicPlotWorld.CLAIMED_WALL_BLOCK; + if (!isAir(claim) || !claim.equals(classicPlotWorld.WALL_BLOCK)) { for (PlotId id : plotIds) { setWall(id, claim); } @@ -445,8 +447,8 @@ public class ClassicPlotManager extends SquarePlotManager { } @Override public boolean claimPlot(Plot plot) { - final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK; - if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) { + final Pattern claim = classicPlotWorld.CLAIMED_WALL_BLOCK; + if (!isAir(claim) || !claim.equals(classicPlotWorld.WALL_BLOCK)) { return setWall(plot.getId(), claim); } return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java index 4d1ad357c..46af0e43c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java @@ -5,9 +5,11 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; +import com.sk89q.worldedit.function.pattern.BlockPattern; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.world.block.BlockTypes; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Field; @@ -18,17 +20,17 @@ import java.util.Locale; public int ROAD_HEIGHT = 62; public int PLOT_HEIGHT = 62; public int WALL_HEIGHT = 62; - public BlockBucket MAIN_BLOCK = BlockBucket.withSingle(BlockUtil.get("stone")); + public Pattern MAIN_BLOCK = new BlockPattern(BlockTypes.STONE.getDefaultState()); // new BlockState[] {BlockUtil.get("stone")}; - public BlockBucket TOP_BLOCK = BlockBucket.withSingle(BlockUtil.get("grass_block")); + public Pattern TOP_BLOCK = new BlockPattern(BlockTypes.GRASS_BLOCK.getDefaultState()); //new BlockState[] {BlockUtil.get("grass")}; - public BlockBucket WALL_BLOCK = BlockBucket.withSingle(BlockUtil.get("stone_slab")); + public Pattern WALL_BLOCK = new BlockPattern(BlockTypes.STONE_SLAB.getDefaultState()); // BlockUtil.get((short) 44, (byte) 0); - public BlockBucket CLAIMED_WALL_BLOCK = BlockBucket.withSingle(BlockUtil.get("sandstone_slab")); + public Pattern CLAIMED_WALL_BLOCK = new BlockPattern(BlockTypes.SANDSTONE_SLAB.getDefaultState()); // BlockUtil.get((short) 44, (byte) 1); - public BlockBucket WALL_FILLING = BlockBucket.withSingle(BlockUtil.get("stone")); + public Pattern WALL_FILLING = new BlockPattern(BlockTypes.STONE.getDefaultState()); //BlockUtil.get((short) 1, (byte) 0); - public BlockBucket ROAD_BLOCK = BlockBucket.withSingle(BlockUtil.get("quartz_block")); + public Pattern ROAD_BLOCK = new BlockPattern(BlockTypes.QUARTZ_BLOCK.getDefaultState()); // BlockUtil.get((short) 155, (byte) 0); public boolean PLOT_BEDROCK = true; @@ -81,16 +83,16 @@ import java.util.Locale; super.loadConfiguration(config); this.PLOT_BEDROCK = config.getBoolean("plot.bedrock"); this.PLOT_HEIGHT = Math.min(255, config.getInt("plot.height")); - this.MAIN_BLOCK = Configuration.BLOCK_BUCKET.parseString(config.getString("plot.filling")); - this.TOP_BLOCK = Configuration.BLOCK_BUCKET.parseString(config.getString("plot.floor")); - this.WALL_BLOCK = Configuration.BLOCK_BUCKET.parseString(config.getString("wall.block")); + this.MAIN_BLOCK = new BlockPattern(BlockUtil.get(config.getString("plot.filling"))); + this.TOP_BLOCK = new BlockPattern(BlockUtil.get(config.getString("plot.floor"))); + this.WALL_BLOCK = new BlockPattern(BlockUtil.get(config.getString("wall.block"))); this.ROAD_HEIGHT = Math.min(255, config.getInt("road.height")); - this.ROAD_BLOCK = Configuration.BLOCK_BUCKET.parseString(config.getString("road.block")); + this.ROAD_BLOCK = new BlockPattern(BlockUtil.get(config.getString("road.block"))); this.WALL_FILLING = - Configuration.BLOCK_BUCKET.parseString(config.getString("wall.filling")); + new BlockPattern(BlockUtil.get(config.getString("wall.filling"))); this.WALL_HEIGHT = Math.min(254, config.getInt("wall.height")); this.CLAIMED_WALL_BLOCK = - Configuration.BLOCK_BUCKET.parseString(config.getString("wall.block_claimed")); + new BlockPattern(BlockUtil.get(config.getString("wall.block_claimed"))); // Dump world settings if (Settings.DEBUG) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java index 7df870508..1910fc07e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java @@ -2,14 +2,13 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.util.MathMan; -import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockTypes; public class HybridGen extends IndependentPlotGenerator { @@ -35,37 +34,6 @@ public class HybridGen extends IndependentPlotGenerator { } } - @Override public BlockBucket[][] generateBlockBucketChunk(PlotArea settings) { - BlockBucket[][] blockBuckets = new BlockBucket[16][]; - HybridPlotWorld hpw = (HybridPlotWorld) settings; - // Bedrock - if (hpw.PLOT_BEDROCK) { - for (short x = 0; x < 16; x++) { - for (short z = 0; z < 16; z++) { - blockBuckets[0][(z << 4) | x] = - BlockBucket.withSingle(BlockUtil.get("bedrock")); - } - } - } - for (short x = 0; x < 16; x++) { - for (short z = 0; z < 16; z++) { - for (int y = 1; y < hpw.PLOT_HEIGHT; y++) { - int layer = y >> 4; - if (blockBuckets[layer] == null) { - blockBuckets[layer] = new BlockBucket[4096]; - } - blockBuckets[layer][((y & 0xF) << 8) | (z << 4) | x] = hpw.MAIN_BLOCK; - } - int layer = hpw.PLOT_HEIGHT >> 4; - if (blockBuckets[layer] == null) { - blockBuckets[layer] = new BlockBucket[4096]; - } - blockBuckets[layer][((hpw.PLOT_HEIGHT & 0xF) << 8) | (z << 4) | x] = hpw.MAIN_BLOCK; - } - } - return blockBuckets; - } - @Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings) { HybridPlotWorld hpw = (HybridPlotWorld) settings; // Biome @@ -74,7 +42,7 @@ public class HybridGen extends IndependentPlotGenerator { if (hpw.PLOT_BEDROCK) { for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { - result.setBlock(x, 0, z, BlockUtil.get("bedrock")); + result.setBlock(x, 0, z, BlockTypes.BEDROCK.getDefaultState()); } } } @@ -128,7 +96,7 @@ public class HybridGen extends IndependentPlotGenerator { for (short z = 0; z < 16; z++) { // Road for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) { - result.setBlock(x, y, z, hpw.ROAD_BLOCK.getBlock()); + result.setBlock(x, y, z, hpw.ROAD_BLOCK); } if (hpw.ROAD_SCHEMATIC_ENABLED) { placeSchem(hpw, result, rx[x], rz[z], x, z, true); @@ -139,7 +107,7 @@ public class HybridGen extends IndependentPlotGenerator { if (gz[z]) { // road for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) { - result.setBlock(x, y, z, hpw.ROAD_BLOCK.getBlock()); + result.setBlock(x, y, z, hpw.ROAD_BLOCK); } if (hpw.ROAD_SCHEMATIC_ENABLED) { placeSchem(hpw, result, rx[x], rz[z], x, z, true); @@ -147,10 +115,10 @@ public class HybridGen extends IndependentPlotGenerator { } else { // wall for (int y = 1; y <= hpw.WALL_HEIGHT; y++) { - result.setBlock(x, y, z, hpw.WALL_FILLING.getBlock()); + result.setBlock(x, y, z, hpw.WALL_FILLING); } if (!hpw.ROAD_SCHEMATIC_ENABLED) { - result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK.getBlock()); + result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK); } else { placeSchem(hpw, result, rx[x], rz[z], x, z, true); } @@ -161,7 +129,7 @@ public class HybridGen extends IndependentPlotGenerator { if (gz[z]) { // road for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) { - result.setBlock(x, y, z, hpw.ROAD_BLOCK.getBlock()); + result.setBlock(x, y, z, hpw.ROAD_BLOCK); } if (hpw.ROAD_SCHEMATIC_ENABLED) { placeSchem(hpw, result, rx[x], rz[z], x, z, true); @@ -169,19 +137,19 @@ public class HybridGen extends IndependentPlotGenerator { } else if (wz[z]) { // wall for (int y = 1; y <= hpw.WALL_HEIGHT; y++) { - result.setBlock(x, y, z, hpw.WALL_FILLING.getBlock()); + result.setBlock(x, y, z, hpw.WALL_FILLING); } if (!hpw.ROAD_SCHEMATIC_ENABLED) { - result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK.getBlock()); + result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK); } else { placeSchem(hpw, result, rx[x], rz[z], x, z, true); } } else { // plot for (int y = 1; y < hpw.PLOT_HEIGHT; y++) { - result.setBlock(x, y, z, hpw.MAIN_BLOCK.getBlock()); + result.setBlock(x, y, z, hpw.MAIN_BLOCK); } - result.setBlock(x, hpw.PLOT_HEIGHT, z, hpw.TOP_BLOCK.getBlock()); + result.setBlock(x, hpw.PLOT_HEIGHT, z, hpw.TOP_BLOCK); if (hpw.PLOT_SCHEMATIC) { placeSchem(hpw, result, rx[x], rz[z], x, z, false); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java index 0ab0947a4..06550a3cb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java @@ -3,7 +3,6 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.commands.Template; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.FileBytes; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; @@ -12,10 +11,12 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; -import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; 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.world.BlockUtil; import com.google.common.collect.Sets; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; @@ -173,8 +174,8 @@ public class HybridPlotManager extends ClassicPlotManager { final boolean canRegen = (hybridPlotWorld.TYPE == 0) && (hybridPlotWorld.TERRAIN == 0) && REGENERATIVE_CLEAR; // The component blocks - final BlockBucket plotfloor = hybridPlotWorld.TOP_BLOCK; - final BlockBucket filling = hybridPlotWorld.MAIN_BLOCK; + final Pattern plotfloor = hybridPlotWorld.TOP_BLOCK; + final Pattern filling = hybridPlotWorld.MAIN_BLOCK; final BlockState bedrock; if (hybridPlotWorld.PLOT_BEDROCK) { bedrock = BlockUtil.get((short) 7, (byte) 0); @@ -182,7 +183,7 @@ public class HybridPlotManager extends ClassicPlotManager { bedrock = BlockUtil.get((short) 0, (byte) 0); } final BlockState air = BlockUtil.get((short) 0, (byte) 0); - final String biome = hybridPlotWorld.PLOT_BIOME; + final BiomeType biome = hybridPlotWorld.PLOT_BIOME; final LocalBlockQueue queue = hybridPlotWorld.getQueue(false); ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override public void run(int[] value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java index f397c3fc2..db3df521a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java @@ -10,21 +10,26 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.object.PlotManager; -import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import com.github.intellectualsites.plotsquared.plot.util.block.ChunkBlockQueue; 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.expiry.PlotAnalysis; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.block.BlockTypes; import java.io.File; import java.util.ArrayDeque; @@ -46,8 +51,190 @@ public abstract class HybridUtils { public static PlotArea area; public static boolean UPDATE = false; - public abstract void analyzeRegion(String world, CuboidRegion region, - RunnableVal whenDone); + public void analyzeRegion(final String world, final CuboidRegion region, final RunnableVal whenDone) { + // int diff, int variety, int vertices, int rotation, int height_sd + /* + * diff: compare to base by looping through all blocks + * variety: add to HashSet for each BlockState + * height_sd: loop over all blocks and get top block + * + * vertices: store air map and compare with neighbours + * for each block check the adjacent + * - Store all blocks then go through in second loop + * - recheck each block + * + */ + TaskManager.runTaskAsync(() -> { + final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); + + final BlockVector3 bot = region.getMinimumPoint(); + final BlockVector3 top = region.getMaximumPoint(); + + final int bx = bot.getX(); + final int bz = bot.getZ(); + final int tx = top.getX(); + final int tz = top.getZ(); + final int cbx = bx >> 4; + final int cbz = bz >> 4; + final int ctx = tx >> 4; + final int ctz = tz >> 4; + MainUtil.initCache(); + final int width = tx - bx + 1; + final int length = tz - bz + 1; + + PlotArea area = PlotSquared.get().getPlotArea(world, null); + + if (!(area instanceof HybridPlotWorld)) { + return; + } + + HybridPlotWorld hpw = (HybridPlotWorld) area; + ChunkBlockQueue chunk = new ChunkBlockQueue(bot, top, false); + hpw.getGenerator().generateChunk(chunk, hpw); + + final BlockState[][][] oldBlocks = chunk.getBlocks(); + final BlockState[][][] newBlocks = new BlockState[256][width][length]; + final BlockState airBlock = BlockTypes.AIR.getDefaultState(); + + System.gc(); + System.gc(); + + final Runnable run = () -> TaskManager.runTaskAsync(() -> { + int size = width * length; + int[] changes = new int[size]; + int[] faces = new int[size]; + int[] data = new int[size]; + int[] air = new int[size]; + int[] variety = new int[size]; + int i = 0; + for (int x = 0; x < width; x++) { + for (int z = 0; z < length; z++) { + Set types = new HashSet<>(); + for (int y = 0; y < 256; y++) { + BlockState old = oldBlocks[y][x][z]; + try { + if (old == null) { + old = airBlock; + } + BlockState now = newBlocks[y][x][z]; + if (!old.equals(now)) { + changes[i]++; + } + if (now.getBlockType().getMaterial().isAir()) { + air[i]++; + } else { + // check vertices + // modifications_adjacent + if (x > 0 && z > 0 && y > 0 && x < width - 1 && z < length - 1 + && y < 255) { + if (newBlocks[y - 1][x][z].getBlockType().getMaterial().isAir()) { + faces[i]++; + } + if (newBlocks[y][x - 1][z].getBlockType().getMaterial().isAir()) { + faces[i]++; + } + if (newBlocks[y][x][z - 1].getBlockType().getMaterial().isAir()) { + faces[i]++; + } + if (newBlocks[y + 1][x][z].getBlockType().getMaterial().isAir()) { + faces[i]++; + } + if (newBlocks[y][x + 1][z].getBlockType().getMaterial().isAir()) { + faces[i]++; + } + if (newBlocks[y][x][z + 1].getBlockType().getMaterial().isAir()) { + faces[i]++; + } + } + + if (!now.equals(now.getBlockType().getDefaultState())) { + data[i]++; + } + types.add(now.getBlockType()); + } + } catch (NullPointerException e) { + e.printStackTrace(); + } + } + variety[i] = types.size(); + i++; + } + } + // analyze plot + // put in analysis obj + + // run whenDone + PlotAnalysis analysis = new PlotAnalysis(); + analysis.changes = (int) (MathMan.getMean(changes) * 100); + analysis.faces = (int) (MathMan.getMean(faces) * 100); + analysis.data = (int) (MathMan.getMean(data) * 100); + analysis.air = (int) (MathMan.getMean(air) * 100); + analysis.variety = (int) (MathMan.getMean(variety) * 100); + + analysis.changes_sd = (int) (MathMan.getSD(changes, analysis.changes) * 100); + analysis.faces_sd = (int) (MathMan.getSD(faces, analysis.faces) * 100); + analysis.data_sd = (int) (MathMan.getSD(data, analysis.data) * 100); + analysis.air_sd = (int) (MathMan.getSD(air, analysis.air) * 100); + analysis.variety_sd = (int) (MathMan.getSD(variety, analysis.variety) * 100); + System.gc(); + System.gc(); + whenDone.value = analysis; + whenDone.run(); + }); + System.gc(); + MainUtil.initCache(); + Location botLoc = new Location(world, bot.getX(), bot.getY(), bot.getZ()); + Location topLoc = new Location(world, top.getX(), top.getY(), top.getZ()); + ChunkManager.chunkTask(botLoc, topLoc, new RunnableVal() { + @Override public void run(int[] value) { + int X = value[0]; + int Z = value[1]; + int minX; + if (X == cbx) { + minX = bx & 15; + } else { + minX = 0; + } + int minZ; + if (Z == cbz) { + minZ = bz & 15; + } else { + minZ = 0; + } + int maxX; + if (X == ctx) { + maxX = tx & 15; + } else { + maxX = 16; + } + int maxZ; + if (Z == ctz) { + maxZ = tz & 15; + } else { + maxZ = 16; + } + + int cbx = X << 4; + int cbz = Z << 4; + + int xb = cbx - bx; + int zb = cbz - bz; + for (int x = minX; x <= maxX; x++) { + int xx = cbx + x; + for (int z = minZ; z <= maxZ; z++) { + int zz = cbz + z; + for (int y = 0; y < 256; y++) { + BlockState block = queue.getBlock(xx, y, zz); + int xr = xb + x; + int zr = zb + z; + newBlocks[y][xr][zr] = block; + } + } + } + } + }, () -> TaskManager.runTaskAsync(run), 5); + }); + } public void analyzePlot(final Plot origin, final RunnableVal whenDone) { final ArrayDeque zones = new ArrayDeque<>(origin.getRegions()); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java index def532368..1467dc1dd 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java @@ -1,7 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.object.SetupObject; @@ -19,14 +18,6 @@ public abstract class IndependentPlotGenerator { */ public abstract String getName(); - /** - * Generates a 16x4096 array of BlockBuckets corresponding to the area settings to allow for plot analysis - * - * @param settings - * @return - */ - public abstract BlockBucket[][] generateBlockBucketChunk(PlotArea settings); - /** * Use the setBlock or setBiome method of the PlotChunk result parameter to make changes. * The PlotArea settings is the same one this was initialized with. diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/SquarePlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/SquarePlotManager.java index b05249d39..eeda6d06e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/SquarePlotManager.java @@ -6,12 +6,11 @@ import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotId; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.sk89q.worldedit.regions.CuboidRegion; import java.util.Arrays; -import java.util.HashSet; import java.util.Iterator; import java.util.Set; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java index 7426b99c8..ef9b25406 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java @@ -20,8 +20,8 @@ import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; -import com.github.intellectualsites.plotsquared.plot.util.world.ItemUtil; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; +import com.github.intellectualsites.plotsquared.plot.util.world.ItemUtil; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/ProcessedWEExtent.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/ProcessedWEExtent.java index f72fb0520..fc7f95d11 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/ProcessedWEExtent.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/ProcessedWEExtent.java @@ -3,7 +3,6 @@ package com.github.intellectualsites.plotsquared.plot.listener; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -12,6 +11,7 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; @@ -19,7 +19,6 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.lang.reflect.Field; -import java.util.HashSet; import java.util.Set; public class ProcessedWEExtent extends AbstractDelegateExtent { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEExtent.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEExtent.java index ea9f404b8..c9a414ed0 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEExtent.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEExtent.java @@ -1,6 +1,5 @@ package com.github.intellectualsites.plotsquared.plot.listener; -import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -8,6 +7,7 @@ import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; @@ -15,7 +15,6 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; -import java.util.HashSet; import java.util.Set; public class WEExtent extends AbstractDelegateExtent { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WESubscriber.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WESubscriber.java index a56063d08..9991e8286 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WESubscriber.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WESubscriber.java @@ -5,7 +5,6 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.sk89q.worldedit.WorldEdit; @@ -13,12 +12,12 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.NullExtent; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.eventbus.EventHandler.Priority; import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.world.World; -import java.util.HashSet; import java.util.Set; public class WESubscriber { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java index 43b519fc3..8a4e784b3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java @@ -4,6 +4,12 @@ import com.github.intellectualsites.plotsquared.configuration.serialization.Conf import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.object.collection.RandomCollection; import com.google.common.collect.ImmutableMap; +import com.sk89q.worldedit.extent.NullExtent; +import com.sk89q.worldedit.function.mask.BlockMask; +import com.sk89q.worldedit.function.pattern.BlockPattern; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.function.pattern.RandomPattern; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import lombok.EqualsAndHashCode; @@ -17,9 +23,11 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Random; +import java.util.stream.Collectors; /** * A block bucket is a container of block types, where each block @@ -37,6 +45,8 @@ import java.util.Random; private RandomCollection randomBlocks; private BlockState single; + private Pattern pattern; + private BlockMask mask; public BlockBucket() { this.blocks = new HashMap<>(); @@ -84,9 +94,7 @@ import java.util.Random; * be found in the bucket */ public Collection getBlocks() { - if (!isCompiled()) { - this.compile(); - } + this.compile(); return Collections.unmodifiableCollection(this.blocks.keySet()); } @@ -126,20 +134,31 @@ import java.util.Random; if (isCompiled()) { return; } - this.compiled = true; switch (blocks.size()) { case 0: single = null; this.randomBlocks = null; + this.pattern = null; + this.mask = new BlockMask(new NullExtent()); break; case 1: single = blocks.keySet().iterator().next(); this.randomBlocks = null; + this.pattern = new BlockPattern(single); + this.mask = new BlockMask(new NullExtent(), single.toBaseBlock()); break; default: single = null; this.randomBlocks = RandomCollection.of(blocks, random); + RandomPattern randomPattern = new RandomPattern(); + for (Entry entry : this.blocks.entrySet()) { + randomPattern.add(new BlockPattern(entry.getKey()), entry.getValue()); + } + this.pattern = randomPattern; + List baseBlocks = getBlocks().stream().map(BlockState::toBaseBlock) + .collect(Collectors.toList()); + this.mask = new BlockMask(new NullExtent(), baseBlocks); break; } } @@ -170,6 +189,16 @@ import java.util.Random; return BlockTypes.AIR.getDefaultState(); } + public Pattern getPattern() { + this.compile(); + return this.pattern; + } + + public BlockMask getMask() { + this.compile(); + return this.mask; + } + @Override public String toString() { if (!isCompiled()) { compile(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java index ae9fffb89..c9b7ab5e7 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java @@ -5,7 +5,6 @@ import com.github.intellectualsites.plotsquared.plot.commands.RequiredType; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode; import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; -import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.item.ItemType; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 67fe23387..65bb23809 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -22,18 +22,21 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; -import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; 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.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis; +import com.github.intellectualsites.plotsquared.plot.util.world.PatternUtil; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.block.BlockTypes; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -921,7 +924,7 @@ public class Plot { * @param biome The biome e.g. "forest" * @param whenDone The task to run when finished, or null */ - public void setBiome(final String biome, final Runnable whenDone) { + public void setBiome(final BiomeType biome, final Runnable whenDone) { final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); final int extendBiome; if (area instanceof SquarePlotWorld) { @@ -1459,7 +1462,7 @@ public class Plot { } Location location = manager.getSignLoc(this); LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(getWorldName(), false); - queue.setBlock(location.getX(), location.getY(), location.getZ(), BlockUtil.get("air")); + queue.setBlock(location.getX(), location.getY(), location.getZ(), BlockTypes.AIR.getDefaultState()); queue.flush(); } @@ -1588,9 +1591,13 @@ public class Plot { * Sets components such as border, wall, floor. * (components are generator specific) */ + @Deprecated public boolean setComponent(String component, String blocks) { BlockBucket parsed = Configuration.BLOCK_BUCKET.parseString(blocks); - return !(parsed == null || parsed.isEmpty()) && this.setComponent(component, parsed); + if (parsed != null && parsed.isEmpty()) { + return false; + } + return this.setComponent(component, parsed.getPattern()); } /** @@ -1598,7 +1605,7 @@ public class Plot { * * @return the name of the biome */ - public String getBiome() { + public BiomeType getBiome() { Location location = this.getCenter(); return WorldUtil.IMP.getBiome(location.getWorld(), location.getX(), location.getZ()); } @@ -2856,7 +2863,7 @@ public class Plot { * @param blocks * @return */ - public boolean setComponent(String component, BlockBucket blocks) { + public boolean setComponent(String component, Pattern blocks) { if (StringMan .isEqualToAny(component, getManager().getPlotComponents(this.getId()))) { EventUtil.manager.callComponentSet(this, component); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java index 970c427b8..0cefe8283 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java @@ -25,6 +25,8 @@ import com.google.common.collect.ImmutableSet; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,14 +56,13 @@ public abstract class PlotArea { private final PlotId min; private final PlotId max; @NotNull private final IndependentPlotGenerator generator; - private final BlockBucket[][] blockBucketChunk; public int MAX_PLOT_MEMBERS = 128; public boolean AUTO_MERGE = false; public boolean ALLOW_SIGNS = true; public boolean MISC_SPAWN_UNOWNED = false; public boolean MOB_SPAWNING = false; public boolean MOB_SPAWNER_SPAWNING = false; - public String PLOT_BIOME = "FOREST"; + public BiomeType PLOT_BIOME = BiomeTypes.FOREST; public boolean PLOT_CHAT = false; public boolean SCHEMATIC_CLAIM_SPECIFY = false; public boolean SCHEMATIC_ON_CLAIM = false; @@ -106,11 +107,6 @@ public abstract class PlotArea { this.max = max; } this.worldhash = worldName.hashCode(); - if (Settings.Enabled_Components.PLOT_EXPIRY) { - blockBucketChunk = generator.generateBlockBucketChunk(this); - } else { - blockBucketChunk = null; - } } @NotNull protected abstract PlotManager createManager(); @@ -119,18 +115,6 @@ public abstract class PlotArea { return GlobalBlockQueue.IMP.getNewQueue(worldname, autoQueue); } - /** - * Get an array of BlockBuckets corresponding to a chunk of a plot - * - * @return BlockBucket[][] - */ - public BlockBucket[][] getBlockBucketChunk() { - if (blockBucketChunk != null) { - return blockBucketChunk; - } - return generator.generateBlockBucketChunk(this); - } - /** * Returns the region for this PlotArea or a CuboidRegion encompassing * the whole world if none exists. diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java index 8f50f3504..e0fc16ddb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java @@ -2,6 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.object; import com.github.intellectualsites.plotsquared.plot.commands.Template; import com.github.intellectualsites.plotsquared.plot.config.Settings; +import com.sk89q.worldedit.function.pattern.Pattern; import java.io.IOException; import java.util.Collections; @@ -53,7 +54,7 @@ public abstract class PlotManager { */ public abstract String[] getPlotComponents(PlotId plotId); - public abstract boolean setComponent(PlotId plotId, String component, BlockBucket blocks); + public abstract boolean setComponent(PlotId plotId, String component, Pattern blocks); /* * PLOT MERGING (return false if your generator does not support plot diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java index 0191b53df..c504af4fb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DefaultPlotAreaManager.java @@ -2,9 +2,9 @@ package com.github.intellectualsites.plotsquared.plot.object.worlds; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.area.QuadMap; +import com.sk89q.worldedit.regions.CuboidRegion; import java.util.ArrayList; import java.util.Arrays; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlot.java index 788e7a99a..1a8c88b9f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlot.java @@ -10,7 +10,6 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; -import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import java.util.Collection; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java index d35257b9b..e54ab6964 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java @@ -2,9 +2,9 @@ package com.github.intellectualsites.plotsquared.plot.object.worlds; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.ArrayUtil; import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; +import com.sk89q.worldedit.regions.CuboidRegion; public class SinglePlotAreaManager extends DefaultPlotAreaManager { private final SinglePlotArea[] array; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java index 49d3788d5..d2aa10499 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java @@ -1,7 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.object.worlds; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; @@ -10,6 +9,7 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.sk89q.worldedit.function.pattern.Pattern; import java.io.File; import java.util.List; @@ -69,7 +69,7 @@ public class SinglePlotManager extends PlotManager { } @Override public boolean setComponent(PlotId plotId, String component, - BlockBucket blocks) { + Pattern blocks) { return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java index 0042ca222..89069173f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java @@ -2,12 +2,12 @@ package com.github.intellectualsites.plotsquared.plot.object.worlds; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; -import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotId; -import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; +import com.sk89q.worldedit.world.biome.BiomeTypes; +import com.sk89q.worldedit.world.block.BlockTypes; public class SingleWorldGenerator extends IndependentPlotGenerator { private Location bedrock1 = new Location(null, 0, 0, 0); @@ -21,64 +21,19 @@ public class SingleWorldGenerator extends IndependentPlotGenerator { return "PlotSquared:single"; } - @Override public BlockBucket[][] generateBlockBucketChunk(PlotArea settings) { - BlockBucket[][] blockBuckets = new BlockBucket[16][]; - SinglePlotArea area = (SinglePlotArea) settings; - if (area.VOID) { - return blockBuckets; - } - for (int x = bedrock1.getX(); x <= bedrock2.getX(); x++) { - for (int z = bedrock1.getZ(); z <= bedrock2.getZ(); z++) { - for (int y = bedrock1.getY(); y <= bedrock2.getY(); y++) { - int layer = y >> 4; - if (blockBuckets[layer] == null) { - blockBuckets[layer] = new BlockBucket[4096]; - } - blockBuckets[layer][((y & 0xF) << 8) | (z << 4) | x] = - BlockBucket.withSingle(BlockUtil.get("bedrock")); - } - } - } - for (int x = dirt1.getX(); x <= dirt2.getX(); x++) { - for (int z = dirt1.getZ(); z <= dirt2.getZ(); z++) { - for (int y = dirt1.getY(); y <= dirt2.getY(); y++) { - int layer = y >> 4; - if (blockBuckets[layer] == null) { - blockBuckets[layer] = new BlockBucket[4096]; - } - blockBuckets[layer][((y & 0xF) << 8) | (z << 4) | x] = - BlockBucket.withSingle(BlockUtil.get("dirt")); - } - } - } - for (int x = grass1.getX(); x <= grass2.getX(); x++) { - for (int z = grass1.getZ(); z <= grass2.getZ(); z++) { - for (int y = grass1.getY(); y <= grass2.getY(); y++) { - int layer = y >> 4; - if (blockBuckets[layer] == null) { - blockBuckets[layer] = new BlockBucket[4096]; - } - blockBuckets[layer][((y & 0xF) << 8) | (z << 4) | x] = - BlockBucket.withSingle(BlockUtil.get("grass_block")); - } - } - } - return blockBuckets; - } - @Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings) { SinglePlotArea area = (SinglePlotArea) settings; if (area.VOID) { Location min = result.getMin(); if (min.getX() == 0 && min.getZ() == 0) { - result.setBlock(0, 0, 0, BlockUtil.get("bedrock")); + result.setBlock(0, 0, 0, BlockTypes.BEDROCK.getDefaultState()); } } else { - result.setCuboid(bedrock1, bedrock2, BlockUtil.get("bedrock")); - result.setCuboid(dirt1, dirt2, BlockUtil.get("dirt")); - result.setCuboid(grass1, grass2, BlockUtil.get("grass_block")); + result.setCuboid(bedrock1, bedrock2, BlockTypes.BEDROCK.getDefaultState()); + result.setCuboid(dirt1, dirt2, BlockTypes.DIRT.getDefaultState()); + result.setCuboid(grass1, grass2, BlockTypes.GRASS_BLOCK.getDefaultState()); } - result.fillBiome("PLAINS"); + result.fillBiome(BiomeTypes.PLAINS); } @Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java index be8a79207..c4df0f04b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ChunkManager.java @@ -3,12 +3,12 @@ package com.github.intellectualsites.plotsquared.plot.util; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; 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 com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.regions.CuboidRegion; import java.io.File; import java.util.ArrayList; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java index d06beab3f..b224e201a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java @@ -16,12 +16,13 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.sk89q.worldedit.math.BlockVector2; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.stream.AbstractDelegateOutputStream; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.biome.BiomeType; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -46,6 +47,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.UUID; @@ -217,10 +219,9 @@ public class MainUtil { * @return true if any changes were made */ public static boolean resetBiome(PlotArea area, Location pos1, Location pos2) { - String biome = area.PLOT_BIOME; - if (!StringMan.isEqual(WorldUtil.IMP - .getBiome(area.worldname, (pos1.getX() + pos2.getX()) / 2, - (pos1.getZ() + pos2.getZ()) / 2), biome)) { + BiomeType biome = area.PLOT_BIOME; + if (!Objects.equals(WorldUtil.IMP.getBiome(area.worldname, (pos1.getX() + pos2.getX()) / 2, + (pos1.getZ() + pos2.getZ()) / 2), biome)) { MainUtil.setBiome(area.worldname, pos1.getX(), pos1.getZ(), pos2.getX(), pos2.getZ(), biome); return true; @@ -567,7 +568,7 @@ public class MainUtil { * @param p2z * @param biome */ - public static void setBiome(String world, int p1x, int p1z, int p2x, int p2z, String biome) { + public static void setBiome(String world, int p1x, int p1z, int p2x, int p2z, BiomeType biome) { BlockVector3 pos1 = BlockVector2.at(p1x, p1z).toBlockVector3(); BlockVector3 pos2 = BlockVector2.at(p2x, p2z).toBlockVector3(Plot.MAX_HEIGHT - 1); CuboidRegion region = new CuboidRegion(pos1, pos2); @@ -750,7 +751,7 @@ public class MainUtil { int num = plot.getConnectedPlots().size(); String alias = !plot.getAlias().isEmpty() ? plot.getAlias() : Captions.NONE.getTranslated(); Location bot = plot.getCorners()[0]; - String biome = WorldUtil.IMP.getBiome(plot.getWorldName(), bot.getX(), bot.getZ()); + BiomeType biome = WorldUtil.IMP.getBiome(plot.getWorldName(), bot.getX(), bot.getZ()); String trusted = getPlayerList(plot.getTrusted()); String members = getPlayerList(plot.getMembers()); String denied = getPlayerList(plot.getDenied()); @@ -798,7 +799,7 @@ public class MainUtil { info = info.replace("%alias%", alias); info = info.replace("%num%", String.valueOf(num)); info = info.replace("%desc%", description); - info = info.replace("%biome%", biome); + info = info.replace("%biome%", biome.toString().toLowerCase()); info = info.replace("%owner%", owner); info = info.replace("%members%", members); info = info.replace("%player%", player.getName()); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java index 75f8d79f0..64477915b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java @@ -10,7 +10,6 @@ import com.github.intellectualsites.plotsquared.plot.generator.ClassicPlotWorld; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.schematic.Schematic; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; @@ -27,6 +26,7 @@ import com.sk89q.worldedit.extent.clipboard.io.MCEditSchematicReader; import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.block.BaseBlock; import org.jetbrains.annotations.NotNull; 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 52be1a312..099b9ea34 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 @@ -4,7 +4,6 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem; import com.sk89q.jnbt.CompoundTag; @@ -13,6 +12,8 @@ import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockState; import java.io.ByteArrayOutputStream; @@ -32,10 +33,6 @@ import java.util.zip.ZipOutputStream; public abstract class WorldUtil { public static WorldUtil IMP; - public abstract int getBiomeFromString(String value); - - public abstract String[] getBiomeList(); - public abstract String getMainWorld(); public abstract boolean isWorld(String worldName); @@ -56,7 +53,7 @@ public abstract class WorldUtil { public abstract StringComparison.ComparisonResult getClosestBlock(String name); - public abstract String getBiome(String world, int x, int z); + public abstract BiomeType getBiome(String world, int x, int z); public abstract BlockState getBlock(Location location); @@ -66,7 +63,7 @@ public abstract class WorldUtil { public abstract void setSign(String world, int x, int y, int z, String[] lines); - public abstract void setBiomes(String world, CuboidRegion region, String biome); + public abstract void setBiomes(String world, CuboidRegion region, BiomeType biome); public abstract com.sk89q.worldedit.world.World getWeWorld(String world); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java index 08bfab890..72b6252a3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java @@ -4,6 +4,9 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.world.PatternUtil; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import org.jetbrains.annotations.NotNull; @@ -85,6 +88,10 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { this.modified = modified; } + @Override public boolean setBlock(int x, int y, int z, Pattern pattern) { + return setBlock(x, y, z, PatternUtil.apply(pattern, x, y, z)); + } + @Override public boolean setBlock(int x, int y, int z, BaseBlock id) { if ((y > 255) || (y < 0)) { return false; @@ -118,7 +125,7 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { return setBlock(x, y, z, id.toBaseBlock()); } - @Override public final boolean setBiome(int x, int z, String biome) { + @Override public final boolean setBiome(int x, int z, BiomeType biomeType) { long pair = (long) (x >> 4) << 32 | (z >> 4) & 0xFFFFFFFFL; LocalChunk result = this.blockChunks.get(pair); if (result == null) { @@ -131,7 +138,7 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { chunks.add(result); } } - result.setBiome(x & 15, z & 15, biome); + result.setBiome(x & 15, z & 15, biomeType); return true; } @@ -160,7 +167,7 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { public final int x; public BaseBlock[][] baseblocks; - public String[][] biomes; + public BiomeType[][] biomes; public LocalChunk(BasicLocalBlockQueue parent, int x, int z) { this.parent = parent; @@ -187,15 +194,15 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { public abstract void setBlock(final int x, final int y, final int z, final BaseBlock block); - public void setBiome(int x, int z, String biome) { + public void setBiome(int x, int z, BiomeType biomeType) { if (this.biomes == null) { - this.biomes = new String[16][]; + this.biomes = new BiomeType[16][]; } - String[] index = this.biomes[x]; + BiomeType[] index = this.biomes[x]; if (index == null) { - index = this.biomes[x] = new String[16]; + index = this.biomes[x] = new BiomeType[16]; } - index[z] = biome; + index[z] = biomeType; } public long longHash() { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ChunkBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ChunkBlockQueue.java new file mode 100644 index 000000000..47e2c8756 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ChunkBlockQueue.java @@ -0,0 +1,95 @@ +package com.github.intellectualsites.plotsquared.plot.util.block; + +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; + +import java.util.Arrays; + +public class ChunkBlockQueue extends ScopedLocalBlockQueue { + + public final BiomeType[] biomeGrid; + public final BlockState[][][] result; + private final int width; + private final int length; + private final int area; + private final BlockVector3 bot; + private final BlockVector3 top; + + public ChunkBlockQueue(BlockVector3 bot, BlockVector3 top, boolean biomes) { + super(null, new Location(null, 0, 0, 0), new Location(null, 15, 255, 15)); + this.width = top.getX() - bot.getX()+ 1; + this.length = top.getZ() - bot.getZ() + 1; + this.area = width * length; + this.result = new BlockState[256][][]; + this.biomeGrid = biomes ? new BiomeType[width * length] : null; + this.bot = bot; + this.top = top; + } + + public BlockState[][][] getBlocks() { + return result; + } + + @Override public void fillBiome(BiomeType biomeType) { + if (biomeGrid == null) { + return; + } + Arrays.fill(biomeGrid, biomeType); + } + + @Override public boolean setBiome(int x, int z, BiomeType biomeType) { + if (this.biomeGrid != null) { + biomeGrid[(z * width) + x] = biomeType; + return true; + } + return false; + } + + @Override public boolean setBlock(int x, int y, int z, BlockState id) { + this.storeCache(x, y, z, id); + return true; + } + + private void storeCache(final int x, final int y, final int z, final BlockState id) { + BlockState[][] resultY = result[y]; + if (resultY == null) { + result[y] = resultY = new BlockState[length][]; + } + BlockState[] resultYZ = resultY[z]; + if (resultYZ == null) { + resultY[z] = resultYZ = new BlockState[width]; + } + resultYZ[x] = id; + } + + @Override public boolean setBlock(int x, int y, int z, BaseBlock id) { + this.storeCache(x, y, z, id.toImmutableState()); + return true; + } + + @Override public BlockState getBlock(int x, int y, int z) { + BlockState[][] blocksY = result[y]; + if (blocksY != null) { + BlockState[] blocksYZ = blocksY[z]; + if (blocksYZ != null) { + return blocksYZ[x]; + } + } + return null; + } + + @Override public String getWorld() { + return null; + } + + @Override public Location getMax() { + return new Location(getWorld(), top.getX(), top.getY(), top.getZ()); + } + + @Override public Location getMin() { + return new Location(getWorld(), bot.getX(), bot.getY(), bot.getZ()); + } +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java index cf695f3d6..78e706b6b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java @@ -1,5 +1,7 @@ package com.github.intellectualsites.plotsquared.plot.util.block; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -58,6 +60,10 @@ public class DelegateLocalBlockQueue extends LocalBlockQueue { } } + @Override public boolean setBlock(int x, int y, int z, Pattern pattern) { + return parent.setBlock(x, y, z, pattern); + } + @Override public boolean setBlock(int x, int y, int z, BaseBlock id) { return parent.setBlock(x, y, z, id); } @@ -70,7 +76,7 @@ public class DelegateLocalBlockQueue extends LocalBlockQueue { return parent.getBlock(x, y, z); } - @Override public boolean setBiome(int x, int z, String biome) { + @Override public boolean setBiome(int x, int z, BiomeType biome) { return parent.setBiome(x, z, biome); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java index 572f70228..4778a1cae 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java @@ -1,14 +1,16 @@ package com.github.intellectualsites.plotsquared.plot.util.block; -import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.PatternUtil; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -57,6 +59,10 @@ public abstract class LocalBlockQueue { public abstract boolean setBlock(final int x, final int y, final int z, final BaseBlock id); + public boolean setBlock(final int x, final int y, final int z, final Pattern pattern) { + return setBlock(x, y, z, PatternUtil.apply(pattern, x, y, z)); + } + public boolean setTile(int x, int y, int z, CompoundTag tag) { SchematicHandler.manager.restoreTile(this, tag, x, y, z); return true; @@ -64,7 +70,7 @@ public abstract class LocalBlockQueue { public abstract BlockState getBlock(int x, int y, int z); - public abstract boolean setBiome(int x, int z, String biome); + public abstract boolean setBiome(int x, int z, BiomeType biome); public abstract String getWorld(); @@ -116,7 +122,7 @@ public abstract class LocalBlockQueue { } } - public void setCuboid(Location pos1, Location pos2, BlockBucket blocks) { + public void setCuboid(Location pos1, Location pos2, Pattern blocks) { int yMin = Math.min(pos1.getY(), pos2.getY()); int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY())); int xMin = Math.min(pos1.getX(), pos2.getX()); @@ -126,7 +132,7 @@ public abstract class LocalBlockQueue { for (int y = yMin; y <= yMax; y++) { for (int x = xMin; x <= xMax; x++) { for (int z = zMin; z <= zMax; z++) { - setBlock(x, y, z, blocks.getBlock()); + setBlock(x, y, z, blocks); } } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/OffsetLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/OffsetLocalBlockQueue.java index d0a561111..37ac7fe5c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/OffsetLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/OffsetLocalBlockQueue.java @@ -1,5 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.util.block; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; public class OffsetLocalBlockQueue extends DelegateLocalBlockQueue { @@ -14,7 +15,7 @@ public class OffsetLocalBlockQueue extends DelegateLocalBlockQueue { this.oz = oz; } - @Override public boolean setBiome(int x, int y, String biome) { + @Override public boolean setBiome(int x, int y, BiomeType biome) { return super.setBiome(ox + x, oy + y, biome); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java index 416a2c36e..6a0e375c5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java @@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotManager; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -38,11 +39,11 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue { } - @Override public boolean setBiome(int x, int z, String biome) { + @Override public boolean setBiome(int x, int z, BiomeType biome) { return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBiome(x + minX, z + minZ, biome); } - public void fillBiome(String biome) { + public void fillBiome(BiomeType biome) { for (int x = 0; x <= dx; x++) { for (int z = 0; z < dz; z++) { setBiome(x, z, biome); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/OperationUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/OperationUtil.java index 05b969065..2cb336f52 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/OperationUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/OperationUtil.java @@ -1,11 +1,8 @@ package com.github.intellectualsites.plotsquared.plot.util.world; import com.github.intellectualsites.plotsquared.plot.object.Location; -import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/PatternUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/PatternUtil.java new file mode 100644 index 000000000..381cfc7f1 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/PatternUtil.java @@ -0,0 +1,66 @@ +package com.github.intellectualsites.plotsquared.plot.util.world; + +import com.github.intellectualsites.plotsquared.commands.Command; +import com.github.intellectualsites.plotsquared.plot.config.Captions; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extension.input.InputParseException; +import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.function.pattern.BlockPattern; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.function.pattern.RandomPattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; + +public class PatternUtil { + public static BaseBlock apply(Pattern pattern, int x, int y, int z) { + if (pattern instanceof BlockPattern + || pattern instanceof RandomPattern + || pattern instanceof BlockState + || pattern instanceof BlockType + || pattern instanceof BaseBlock) { + return pattern.apply(BlockVector3.ZERO); + } + return pattern.apply(BlockVector3.at(x, y, z)); + } + + public static Pattern parse(PlotPlayer plotPlayer, String input) { + Actor actor = plotPlayer.toActor(); + ParserContext context = new ParserContext(); + context.setActor(actor); + if (actor instanceof Player) { + context.setWorld(((Player) actor).getWorld()); + } + context.setSession(WorldEdit.getInstance().getSessionManager().get(actor)); + context.setRestricted(true); + context.setPreferringWildcard(false); + context.setTryLegacy(true); + try { + Pattern pattern = + WorldEdit.getInstance().getPatternFactory().parseFromInput(input, context); + return pattern; + } catch (InputParseException e) { + throw new Command.CommandException(Captions.NOT_VALID_BLOCK, e.getMessage()); + } + } + + public static boolean isAir(Pattern pattern) { + if (pattern instanceof BlockPattern) { + return ((BlockPattern) pattern).getBlock().getBlockType().getMaterial().isAir(); + } + if (pattern instanceof BlockState) { + return ((BlockState) pattern).getBlockType().getMaterial().isAir(); + } + if (pattern instanceof BlockType) { + return ((BlockType) pattern).getMaterial().isAir(); + } + if (pattern instanceof BaseBlock) { + return ((BaseBlock) pattern).getBlockType().getMaterial().isAir(); + } + return false; + } +}