From 88732bb88cd2f066654fdc17786cf9e9fe4f0c4a Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 4 Nov 2019 21:08:33 +0000 Subject: [PATCH] Use CuboidRegion instead of RegionWrapper --- .../plotsquared/bukkit/chat/Reflection.java | 8 +- .../generator/DelegatePlotGenerator.java | 2 +- .../bukkit/util/BukkitChunkManager.java | 41 +++--- .../bukkit/util/BukkitHybridUtils.java | 8 +- .../bukkit/util/BukkitSchematicHandler.java | 12 +- .../plotsquared/bukkit/util/BukkitUtil.java | 10 +- .../bukkit/util/block/BukkitLocalQueue.java | 2 +- .../bukkit/util/block/GenChunk.java | 2 +- .../plotsquared/plot/IPlotMain.java | 4 +- .../plotsquared/plot/PlotSquared.java | 4 +- .../plotsquared/plot/commands/Area.java | 11 +- .../plotsquared/plot/commands/Trim.java | 15 ++- .../plot/flag/BlockStateListFlag.java | 2 +- .../plot/generator/AugmentedUtils.java | 13 +- .../plot/generator/ClassicPlotManager.java | 34 ++--- .../plot/generator/ClassicPlotWorld.java | 2 +- .../plotsquared/plot/generator/HybridGen.java | 2 +- .../plot/generator/HybridPlotManager.java | 2 +- .../plot/generator/HybridUtils.java | 17 +-- .../plot/generator/SquarePlotManager.java | 13 +- .../plot/listener/PlotListener.java | 2 +- .../plot/listener/ProcessedWEExtent.java | 7 +- .../plotsquared/plot/listener/WEExtent.java | 7 +- .../plotsquared/plot/listener/WEManager.java | 51 ++++---- .../plot/listener/WESubscriber.java | 5 +- .../plot/object/ConsolePlayer.java | 7 +- .../plotsquared/plot/object/Location.java | 4 - .../plotsquared/plot/object/Plot.java | 121 +++++++++--------- .../plotsquared/plot/object/PlotArea.java | 36 +++--- .../plotsquared/plot/object/PlotCluster.java | 8 +- .../plot/object/RegionWrapper.java | 71 ---------- .../object/worlds/DefaultPlotAreaManager.java | 6 +- .../plot/object/worlds/PlotAreaManager.java | 4 +- .../plot/object/worlds/SinglePlot.java | 13 +- .../object/worlds/SinglePlotAreaManager.java | 4 +- .../object/worlds/SingleWorldGenerator.java | 2 +- .../plotsquared/plot/util/ChunkManager.java | 20 +-- .../plotsquared/plot/util/MainUtil.java | 22 +++- .../plot/util/SchematicHandler.java | 20 +-- .../plotsquared/plot/util/WorldUtil.java | 4 +- .../plotsquared/plot/util/area/QuadMap.java | 41 +++--- .../plot/util/{block => world}/BlockUtil.java | 2 +- .../plot/util/{block => world}/ItemUtil.java | 2 +- .../plot/util/world/RegionUtil.java | 40 ++++++ .../plotsquared/plot/FlagTest.java | 2 +- 45 files changed, 357 insertions(+), 348 deletions(-) delete mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/RegionWrapper.java rename Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/{block => world}/BlockUtil.java (97%) rename Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/{block => world}/ItemUtil.java (94%) create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/RegionUtil.java diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/Reflection.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/Reflection.java index 717e164ee..ebe7e81b3 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/Reflection.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/Reflection.java @@ -22,7 +22,7 @@ public final class Reflection { /** * Stores loaded classes from the {@code org.bukkit.craftbukkit} package (and subpackages). -import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; */ private static final Map> _loadedOBCClasses = new HashMap<>(); private static final Map, Map> _loadedFields = new HashMap<>(); @@ -40,10 +40,10 @@ import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; /** * Gets the version string from the package name of the CraftBukkit server implementation. -import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; * This is needed to bypass the JAR package name changing on each update. -import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; * * @return The version string of the OBC and NMS packages, including the trailing dot. */ @@ -86,7 +86,7 @@ import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; * * @param className The name of the class, excluding the package, within OBC. This name may contain a subpackage name, such as {@code inventory.CraftItemStack}. -import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; * @return The class instance representing the specified OBC class, or {@code null} if it could not be loaded. */ public synchronized static Class getOBCClass(String className) { 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 c410a3e0b..aab23d804 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/DelegatePlotGenerator.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/DelegatePlotGenerator.java @@ -9,7 +9,7 @@ import com.github.intellectualsites.plotsquared.plot.object.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.block.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; import lombok.RequiredArgsConstructor; import org.bukkit.World; 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 e6731d6ce..44bad9589 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,11 +9,12 @@ 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.object.RegionWrapper; +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.block.BlockUtil; +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; @@ -44,15 +45,15 @@ import java.util.concurrent.CompletableFuture; public class BukkitChunkManager extends ChunkManager { - public static boolean isIn(RegionWrapper region, int x, int z) { - return x >= region.minX && x <= region.maxX && z >= region.minZ && z <= region.maxZ; + public static boolean isIn(CuboidRegion region, int x, int z) { + return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX() && z >= region.getMinimumPoint().getZ() && z <= region.getMaximumPoint().getZ(); } public static ContentMap swapChunk(World world1, World world2, Chunk pos1, Chunk pos2, - RegionWrapper r1, RegionWrapper r2) { + CuboidRegion r1, CuboidRegion r2) { ContentMap map = new ContentMap(); - int relX = r2.minX - r1.minX; - int relZ = r2.minZ - r1.minZ; + int relX = r2.getMinimumPoint().getX() - r1.getMinimumPoint().getX(); + int relZ = r2.getMinimumPoint().getZ() - r1.getMinimumPoint().getZ(); map.saveEntitiesIn(pos1, r1, relX, relZ, true); map.saveEntitiesIn(pos2, r2, -relX, -relZ, true); @@ -69,8 +70,8 @@ public class BukkitChunkManager extends ChunkManager { LocalBlockQueue queue1 = GlobalBlockQueue.IMP.getNewQueue(worldName1, false); LocalBlockQueue queue2 = GlobalBlockQueue.IMP.getNewQueue(worldName2, false); - for (int x = Math.max(r1.minX, sx); x <= Math.min(r1.maxX, sx + 15); x++) { - for (int z = Math.max(r1.minZ, sz); z <= Math.min(r1.maxZ, sz + 15); z++) { + for (int x = Math.max(r1.getMinimumPoint().getX(), sx); x <= Math.min(r1.getMaximumPoint().getX(), sx + 15); x++) { + for (int z = Math.max(r1.getMinimumPoint().getZ(), sz); z <= Math.min(r1.getMaximumPoint().getZ(), sz + 15); z++) { for (int y = 0; y < 256; y++) { Block block1 = world1.getBlockAt(x, y, z); BaseBlock baseBlock1 = bukkitWorld1.getFullBlock(BlockVector3.at(x, y, z)); @@ -198,8 +199,8 @@ public class BukkitChunkManager extends ChunkManager { final int relX = newPos.getX() - pos1.getX(); final int relZ = newPos.getZ() - pos1.getZ(); - final RegionWrapper region = - new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); + final CuboidRegion region = + RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); final World oldWorld = Bukkit.getWorld(pos1.getWorld()); final BukkitWorld oldBukkitWorld = new BukkitWorld(oldWorld); final World newWorld = Bukkit.getWorld(newPos.getWorld()); @@ -350,8 +351,8 @@ public class BukkitChunkManager extends ChunkManager { if (checkX2 && checkZ2) { map.saveRegion(bukkitWorldObj, xxt2, xxt, zzt2, zzt); // } - RegionWrapper currentPlotClear = - new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); + CuboidRegion currentPlotClear = + RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); map.saveEntitiesOut(chunkObj, currentPlotClear); AugmentedUtils.bypass(ignoreAugment, () -> setChunkInPlotArea(null, new RunnableVal() { @@ -434,10 +435,10 @@ public class BukkitChunkManager extends ChunkManager { @Override public void swap(Location bot1, Location top1, Location bot2, Location top2, final Runnable whenDone) { - RegionWrapper region1 = - new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ()); - RegionWrapper region2 = - new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ()); + CuboidRegion region1 = + RegionUtil.createRegion(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ()); + CuboidRegion region2 = + RegionUtil.createRegion(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ()); final World world1 = Bukkit.getWorld(bot1.getWorld()); World world2 = Bukkit.getWorld(bot2.getWorld()); @@ -622,7 +623,7 @@ public class BukkitChunkManager extends ChunkManager { } } - void saveEntitiesOut(Chunk chunk, RegionWrapper region) { + void saveEntitiesOut(Chunk chunk, CuboidRegion region) { for (Entity entity : chunk.getEntities()) { Location location = BukkitUtil.getLocation(entity); int x = location.getX(); @@ -639,11 +640,11 @@ public class BukkitChunkManager extends ChunkManager { } } - void saveEntitiesIn(Chunk chunk, RegionWrapper region) { + void saveEntitiesIn(Chunk chunk, CuboidRegion region) { saveEntitiesIn(chunk, region, 0, 0, false); } - void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ, + void saveEntitiesIn(Chunk chunk, CuboidRegion region, int offsetX, int offsetZ, boolean delete) { for (Entity entity : chunk.getEntities()) { Location location = BukkitUtil.getLocation(entity); 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 29c4c63b7..95f4b2ebc 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 @@ -8,7 +8,7 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +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; @@ -34,7 +34,7 @@ import java.util.Set; public class BukkitHybridUtils extends HybridUtils { - @Override public void analyzeRegion(final String world, final RegionWrapper region, + @Override public void analyzeRegion(final String world, final CuboidRegion region, final RunnableVal whenDone) { // int diff, int variety, int vertices, int rotation, int height_sd /* @@ -56,8 +56,8 @@ public class BukkitHybridUtils extends HybridUtils { return; } - final Location bot = new Location(world, region.minX, region.minY, region.minZ); - final Location top = new Location(world, region.maxX, region.maxY, region.maxZ); + 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(); 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 3f980d37c..ed0a8cfcc 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,7 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +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; @@ -35,7 +35,7 @@ import java.util.stream.IntStream; */ public class BukkitSchematicHandler extends SchematicHandler { - @Override public void getCompoundTag(final String world, final Set regions, + @Override public void getCompoundTag(final String world, final Set regions, final RunnableVal whenDone) { // async TaskManager.runTaskAsync(new Runnable() { @@ -74,7 +74,7 @@ public class BukkitSchematicHandler extends SchematicHandler { List tileEntities = new ArrayList<>(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length); // Queue - final ArrayDeque queue = new ArrayDeque<>(regions); + final ArrayDeque queue = new ArrayDeque<>(regions); TaskManager.runTask(new Runnable() { @Override public void run() { if (queue.isEmpty()) { @@ -95,9 +95,9 @@ public class BukkitSchematicHandler extends SchematicHandler { return; } final Runnable regionTask = this; - RegionWrapper region = queue.poll(); - Location pos1 = new Location(world, region.minX, region.minY, region.minZ); - Location pos2 = new Location(world, region.maxX, region.maxY, region.maxZ); + CuboidRegion region = queue.poll(); + Location pos1 = new Location(world, region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ()); + Location pos2 = new Location(world, region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ()); final int p1x = pos1.getX(); final int sy = pos1.getY(); final int p1z = pos1.getZ(); 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 38c7e069d..a73872bee 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 @@ -6,14 +6,14 @@ 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.object.RegionWrapper; +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; import com.github.intellectualsites.plotsquared.plot.util.StringComparison; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; -import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; +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.world.block.BlockState; @@ -428,12 +428,12 @@ import java.util.Set; } @Override - public void setBiomes(@NonNull final String worldName, @NonNull final RegionWrapper region, + public void setBiomes(@NonNull final String worldName, @NonNull final CuboidRegion region, @NonNull final String biomeString) { final World world = getWorld(worldName); final Biome biome = Biome.valueOf(biomeString.toUpperCase()); - for (int x = region.minX; x <= region.maxX; x++) { - for (int z = region.minZ; z <= region.maxZ; z++) { + 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); } } 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 54e153845..9f5dc4e7f 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 @@ -5,7 +5,7 @@ import com.github.intellectualsites.plotsquared.bukkit.object.schematic.StateWra import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQueue; -import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; +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.block.BaseBlock; 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 50dd042ad..a93c22679 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,7 +5,7 @@ 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.block.BlockUtil; +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 com.sk89q.worldedit.world.block.BaseBlock; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/IPlotMain.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/IPlotMain.java index 77f36bb41..3a47773b7 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/IPlotMain.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/IPlotMain.java @@ -88,11 +88,11 @@ public interface IPlotMain extends ILogger { /** * Gets the NMS package prefix. -import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; * * @return The NMS package prefix -import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; */ String getNMSPackage(); 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 31f06f9d0..a08a8b1c2 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,7 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +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; @@ -2008,7 +2008,7 @@ import java.util.zip.ZipInputStream; return Collections.unmodifiableSet(result); } - public Set getPlotAreas(final String world, final RegionWrapper region) { + public Set getPlotAreas(final String world, final CuboidRegion region) { final PlotArea[] areas = plotAreaManager.getPlotAreas(world, region); final Set set = new HashSet<>(); Collections.addAll(set, areas); 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 0f39ebe94..f773c1e1c 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,7 +12,8 @@ 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.object.RegionWrapper; +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; @@ -99,7 +100,7 @@ import java.util.Set; area.ROAD_WIDTH / 2; final int offsetX = bx - (area.ROAD_WIDTH == 0 ? 0 : lower); final int offsetZ = bz - (area.ROAD_WIDTH == 0 ? 0 : lower); - final RegionWrapper region = new RegionWrapper(bx, tx, bz, tz); + final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz); Set areas = PlotSquared.get().getPlotAreas(area.worldname, region); if (!areas.isEmpty()) { @@ -460,10 +461,10 @@ import java.util.Set; if (area.TYPE != 2) { center = WorldUtil.IMP.getSpawn(area.worldname); } else { - RegionWrapper region = area.getRegion(); + CuboidRegion region = area.getRegion(); center = - new Location(area.worldname, region.minX + (region.maxX - region.minX) / 2, - 0, region.minZ + (region.maxZ - region.minZ) / 2); + new Location(area.worldname, region.getMinimumPoint().getX() + (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2, + 0, region.getMinimumPoint().getZ() + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2); center.setY(1 + WorldUtil.IMP .getHighestBlock(area.worldname, center.getX(), center.getZ())); } 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 000aa9b56..66a024ec4 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,7 +6,8 @@ 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.object.RegionWrapper; +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; @@ -176,18 +177,18 @@ import java.util.Set; } int bx = cbx << 4; int bz = cbz << 4; - RegionWrapper region = new RegionWrapper(bx, bx + 511, bz, bz + 511); + CuboidRegion region = RegionUtil.createRegion(bx, bx + 511, bz, bz + 511); for (Plot plot : PlotSquared.get().getPlots(world)) { Location bot = plot.getBottomAbs(); Location top = plot.getExtendedTopAbs(); - RegionWrapper plotReg = - new RegionWrapper(bot.getX(), top.getX(), bot.getZ(), + CuboidRegion plotReg = + RegionUtil.createRegion(bot.getX(), top.getX(), bot.getZ(), top.getZ()); - if (!region.intersects(plotReg)) { + if (!RegionUtil.intersects(region, plotReg)) { continue; } - for (int x = plotReg.minX >> 4; x <= plotReg.maxX >> 4; x++) { - for (int z = plotReg.minZ >> 4; z <= plotReg.maxZ >> 4; z++) { + for (int x = plotReg.getMinimumPoint().getX() >> 4; x <= plotReg.getMaximumPoint().getX() >> 4; x++) { + for (int z = plotReg.getMinimumPoint().getZ() >> 4; z <= plotReg.getMaximumPoint().getZ() >> 4; z++) { BlockVector2 loc = BlockVector2.at(x, z); chunks.remove(loc); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/BlockStateListFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/BlockStateListFlag.java index 1ca476618..b9f3367d0 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/BlockStateListFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/BlockStateListFlag.java @@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.flag; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.util.StringMan; -import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; 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 73a9e75d0..f5aa2e440 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,7 +4,8 @@ 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.object.RegionWrapper; +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; @@ -33,7 +34,7 @@ public class AugmentedUtils { final int blockX = chunkX << 4; final int blockZ = chunkZ << 4; - RegionWrapper region = new RegionWrapper(blockX, blockX + 15, blockZ, blockZ + 15); + CuboidRegion region = RegionUtil.createRegion(blockX, blockX + 15, blockZ, blockZ + 15); Set areas = PlotSquared.get().getPlotAreas(world, region); if (areas.isEmpty()) { return false; @@ -59,10 +60,10 @@ public class AugmentedUtils { int tzz; // gen if (area.TYPE == 2) { - bxx = Math.max(0, area.getRegion().minX - blockX); - bzz = Math.max(0, area.getRegion().minZ - blockZ); - txx = Math.min(15, area.getRegion().maxX - blockX); - tzz = Math.min(15, area.getRegion().maxZ - blockZ); + bxx = Math.max(0, area.getRegion().getMinimumPoint().getX() - blockX); + bzz = Math.max(0, area.getRegion().getMinimumPoint().getZ() - blockZ); + txx = Math.min(15, area.getRegion().getMaximumPoint().getX() - blockX); + tzz = Math.min(15, area.getRegion().getMaximumPoint().getZ() - blockZ); primaryMask = new DelegateLocalBlockQueue(queue) { @Override public boolean setBlock(int x, int y, int z, BlockState id) { if (area.contains(x, z)) { 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 d3eee1165..b0ef7e138 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 @@ -6,9 +6,9 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.MathMan; -import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; +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; @@ -59,11 +59,11 @@ public class ClassicPlotManager extends SquarePlotManager { Plot plot = classicPlotWorld.getPlotAbs(plotId); LocalBlockQueue queue = classicPlotWorld.getQueue(false); if (plot.isBasePlot()) { - for (RegionWrapper region : plot.getRegions()) { + for (CuboidRegion region : plot.getRegions()) { Location pos1 = - new Location(classicPlotWorld.worldname, region.minX, classicPlotWorld.PLOT_HEIGHT, region.minZ); + new Location(classicPlotWorld.worldname, region.getMinimumPoint().getX(), classicPlotWorld.PLOT_HEIGHT, region.getMinimumPoint().getZ()); Location pos2 = - new Location(classicPlotWorld.worldname, region.maxX, classicPlotWorld.PLOT_HEIGHT, region.maxZ); + new Location(classicPlotWorld.worldname, region.getMaximumPoint().getX(), classicPlotWorld.PLOT_HEIGHT, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } } @@ -77,9 +77,9 @@ public class ClassicPlotManager extends SquarePlotManager { } LocalBlockQueue queue = classicPlotWorld.getQueue(false); int maxY = getWorldHeight(); - for (RegionWrapper region : plot.getRegions()) { - Location pos1 = new Location(classicPlotWorld.worldname, region.minX, 1, region.minZ); - Location pos2 = new Location(classicPlotWorld.worldname, region.maxX, maxY, region.maxZ); + for (CuboidRegion region : plot.getRegions()) { + Location pos1 = new Location(classicPlotWorld.worldname, region.getMinimumPoint().getX(), 1, region.getMinimumPoint().getZ()); + Location pos2 = new Location(classicPlotWorld.worldname, region.getMaximumPoint().getX(), maxY, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } return queue.enqueue(); @@ -92,10 +92,10 @@ public class ClassicPlotManager extends SquarePlotManager { } LocalBlockQueue queue = classicPlotWorld.getQueue(false); int maxY = getWorldHeight(); - for (RegionWrapper region : plot.getRegions()) { + for (CuboidRegion region : plot.getRegions()) { Location pos1 = - new Location(classicPlotWorld.worldname, region.minX, classicPlotWorld.PLOT_HEIGHT + 1, region.minZ); - Location pos2 = new Location(classicPlotWorld.worldname, region.maxX, maxY, region.maxZ); + new Location(classicPlotWorld.worldname, region.getMinimumPoint().getX(), classicPlotWorld.PLOT_HEIGHT + 1, region.getMinimumPoint().getZ()); + Location pos2 = new Location(classicPlotWorld.worldname, region.getMaximumPoint().getX(), maxY, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } return queue.enqueue(); @@ -107,10 +107,10 @@ public class ClassicPlotManager extends SquarePlotManager { return false; } LocalBlockQueue queue = classicPlotWorld.getQueue(false); - for (RegionWrapper region : plot.getRegions()) { - Location pos1 = new Location(classicPlotWorld.worldname, region.minX, 1, region.minZ); + for (CuboidRegion region : plot.getRegions()) { + Location pos1 = new Location(classicPlotWorld.worldname, region.getMinimumPoint().getX(), 1, region.getMinimumPoint().getZ()); Location pos2 = - new Location(classicPlotWorld.worldname, region.maxX, classicPlotWorld.PLOT_HEIGHT - 1, region.maxZ); + new Location(classicPlotWorld.worldname, region.getMaximumPoint().getX(), classicPlotWorld.PLOT_HEIGHT - 1, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } return queue.enqueue(); @@ -173,9 +173,9 @@ public class ClassicPlotManager extends SquarePlotManager { } } if (plot.isBasePlot()) { - for (RegionWrapper region : plot.getRegions()) { - Location pos1 = new Location(classicPlotWorld.worldname, region.minX, maxY, region.minZ); - Location pos2 = new Location(classicPlotWorld.worldname, region.maxX, maxY, region.maxZ); + for (CuboidRegion region : plot.getRegions()) { + Location pos1 = new Location(classicPlotWorld.worldname, region.getMinimumPoint().getX(), maxY, region.getMinimumPoint().getZ()); + Location pos2 = new Location(classicPlotWorld.worldname, region.getMaximumPoint().getX(), maxY, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } } 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 249df910c..4d1ad357c 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 @@ -7,7 +7,7 @@ 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.block.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Field; 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 aae8b3643..7df870508 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 @@ -7,7 +7,7 @@ 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.block.BlockUtil; +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; 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 e87860190..0ab0947a4 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 @@ -12,7 +12,7 @@ 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.block.BlockUtil; +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.google.common.collect.Sets; 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 cc3a5ba02..f397c3fc2 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,7 +10,8 @@ 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.object.RegionWrapper; +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.MathMan; @@ -45,11 +46,11 @@ public abstract class HybridUtils { public static PlotArea area; public static boolean UPDATE = false; - public abstract void analyzeRegion(String world, RegionWrapper region, + public abstract void analyzeRegion(String world, CuboidRegion region, RunnableVal whenDone); public void analyzePlot(final Plot origin, final RunnableVal whenDone) { - final ArrayDeque zones = new ArrayDeque<>(origin.getRegions()); + final ArrayDeque zones = new ArrayDeque<>(origin.getRegions()); final ArrayList analysis = new ArrayList<>(); Runnable run = new Runnable() { @Override public void run() { @@ -97,7 +98,7 @@ public abstract class HybridUtils { TaskManager.runTask(whenDone); return; } - RegionWrapper region = zones.poll(); + CuboidRegion region = zones.poll(); final Runnable task = this; analyzeRegion(origin.getWorldName(), region, new RunnableVal() { @Override public void run(PlotAnalysis value) { @@ -271,10 +272,10 @@ public abstract class HybridUtils { int tz = sz - 1; int ty = get_ey(plotManager, queue, sx, ex, bz, tz, sy); - Set sideRoad = - new HashSet<>(Collections.singletonList(new RegionWrapper(sx, ex, sy, ey, sz, ez))); - final Set intersection = - new HashSet<>(Collections.singletonList(new RegionWrapper(sx, ex, sy, ty, bz, tz))); + Set sideRoad = + new HashSet<>(Collections.singletonList(RegionUtil.createRegion(sx, ex, sy, ey, sz, ez))); + final Set intersection = + new HashSet<>(Collections.singletonList(RegionUtil.createRegion(sx, ex, sy, ty, bz, tz))); final String dir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.getArea() 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 8ee343b3f..b05249d39 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,13 +6,14 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; +import java.util.Set; /** * A plot manager with a square grid layout, with square shaped plots. @@ -28,20 +29,20 @@ public abstract class SquarePlotManager extends GridPlotManager { @Override public boolean clearPlot(final Plot plot, final Runnable whenDone) { - final HashSet regions = plot.getRegions(); + final Set regions = plot.getRegions(); Runnable run = new Runnable() { @Override public void run() { if (regions.isEmpty()) { whenDone.run(); return; } - Iterator iterator = regions.iterator(); - RegionWrapper region = iterator.next(); + Iterator iterator = regions.iterator(); + CuboidRegion region = iterator.next(); iterator.remove(); Location pos1 = - new Location(plot.getWorldName(), region.minX, region.minY, region.minZ); + new Location(plot.getWorldName(), region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ()); Location pos2 = - new Location(plot.getWorldName(), region.maxX, region.maxY, region.maxZ); + new Location(plot.getWorldName(), region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ()); ChunkManager.manager.regenerateRegion(pos1, pos2, false, this); } }; 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 a91a97f90..7426b99c8 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,7 +20,7 @@ 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.block.ItemUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.ItemUtil; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; 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 7d2d824b4..f72fb0520 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,7 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -20,10 +20,11 @@ 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 { - private final HashSet mask; + private final Set mask; private final String world; private final int max; int BScount = 0; @@ -33,7 +34,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { private int count; private Extent parent; - public ProcessedWEExtent(String world, HashSet mask, int max, Extent child, + public ProcessedWEExtent(String world, Set mask, int max, Extent child, Extent parent) { super(child); this.mask = mask; 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 073819fa3..ea9f404b8 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,6 @@ package com.github.intellectualsites.plotsquared.plot.listener; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -16,14 +16,15 @@ 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 { public static BlockState AIRSTATE = BlockTypes.AIR.getDefaultState(); public static BaseBlock AIRBASE = BlockTypes.AIR.getDefaultState().toBaseBlock(); - private final HashSet mask; + private final Set mask; - public WEExtent(HashSet mask, Extent extent) { + public WEExtent(Set mask, Extent extent) { super(extent); this.mask = mask; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java index 3692efa51..8d0081273 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java @@ -7,62 +7,65 @@ 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.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import java.util.HashSet; +import java.util.Set; import java.util.UUID; public class WEManager { - public static boolean maskContains(HashSet mask, int x, int y, int z) { - for (RegionWrapper region : mask) { - if (region.isIn(x, y, z)) { + public static boolean maskContains(Set mask, int x, int y, int z) { + for (CuboidRegion region : mask) { + if (RegionUtil.contains(region, x, y, z)) { return true; } } return false; } - public static boolean maskContains(HashSet mask, int x, int z) { - for (RegionWrapper region : mask) { - if (region.isIn(x, z)) { + public static boolean maskContains(Set mask, int x, int z) { + for (CuboidRegion region : mask) { + if (RegionUtil.contains(region, x, z)) { return true; } } return false; } - public static boolean maskContains(HashSet mask, double dx, double dy, + public static boolean maskContains(Set mask, double dx, double dy, double dz) { int x = Math.toIntExact(Math.round(dx >= 0 ? dx - 0.5 : dx + 0.5)); int y = Math.toIntExact(Math.round(dy - 0.5)); int z = Math.toIntExact(Math.round(dz >= 0 ? dz - 0.5 : dz + 0.5)); - for (RegionWrapper region : mask) { - if (region.isIn(x, y, z)) { + for (CuboidRegion region : mask) { + if (RegionUtil.contains(region, x, y, z)) { return true; } } return false; } - public static boolean maskContains(HashSet mask, double dx, double dz) { + public static boolean maskContains(Set mask, double dx, double dz) { int x = Math.toIntExact(Math.round(dx >= 0 ? dx - 0.5 : dx + 0.5)); int z = Math.toIntExact(Math.round(dz >= 0 ? dz - 0.5 : dz + 0.5)); - for (RegionWrapper region : mask) { - if (region.isIn(x, z)) { + for (CuboidRegion region : mask) { + if (RegionUtil.contains(region, x, z)) { return true; } } return false; } - public static HashSet getMask(PlotPlayer player) { - HashSet regions = new HashSet<>(); + public static HashSet getMask(PlotPlayer player) { + HashSet regions = new HashSet<>(); UUID uuid = player.getUUID(); Location location = player.getLocation(); String world = location.getWorld(); if (!PlotSquared.get().hasPlotArea(world)) { - regions.add(new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, + regions.add(RegionUtil.createRegion(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE)); return regions; } @@ -78,10 +81,10 @@ public class WEManager { if (plot != null && (!Settings.Done.RESTRICT_BUILDING || !Flags.DONE.isSet(plot)) && ( (allowMember && plot.isAdded(uuid)) || (!allowMember && (plot.isOwner(uuid)) || plot .getTrusted().contains(uuid))) && !(Flags.NO_WORLDEDIT.isTrue(plot))) { - for (RegionWrapper region : plot.getRegions()) { - RegionWrapper copy = - new RegionWrapper(region.minX, region.maxX, area.MIN_BUILD_HEIGHT, - area.MAX_BUILD_HEIGHT, region.minZ, region.maxZ); + for (CuboidRegion region : plot.getRegions()) { + BlockVector3 pos1 = region.getMinimumPoint().withY(area.MIN_BUILD_HEIGHT); + BlockVector3 pos2 = region.getMaximumPoint().withY(area.MAX_BUILD_HEIGHT); + CuboidRegion copy = new CuboidRegion(pos1, pos2); regions.add(copy); } player.setMeta("WorldEditRegionPlot", plot); @@ -89,12 +92,12 @@ public class WEManager { return regions; } - public static boolean intersects(RegionWrapper region1, RegionWrapper region2) { - return region1.intersects(region2); + public static boolean intersects(CuboidRegion region1, CuboidRegion region2) { + return RegionUtil.intersects(region1, region2); } - public static boolean regionContains(RegionWrapper selection, HashSet mask) { - for (RegionWrapper region : mask) { + public static boolean regionContains(CuboidRegion selection, HashSet mask) { + for (CuboidRegion region : mask) { if (intersects(region, selection)) { return true; } 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 78379fd9e..a56063d08 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,7 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +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; @@ -19,6 +19,7 @@ import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.world.World; import java.util.HashSet; +import java.util.Set; public class WESubscriber { @@ -37,7 +38,7 @@ public class WESubscriber { if (actor != null && actor.isPlayer()) { String name = actor.getName(); PlotPlayer plotPlayer = PlotPlayer.wrap(name); - HashSet mask; + Set mask; if (plotPlayer == null) { Player player = (Player) actor; Location location = player.getLocation(); 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 4d9f23e5f..28ad5669b 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,6 +5,7 @@ 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.regions.CuboidRegion; import com.sk89q.worldedit.world.item.ItemType; import org.jetbrains.annotations.NotNull; @@ -18,9 +19,9 @@ public class ConsolePlayer extends PlotPlayer { PlotArea area = PlotSquared.get().getFirstPlotArea(); Location location; if (area != null) { - RegionWrapper region = area.getRegion(); - location = new Location(area.worldname, region.minX + region.maxX / 2, 0, - region.minZ + region.maxZ / 2); + CuboidRegion region = area.getRegion(); + location = new Location(area.worldname, region.getMinimumPoint().getX() + region.getMaximumPoint().getX() / 2, 0, + region.getMinimumPoint().getZ() + region.getMaximumPoint().getZ() / 2); } else { location = new Location("world", 0, 0, 0); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java index 5f2b6bafe..30c8b19c8 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java @@ -27,10 +27,6 @@ public class Location implements Cloneable, Comparable { this.blockVector3 = BlockVector3.at(x, y, z); } - public Location() { - this.world = ""; - } - public Location(String world, int x, int y, int z) { this(world, x, y, z, 0f, 0f); } 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 c753cefe7..9718eb198 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,7 +22,7 @@ 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.block.BlockUtil; +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; @@ -32,6 +32,8 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -66,13 +68,13 @@ import java.util.stream.Collectors; */ public class Plot { - private static final int MAX_HEIGHT = 256; + public static final int MAX_HEIGHT = 256; /** * @deprecated raw access is deprecated */ - @Deprecated private static HashSet connected_cache; - private static HashSet regions_cache; + @Deprecated private static Set connected_cache; + private static Set regions_cache; @NotNull private final PlotId id; @@ -865,7 +867,7 @@ public class Plot { return false; } } - final HashSet regions = this.getRegions(); + final Set regions = this.getRegions(); final Set plots = this.getConnectedPlots(); final ArrayDeque queue = new ArrayDeque<>(plots); if (isDelete) { @@ -877,10 +879,10 @@ public class Plot { @Override public void run() { if (queue.isEmpty()) { Runnable run = () -> { - for (RegionWrapper region : regions) { - Location[] corners = region.getCorners(getWorldName()); - ChunkManager.manager.clearAllEntities(corners[0], corners[1]); - } +// for (CuboidRegion region : regions) { +// Location[] corners = MainUtil.getCorners(getWorldName(), region); +// ChunkManager.manager.clearAllEntities(corners[0], corners[1]); +// } TaskManager.runTask(whenDone); }; for (Plot current : plots) { @@ -920,7 +922,7 @@ public class Plot { * @param whenDone The task to run when finished, or null */ public void setBiome(final String biome, final Runnable whenDone) { - final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); + final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); final int extendBiome; if (area instanceof SquarePlotWorld) { extendBiome = (((SquarePlotWorld) area).ROAD_WIDTH > 0) ? 1 : 0; @@ -934,11 +936,11 @@ public class Plot { TaskManager.runTask(whenDone); return; } - RegionWrapper region = regions.poll(); - Location pos1 = new Location(getWorldName(), region.minX - extendBiome, region.minY, - region.minZ - extendBiome); - Location pos2 = new Location(getWorldName(), region.maxX + extendBiome, region.maxY, - region.maxZ + extendBiome); + CuboidRegion region = regions.poll(); + Location pos1 = new Location(getWorldName(), region.getMinimumPoint().getX() - extendBiome, region.getMinimumPoint().getY(), + region.getMinimumPoint().getZ() - extendBiome); + Location pos2 = new Location(getWorldName(), region.getMaximumPoint().getX() + extendBiome, region.getMaximumPoint().getY(), + region.getMaximumPoint().getZ() + extendBiome); ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override public void run(int[] value) { BlockVector2 loc = BlockVector2.at(value[0], value[1]); @@ -1254,9 +1256,9 @@ public class Plot { } public Location getSide() { - RegionWrapper largest = getLargestRegion(); - int x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX; - int z = largest.minZ - 1; + CuboidRegion largest = getLargestRegion(); + int x = (largest.getMaximumPoint().getX() >> 1) - (largest.getMinimumPoint().getX() >> 1) + largest.getMinimumPoint().getX(); + int z = largest.getMinimumPoint().getZ() - 1; PlotManager manager = getManager(); int y = isLoaded() ? WorldUtil.IMP.getHighestBlock(getWorldName(), x, z) : 62; if (area.ALLOW_SIGNS && (y <= 0 || y >= 255)) { @@ -1328,9 +1330,9 @@ public class Plot { int z; if (loc.getX() == Integer.MAX_VALUE && loc.getZ() == Integer.MAX_VALUE) { // center - RegionWrapper largest = plot.getLargestRegion(); - x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX; - z = (largest.maxZ >> 1) - (largest.minZ >> 1) + largest.minZ; + CuboidRegion largest = plot.getLargestRegion(); + x = (largest.getMaximumPoint().getX() >> 1) - (largest.getMinimumPoint().getX() >> 1) + largest.getMinimumPoint().getX(); + z = (largest.getMaximumPoint().getZ() >> 1) - (largest.getMinimumPoint().getZ() >> 1) + largest.getMinimumPoint().getZ(); } else { // specific Location bot = plot.getBottomAbs(); @@ -1348,9 +1350,9 @@ public class Plot { public double getVolume() { double count = 0; - for (RegionWrapper region : getRegions()) { + for (CuboidRegion region : getRegions()) { count += - (region.maxX - (double) region.minX + 1) * (region.maxZ - (double) region.minZ + 1) + (region.getMaximumPoint().getX() - (double) region.getMinimumPoint().getX() + 1) * (region.getMaximumPoint().getZ() - (double) region.getMinimumPoint().getZ() + 1) * MAX_HEIGHT; } return count; @@ -1436,9 +1438,9 @@ public class Plot { public void refreshChunks() { LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(getWorldName(), false); HashSet chunks = new HashSet<>(); - for (RegionWrapper region : Plot.this.getRegions()) { - for (int x = region.minX >> 4; x <= region.maxX >> 4; x++) { - for (int z = region.minZ >> 4; z <= region.maxZ >> 4; z++) { + for (CuboidRegion region : Plot.this.getRegions()) { + for (int x = region.getMinimumPoint().getX() >> 4; x <= region.getMaximumPoint().getX() >> 4; x++) { + for (int z = region.getMinimumPoint().getZ() >> 4; z <= region.getMaximumPoint().getZ() >> 4; z++) { if (chunks.add(BlockVector2.at(x, z))) { queue.refreshChunk(x, z); } @@ -2593,7 +2595,7 @@ public class Plot { * * @return */ - @NotNull public HashSet getRegions() { + @NotNull public Set getRegions() { if (regions_cache != null && connected_cache != null && connected_cache.contains(this)) { return regions_cache; } @@ -2601,14 +2603,13 @@ public class Plot { Location pos1 = this.getBottomAbs(); Location pos2 = this.getTopAbs(); connected_cache = Sets.newHashSet(this); - regions_cache = Sets.newHashSet( - new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getY(), pos2.getY(), pos1.getZ(), - pos2.getZ())); + CuboidRegion rg = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()); + regions_cache = Collections.singleton(rg); return regions_cache; } Set plots = this.getConnectedPlots(); - HashSet regions = regions_cache = new HashSet<>(); - HashSet visited = new HashSet<>(); + Set regions = regions_cache = new HashSet<>(); + Set visited = new HashSet<>(); for (Plot current : plots) { if (visited.contains(current.getId())) { continue; @@ -2685,12 +2686,14 @@ public class Plot { Location toploc = plot.getExtendedTopAbs(); Location botabs = plot.getBottomAbs(); Location topabs = plot.getTopAbs(); - regions.add(new RegionWrapper(botabs.getX(), topabs.getX(), topabs.getZ() + 1, - toploc.getZ())); + BlockVector3 pos1 = BlockVector3.at(botabs.getX(), 0, topabs.getZ() + 1); + BlockVector3 pos2 = BlockVector3.at(topabs.getX(), Plot.MAX_HEIGHT - 1, toploc.getZ()); + regions.add(new CuboidRegion(pos1, pos2)); if (plot.getMerged(Direction.SOUTHEAST)) { + pos1 = BlockVector3.at(topabs.getX() + 1, 0, topabs.getZ() + 1); + pos2 = BlockVector3.at(toploc.getX(), Plot.MAX_HEIGHT - 1, toploc.getZ()); regions.add( - new RegionWrapper(topabs.getX() + 1, toploc.getX(), topabs.getZ() + 1, - toploc.getZ())); + new CuboidRegion(pos1, pos2)); // intersection } } @@ -2703,18 +2706,22 @@ public class Plot { Location toploc = plot.getExtendedTopAbs(); Location botabs = plot.getBottomAbs(); Location topabs = plot.getTopAbs(); - regions.add(new RegionWrapper(topabs.getX() + 1, toploc.getX(), botabs.getZ(), - topabs.getZ())); + BlockVector3 pos1 = BlockVector3.at(topabs.getX() + 1, 0, botabs.getZ()); + BlockVector3 pos2 = BlockVector3.at(toploc.getX(), Plot.MAX_HEIGHT - 1, topabs.getZ()); + regions.add(new CuboidRegion(pos1, pos2)); if (plot.getMerged(Direction.SOUTHEAST)) { + pos1 = BlockVector3.at(topabs.getX() + 1, 0, topabs.getZ()); + pos2 = BlockVector3.at(toploc.getX(), Plot.MAX_HEIGHT - 1, toploc.getZ()); regions.add( - new RegionWrapper(topabs.getX() + 1, toploc.getX(), topabs.getZ() + 1, - toploc.getZ())); + new CuboidRegion(pos1, pos2)); // intersection } } } + BlockVector3 pos1 = BlockVector3.at(gbotabs.getX() + 1, 0, gbotabs.getZ()); + BlockVector3 pos2 = BlockVector3.at(gtopabs.getX(), Plot.MAX_HEIGHT - 1, gtopabs.getZ()); regions.add( - new RegionWrapper(gbotabs.getX(), gtopabs.getX(), gbotabs.getZ(), gtopabs.getZ())); + new CuboidRegion(pos1, pos2)); } return regions; } @@ -2724,13 +2731,13 @@ public class Plot { * * @return */ - public RegionWrapper getLargestRegion() { - HashSet regions = this.getRegions(); - RegionWrapper max = null; + public CuboidRegion getLargestRegion() { + Set regions = this.getRegions(); + CuboidRegion max = null; double area = Double.NEGATIVE_INFINITY; - for (RegionWrapper region : regions) { + for (CuboidRegion region : regions) { double current = - (region.maxX - (double) region.minX + 1) * (region.maxZ - (double) region.minZ + 1); + (region.getMaximumPoint().getX() - (double) region.getMinimumPoint().getX() + 1) * (region.getMaximumPoint().getZ() - (double) region.getMinimumPoint().getZ() + 1); if (current > area) { max = region; area = current; @@ -2759,9 +2766,9 @@ public class Plot { */ public List getAllCorners() { Area area = new Area(); - for (RegionWrapper region : this.getRegions()) { - Rectangle2D rect = new Rectangle2D.Double(region.minX - 0.6, region.minZ - 0.6, - region.maxX - region.minX + 1.2, region.maxZ - region.minZ + 1.2); + for (CuboidRegion region : this.getRegions()) { + Rectangle2D rect = new Rectangle2D.Double(region.getMinimumPoint().getX() - 0.6, region.getMinimumPoint().getZ() - 0.6, + region.getMaximumPoint().getX() - region.getMinimumPoint().getX() + 1.2, region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ() + 1.2); Area rectArea = new Area(rect); area.add(rectArea); } @@ -2976,7 +2983,7 @@ public class Plot { } // world border destination.updateWorldBorder(); - final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); + final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); // move / swap data final PlotArea originArea = getArea(); for (Plot plot : plots) { @@ -2991,8 +2998,8 @@ public class Plot { TaskManager.runTask(whenDone); return; } - RegionWrapper region = regions.poll(); - Location[] corners = region.getCorners(getWorldName()); + CuboidRegion region = regions.poll(); + Location[] corners = MainUtil.getCorners(getWorldName(), region); Location pos1 = corners[0]; Location pos2 = corners[1]; Location pos3 = pos1.clone().add(offsetX, 0, offsetZ); @@ -3019,8 +3026,8 @@ public class Plot { return; } final Runnable task = this; - RegionWrapper region = regions.poll(); - Location[] corners = region.getCorners(getWorldName()); + CuboidRegion region = regions.poll(); + Location[] corners = MainUtil.getCorners(getWorldName(), region); final Location pos1 = corners[0]; final Location pos2 = corners[1]; Location newPos = pos1.clone().add(offsetX, 0, offsetZ); @@ -3093,7 +3100,7 @@ public class Plot { } } // copy terrain - final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); + final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); Runnable run = new Runnable() { @Override public void run() { if (regions.isEmpty()) { @@ -3104,8 +3111,8 @@ public class Plot { TaskManager.runTask(whenDone); return; } - RegionWrapper region = regions.poll(); - Location[] corners = region.getCorners(getWorldName()); + CuboidRegion region = regions.poll(); + Location[] corners = MainUtil.getCorners(getWorldName(), region); Location pos1 = corners[0]; Location pos2 = corners[1]; Location newPos = pos1.clone().add(offsetX, 0, offsetZ); 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 b3217297d..970c427b8 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 @@ -19,8 +19,12 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.area.QuadMap; 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.RegionUtil; import com.google.common.collect.ImmutableMap; 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 org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -79,7 +83,7 @@ public abstract class PlotArea { public int MIN_BUILD_HEIGHT = 1; public PlotGameMode GAMEMODE = PlotGameMode.CREATIVE; private int hash; - private RegionWrapper region; + private CuboidRegion region; private ConcurrentHashMap meta; private QuadMap clusters; @@ -128,16 +132,16 @@ public abstract class PlotArea { } /** - * Returns the region for this PlotArea or a RegionWrapper encompassing + * Returns the region for this PlotArea or a CuboidRegion encompassing * the whole world if none exists. * - * @return RegionWrapper + * @return CuboidRegion */ - public RegionWrapper getRegion() { + public CuboidRegion getRegion() { this.region = getRegionAbs(); if (this.region == null) { - return new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, - Integer.MAX_VALUE); + return new CuboidRegion(BlockVector3.at(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE), + BlockVector3.at(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE)); } return this.region; } @@ -145,15 +149,16 @@ public abstract class PlotArea { /** * Returns the region for this PlotArea. * - * @return RegionWrapper or null if no applicable region + * @return CuboidRegion or null if no applicable region */ - private RegionWrapper getRegionAbs() { + private CuboidRegion getRegionAbs() { if (this.region == null) { if (this.min != null) { Location bot = getPlotManager().getPlotBottomLocAbs(this.min); Location top = getPlotManager().getPlotTopLocAbs(this.max); - this.region = new RegionWrapper(bot.getX() - 1, top.getX() + 1, bot.getZ() - 1, - top.getZ() + 1); + BlockVector3 pos1 = bot.getBlockVector3().subtract(BlockVector3.ONE); + BlockVector3 pos2 = top.getBlockVector3().add(BlockVector3.ONE); + this.region = new CuboidRegion(pos1, pos2); } } return this.region; @@ -497,7 +502,7 @@ public abstract class PlotArea { } public boolean contains(final int x, final int z) { - return this.TYPE != 2 || getRegionAbs().isIn(x, z); + return this.TYPE != 2 || RegionUtil.contains(getRegionAbs(), x, z); } public boolean contains(@NotNull final PlotId id) { @@ -507,7 +512,7 @@ public abstract class PlotArea { public boolean contains(@NotNull final Location location) { return StringMan.isEqual(location.getWorld(), this.worldname) && (getRegionAbs() == null - || this.region.isIn(location.getX(), location.getZ())); + || this.region.contains(location.getBlockVector3())); } @NotNull Set getPlotsAbs(final UUID uuid) { @@ -940,9 +945,10 @@ public abstract class PlotArea { public void addCluster(@Nullable final PlotCluster plotCluster) { if (this.clusters == null) { this.clusters = new QuadMap(Integer.MAX_VALUE, 0, 0, 62) { - @Override public RegionWrapper getRegion(PlotCluster value) { - return new RegionWrapper(value.getP1().x, value.getP2().x, value.getP1().y, - value.getP2().y); + @Override public CuboidRegion getRegion(PlotCluster value) { + BlockVector2 pos1 = BlockVector2.at(value.getP1().x, value.getP1().y); + BlockVector2 pos2 = BlockVector2.at(value.getP2().x, value.getP2().y); + return new CuboidRegion(pos1.toBlockVector3(), pos2.toBlockVector3(Plot.MAX_HEIGHT - 1)); } }; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotCluster.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotCluster.java index d5d7c95d3..4a653d8dd 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotCluster.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotCluster.java @@ -2,6 +2,8 @@ package com.github.intellectualsites.plotsquared.plot.object; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.regions.CuboidRegion; import java.util.HashSet; import java.util.UUID; @@ -15,7 +17,7 @@ public class PlotCluster { public int temp; private PlotId pos1; private PlotId pos2; - private RegionWrapper region; + private CuboidRegion region; public PlotCluster(PlotArea area, PlotId pos1, PlotId pos2, UUID owner) { this.area = area; @@ -56,10 +58,10 @@ public class PlotCluster { } private void setRegion() { - this.region = new RegionWrapper(this.pos1.x, this.pos2.x, this.pos1.y, this.pos2.y); + this.region = RegionUtil.createRegion(this.pos1.x, this.pos2.x, this.pos1.y, this.pos2.y); } - public RegionWrapper getRegion() { + public CuboidRegion getRegion() { return this.region; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/RegionWrapper.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/RegionWrapper.java deleted file mode 100644 index ced127a22..000000000 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/RegionWrapper.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.github.intellectualsites.plotsquared.plot.object; - -public class RegionWrapper { - public final int minX; - public final int maxX; - public final int minY; - public final int maxY; - public final int minZ; - public final int maxZ; - - public RegionWrapper(int minX, int maxX, int minZ, int maxZ) { - this.maxX = maxX; - this.minX = minX; - this.maxZ = maxZ; - this.minZ = minZ; - this.minY = 0; - this.maxY = 256; - } - - public RegionWrapper(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) { - this.maxX = maxX; - this.minX = minX; - this.maxZ = maxZ; - this.minZ = minZ; - this.minY = minY; - this.maxY = maxY; - } - - public boolean isIn(int x, int y, int z) { - return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ - && y >= this.minY && y <= this.maxY; - } - - public boolean isIn(int x, int z) { - return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ; - } - - public boolean intersects(RegionWrapper other) { - return other.minX <= this.maxX && other.maxX >= this.minX && other.minY <= this.maxY - && other.maxY >= this.minY; - } - - @Override public int hashCode() { - return this.minX + 13 * this.maxX + 23 * this.minZ + 39 * this.maxZ; - } - - @Override public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (obj instanceof RegionWrapper) { - RegionWrapper other = (RegionWrapper) obj; - return this.minX == other.minX && this.minZ == other.minZ && this.minY == other.minY - && this.maxX == other.maxX && this.maxZ == other.maxZ && this.maxY == other.maxY; - } - return false; - } - - @Override public String toString() { - return this.minX + "->" + this.maxX + "," + this.minZ + "->" + this.maxZ; - } - - public Location[] getCorners(String world) { - Location pos1 = new Location(world, this.minX, this.minY, this.minZ); - Location pos2 = new Location(world, this.maxX, this.maxY, this.maxZ); - return new Location[] {pos1, pos2}; - } -} 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 8d5152a1b..0191b53df 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,7 +2,7 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.area.QuadMap; @@ -99,7 +99,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager { QuadMap map = this.plotAreaGrid.get(plotArea.worldname); if (map == null) { map = new QuadMap(Integer.MAX_VALUE, 0, 0) { - @Override public RegionWrapper getRegion(PlotArea value) { + @Override public CuboidRegion getRegion(PlotArea value) { return value.getRegion(); } }; @@ -201,7 +201,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager { } } - @Override public PlotArea[] getPlotAreas(String world, RegionWrapper region) { + @Override public PlotArea[] getPlotAreas(String world, CuboidRegion region) { if (region == null) { PlotArea[] areas = this.plotAreaMap.get(world); if (areas == null) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/PlotAreaManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/PlotAreaManager.java index 7a59dab9d..b34ad2787 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/PlotAreaManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/PlotAreaManager.java @@ -2,7 +2,7 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; public interface PlotAreaManager { PlotArea getApplicablePlotArea(Location location); @@ -11,7 +11,7 @@ public interface PlotAreaManager { PlotArea getPlotArea(String world, String id); - PlotArea[] getPlotAreas(String world, RegionWrapper region); + PlotArea[] getPlotAreas(String world, CuboidRegion region); PlotArea[] getAllPlotAreas(); 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 7f63e2ed0..a9a620daa 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 @@ -8,18 +8,21 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +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; +import java.util.Collections; import java.util.HashSet; +import java.util.Set; import java.util.UUID; public class SinglePlot extends Plot { - private HashSet regions = Sets.newHashSet( - new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, - Integer.MAX_VALUE)); + private Set regions = Collections.singleton( + new CuboidRegion(BlockVector3.at(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE), + BlockVector3.at(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE))); public SinglePlot(PlotArea area, PlotId id, UUID owner) { super(area, id, owner); @@ -66,7 +69,7 @@ public class SinglePlot extends Plot { return super.isLoaded(); } - @NotNull @Override public HashSet getRegions() { + @NotNull @Override public Set getRegions() { return regions; } 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 f2e0b3c03..620a689b3 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,7 +2,7 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.sk89q.worldedit.regions.CuboidRegion; import com.github.intellectualsites.plotsquared.plot.util.ArrayUtil; import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; @@ -90,7 +90,7 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { return isWorld(location.getWorld()) || location.getWorld().equals("*") ? area : null; } - @Override public PlotArea[] getPlotAreas(String world, RegionWrapper region) { + @Override public PlotArea[] getPlotAreas(String world, CuboidRegion region) { PlotArea[] found = super.getPlotAreas(world, region); if (found != null && found.length != 0) { return found; 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 a7f3e2b62..0042ca222 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 @@ -6,7 +6,7 @@ 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.block.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; public class SingleWorldGenerator extends IndependentPlotGenerator { 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 206f2b710..be8a79207 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,7 +3,7 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +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; @@ -80,7 +80,7 @@ public abstract class ChunkManager { return false; } - public static void largeRegionTask(final String world, final RegionWrapper region, + public static void largeRegionTask(final String world, final CuboidRegion region, final RunnableVal task, final Runnable whenDone) { TaskManager.runTaskAsync(() -> { HashSet chunks = new HashSet<>(); @@ -90,16 +90,16 @@ public abstract class ChunkManager { int bz = mcr.getZ() << 9; int tx = bx + 511; int tz = bz + 511; - if (bx <= region.maxX && tx >= region.minX && bz <= region.maxZ - && tz >= region.minZ) { + if (bx <= region.getMaximumPoint().getX() && tx >= region.getMinimumPoint().getX() && bz <= region.getMaximumPoint().getZ() + && tz >= region.getMinimumPoint().getZ()) { for (int x = bx >> 4; x <= (tx >> 4); x++) { int cbx = x << 4; int ctx = cbx + 15; - if (cbx <= region.maxX && ctx >= region.minX) { + if (cbx <= region.getMaximumPoint().getX() && ctx >= region.getMinimumPoint().getX()) { for (int z = bz >> 4; z <= (tz >> 4); z++) { int cbz = z << 4; int ctz = cbz + 15; - if (cbz <= region.maxZ && ctz >= region.minZ) { + if (cbz <= region.getMaximumPoint().getZ() && ctz >= region.getMinimumPoint().getZ()) { chunks.add(BlockVector2.at(x, z)); } } @@ -118,16 +118,16 @@ public abstract class ChunkManager { public static void chunkTask(final Plot plot, final RunnableVal task, final Runnable whenDone, final int allocate) { - final ArrayList regions = new ArrayList<>(plot.getRegions()); + final ArrayList regions = new ArrayList<>(plot.getRegions()); Runnable smallTask = new Runnable() { @Override public void run() { if (regions.isEmpty()) { TaskManager.runTask(whenDone); return; } - RegionWrapper value = regions.remove(0); - Location pos1 = new Location(plot.getWorldName(), value.minX, 0, value.minZ); - Location pos2 = new Location(plot.getWorldName(), value.maxX, 0, value.maxZ); + CuboidRegion value = regions.remove(0); + Location pos1 = new Location(plot.getWorldName(), value.getMinimumPoint().getX(), 0, value.getMinimumPoint().getZ()); + Location pos2 = new Location(plot.getWorldName(), value.getMaximumPoint().getX(), 0, value.getMaximumPoint().getZ()); chunkTask(pos1, pos2, task, this, allocate); } }; 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 af4b21e3c..d06beab3f 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,7 +16,9 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +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; @@ -372,6 +374,14 @@ public class MainUtil { return plot.getFlag(Flags.SERVER_PLOT).orElse(false); } + @NotNull public static Location[] getCorners(String world, CuboidRegion region) { + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + Location pos1 = new Location(world, min.getX(), min.getY(), min.getZ()); + Location pos2 = new Location(world, max.getX(), max.getY(), max.getZ()); + return new Location[] {pos1, pos2}; + } + /** * Get the corner locations for a list of regions. * @@ -380,11 +390,11 @@ public class MainUtil { * @return * @see Plot#getCorners() */ - @NotNull public static Location[] getCorners(String world, Collection regions) { + @NotNull public static Location[] getCorners(String world, Collection regions) { Location min = null; Location max = null; - for (RegionWrapper region : regions) { - Location[] corners = region.getCorners(world); + for (CuboidRegion region : regions) { + Location[] corners = getCorners(world, region); if (min == null) { min = corners[0]; max = corners[1]; @@ -558,7 +568,9 @@ public class MainUtil { * @param biome */ public static void setBiome(String world, int p1x, int p1z, int p2x, int p2z, String biome) { - RegionWrapper region = new RegionWrapper(p1x, p2x, p1z, p2z); + BlockVector3 pos1 = BlockVector2.at(p1x, p1z).toBlockVector3(); + BlockVector3 pos2 = BlockVector2.at(p2x, p2z).toBlockVector3(Plot.MAX_HEIGHT - 1); + CuboidRegion region = new CuboidRegion(pos1, pos2); WorldUtil.IMP.setBiomes(world, region, biome); } 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 a1c920d9e..75f8d79f0 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,7 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +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; @@ -168,13 +168,13 @@ public abstract class SchematicHandler { final int LENGTH = dimension.getZ(); final int HEIGHT = dimension.getY(); // Validate dimensions - RegionWrapper region = plot.getLargestRegion(); - if (((region.maxX - region.minX + xOffset + 1) < WIDTH) || ( - (region.maxZ - region.minZ + zOffset + 1) < LENGTH) || (HEIGHT > 256)) { + CuboidRegion region = plot.getLargestRegion(); + if (((region.getMaximumPoint().getX() - region.getMinimumPoint().getX() + xOffset + 1) < WIDTH) || ( + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ() + zOffset + 1) < LENGTH) || (HEIGHT > 256)) { PlotSquared.debug("Schematic is too large"); PlotSquared.debug( "(" + WIDTH + ',' + LENGTH + ',' + HEIGHT + ") is bigger than (" + ( - region.maxX - region.minX) + ',' + (region.maxZ - region.minZ) + region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) + ',' + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) + ",256)"); TaskManager.runTask(whenDone); return; @@ -192,16 +192,16 @@ public abstract class SchematicHandler { y_offset_actual = yOffset + ((ClassicPlotWorld) pw).PLOT_HEIGHT; } else { y_offset_actual = yOffset + 1 + MainUtil - .getHeighestBlock(plot.getWorldName(), region.minX + 1, - region.minZ + 1); + .getHeighestBlock(plot.getWorldName(), region.getMinimumPoint().getX() + 1, + region.getMinimumPoint().getZ() + 1); } } } else { y_offset_actual = yOffset; } Location pos1 = - new Location(plot.getWorldName(), region.minX + xOffset, y_offset_actual, - region.minZ + zOffset); + new Location(plot.getWorldName(), region.getMinimumPoint().getX() + xOffset, y_offset_actual, + region.getMinimumPoint().getZ() + zOffset); Location pos2 = pos1.clone().add(WIDTH - 1, HEIGHT - 1, LENGTH - 1); final int p1x = pos1.getX(); final int p1z = pos1.getZ(); @@ -445,7 +445,7 @@ public abstract class SchematicHandler { return true; } - public abstract void getCompoundTag(String world, Set regions, + public abstract void getCompoundTag(String world, Set regions, RunnableVal whenDone); public void getCompoundTag(final Plot plot, final RunnableVal whenDone) { 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 9d60a80ba..52be1a312 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,7 @@ 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.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +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; @@ -66,7 +66,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, RegionWrapper region, String biome); + public abstract void setBiomes(String world, CuboidRegion region, String biome); public abstract com.sk89q.worldedit.world.World getWeWorld(String world); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/area/QuadMap.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/area/QuadMap.java index 133088a2e..e016cfeea 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/area/QuadMap.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/area/QuadMap.java @@ -1,6 +1,7 @@ package com.github.intellectualsites.plotsquared.plot.util.area; -import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.github.intellectualsites.plotsquared.plot.util.world.RegionUtil; +import com.sk89q.worldedit.regions.CuboidRegion; import java.util.HashSet; import java.util.Set; @@ -96,9 +97,9 @@ public class QuadMap { this.objects.add(area); return; } - RegionWrapper region = getRegion(area); - if (region.minX >= this.x) { - if (region.minZ >= this.z) { + CuboidRegion region = getRegion(area); + if (region.getMinimumPoint().getX() >= this.x) { + if (region.getMinimumPoint().getZ() >= this.z) { if (this.one == null) { this.one = newInstance(this.newsize, this.x + this.newsize, this.z + this.newsize, @@ -107,7 +108,7 @@ public class QuadMap { this.one.add(area); recalculateSkip(); return; - } else if (region.maxZ < this.z) { + } else if (region.getMaximumPoint().getZ() < this.z) { if (this.two == null) { this.two = newInstance(this.newsize, this.x + this.newsize, this.z - this.newsize, @@ -117,8 +118,8 @@ public class QuadMap { recalculateSkip(); return; } - } else if (region.maxX < this.x) { - if (region.minZ >= this.z) { + } else if (region.getMaximumPoint().getX() < this.x) { + if (region.getMinimumPoint().getZ() >= this.z) { if (this.four == null) { this.four = newInstance(this.newsize, this.x - this.newsize, this.z + this.newsize, @@ -127,7 +128,7 @@ public class QuadMap { this.four.add(area); recalculateSkip(); return; - } else if (region.maxZ < this.z) { + } else if (region.getMaximumPoint().getZ() < this.z) { if (this.three == null) { this.three = newInstance(this.newsize, this.x - this.newsize, this.z - this.newsize, @@ -144,14 +145,14 @@ public class QuadMap { this.objects.add(area); } - public RegionWrapper getRegion(T value) { + public CuboidRegion getRegion(T value) { return null; } public QuadMap newInstance(int newsize, int x, int z, int min) { try { return new QuadMap(newsize, x, z, min) { - @Override public RegionWrapper getRegion(T value) { + @Override public CuboidRegion getRegion(T value) { return QuadMap.this.getRegion(value); } }; @@ -172,9 +173,9 @@ public class QuadMap { this.skip = null; } } else { - RegionWrapper region = getRegion(area); - if (region.minX >= this.x) { - if (region.minZ >= this.z) { + CuboidRegion region = getRegion(area); + if (region.getMinimumPoint().getX() >= this.x) { + if (region.getMinimumPoint().getZ() >= this.z) { if (this.one != null) { if (this.one.remove(area)) { this.one = null; @@ -190,7 +191,7 @@ public class QuadMap { } } } else { - if (region.minZ >= this.z) { + if (region.getMinimumPoint().getZ() >= this.z) { if (this.four != null) { if (this.four.remove(area)) { this.four = null; @@ -224,11 +225,11 @@ public class QuadMap { this.skip = map.skip == null ? map : map.skip; } - public Set get(RegionWrapper region) { + public Set get(CuboidRegion region) { HashSet set = new HashSet<>(); if (this.objects != null) { for (T obj : this.objects) { - if (getRegion(obj).intersects(region)) { + if (RegionUtil.intersects(getRegion(obj), region)) { set.add(obj); } } @@ -254,15 +255,15 @@ public class QuadMap { return set; } - public boolean intersects(RegionWrapper other) { - return (other.minX <= this.x + this.size) && (other.maxX >= this.x - this.size) && ( - other.minZ <= this.z + this.size) && (other.maxZ >= this.z - this.size); + public boolean intersects(CuboidRegion other) { + return (other.getMinimumPoint().getX() <= this.x + this.size) && (other.getMaximumPoint().getX() >= this.x - this.size) && ( + other.getMinimumPoint().getZ() <= this.z + this.size) && (other.getMaximumPoint().getZ() >= this.z - this.size); } public T get(int x, int z) { if (this.objects != null) { for (T obj : this.objects) { - if (getRegion(obj).isIn(x, z)) { + if (RegionUtil.contains(getRegion(obj), x, z)) { return obj; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BlockUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/BlockUtil.java similarity index 97% rename from Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BlockUtil.java rename to Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/BlockUtil.java index f377de6e4..6ea6d1c6c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BlockUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/BlockUtil.java @@ -1,4 +1,4 @@ -package com.github.intellectualsites.plotsquared.plot.util.block; +package com.github.intellectualsites.plotsquared.plot.util.world; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.sk89q.worldedit.WorldEdit; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ItemUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/ItemUtil.java similarity index 94% rename from Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ItemUtil.java rename to Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/ItemUtil.java index 243d098ab..415df8fe1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ItemUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/ItemUtil.java @@ -1,4 +1,4 @@ -package com.github.intellectualsites.plotsquared.plot.util.block; +package com.github.intellectualsites.plotsquared.plot.util.world; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.sk89q.worldedit.world.item.ItemType; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/RegionUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/RegionUtil.java new file mode 100644 index 000000000..271f76dac --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/RegionUtil.java @@ -0,0 +1,40 @@ +package com.github.intellectualsites.plotsquared.plot.util.world; + +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; + +public class RegionUtil { + public static CuboidRegion createRegion(int pos1x, int pos2x, int pos1z, int pos2z) { + return createRegion(pos1x, pos2x, 0, Plot.MAX_HEIGHT - 1, pos1z, pos2z); + } + + public static CuboidRegion createRegion(int pos1x, int pos2x, int pos1y, int pos2y, int pos1z, int pos2z) { + BlockVector3 pos1 = BlockVector3.at(pos1x, pos1y, pos1z); + BlockVector3 pos2 = BlockVector3.at(pos2x, pos2y, pos2z); + return new CuboidRegion(pos1, pos2); + } + + public static boolean contains(CuboidRegion region, int x, int z) { + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + return x >= min.getX() && x <= max.getX() && z >= min.getZ() && z <= max.getZ(); + } + + public static boolean contains(CuboidRegion region, int x, int y, int z) { + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + return x >= min.getX() && x <= max.getX() && z >= min.getZ() && z <= max.getZ() && y >= min.getY() && y <= max.getY(); + } + + // Because WE (not fawe) lack this for CuboidRegion + public static boolean intersects(CuboidRegion region, CuboidRegion other) { + BlockVector3 regionMin = region.getMinimumPoint(); + BlockVector3 regionMax = region.getMaximumPoint(); + + BlockVector3 otherMin = other.getMinimumPoint(); + BlockVector3 otherMax = other.getMaximumPoint(); + + return otherMin.getX() <= regionMax.getX() && otherMax.getX() >= regionMin.getX() && otherMin.getZ() <= regionMax.getZ() && otherMax.getZ() >= regionMin.getZ(); + } +} diff --git a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java index 6c322864b..8bbc1193f 100644 --- a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java +++ b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java @@ -8,7 +8,7 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.EventUtilTest; -import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.sk89q.worldedit.world.block.BlockType; import org.junit.Before; import org.junit.Test;