Use CuboidRegion instead of RegionWrapper

This commit is contained in:
Jesse Boyd 2019-11-04 21:08:33 +00:00
parent ba3ff08d6c
commit 88732bb88c
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
45 changed files with 357 additions and 348 deletions

View File

@ -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<String, Class<?>> _loadedOBCClasses = new HashMap<>();
private static final Map<Class<?>, Map<String, Field>> _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, <em>including the trailing dot</em>.
*/
@ -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) {

View File

@ -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;

View File

@ -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<ScopedLocalBlockQueue>() {
@ -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);

View File

@ -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<PlotAnalysis> 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();

View File

@ -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<RegionWrapper> regions,
@Override public void getCompoundTag(final String world, final Set<CuboidRegion> regions,
final RunnableVal<CompoundTag> whenDone) {
// async
TaskManager.runTaskAsync(new Runnable() {
@ -74,7 +74,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
List<CompoundTag> tileEntities = new ArrayList<>();
ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length);
// Queue
final ArrayDeque<RegionWrapper> queue = new ArrayDeque<>(regions);
final ArrayDeque<CuboidRegion> 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();

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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<PlotArea> getPlotAreas(final String world, final RegionWrapper region) {
public Set<PlotArea> getPlotAreas(final String world, final CuboidRegion region) {
final PlotArea[] areas = plotAreaManager.getPlotAreas(world, region);
final Set<PlotArea> set = new HashSet<>();
Collections.addAll(set, areas);

View File

@ -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<PlotArea> 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()));
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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<PlotArea> 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)) {

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<PlotAnalysis> whenDone);
public void analyzePlot(final Plot origin, final RunnableVal<PlotAnalysis> whenDone) {
final ArrayDeque<RegionWrapper> zones = new ArrayDeque<>(origin.getRegions());
final ArrayDeque<CuboidRegion> zones = new ArrayDeque<>(origin.getRegions());
final ArrayList<PlotAnalysis> 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<PlotAnalysis>() {
@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<RegionWrapper> sideRoad =
new HashSet<>(Collections.singletonList(new RegionWrapper(sx, ex, sy, ey, sz, ez)));
final Set<RegionWrapper> intersection =
new HashSet<>(Collections.singletonList(new RegionWrapper(sx, ex, sy, ty, bz, tz)));
Set<CuboidRegion> sideRoad =
new HashSet<>(Collections.singletonList(RegionUtil.createRegion(sx, ex, sy, ey, sz, ez)));
final Set<CuboidRegion> 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()

View File

@ -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<RegionWrapper> regions = plot.getRegions();
final Set<CuboidRegion> regions = plot.getRegions();
Runnable run = new Runnable() {
@Override public void run() {
if (regions.isEmpty()) {
whenDone.run();
return;
}
Iterator<RegionWrapper> iterator = regions.iterator();
RegionWrapper region = iterator.next();
Iterator<CuboidRegion> 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);
}
};

View File

@ -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;

View File

@ -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<RegionWrapper> mask;
private final Set<CuboidRegion> 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<RegionWrapper> mask, int max, Extent child,
public ProcessedWEExtent(String world, Set<CuboidRegion> mask, int max, Extent child,
Extent parent) {
super(child);
this.mask = mask;

View File

@ -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<RegionWrapper> mask;
private final Set<CuboidRegion> mask;
public WEExtent(HashSet<RegionWrapper> mask, Extent extent) {
public WEExtent(Set<CuboidRegion> mask, Extent extent) {
super(extent);
this.mask = mask;
}

View File

@ -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<RegionWrapper> mask, int x, int y, int z) {
for (RegionWrapper region : mask) {
if (region.isIn(x, y, z)) {
public static boolean maskContains(Set<CuboidRegion> 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<RegionWrapper> mask, int x, int z) {
for (RegionWrapper region : mask) {
if (region.isIn(x, z)) {
public static boolean maskContains(Set<CuboidRegion> mask, int x, int z) {
for (CuboidRegion region : mask) {
if (RegionUtil.contains(region, x, z)) {
return true;
}
}
return false;
}
public static boolean maskContains(HashSet<RegionWrapper> mask, double dx, double dy,
public static boolean maskContains(Set<CuboidRegion> 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<RegionWrapper> mask, double dx, double dz) {
public static boolean maskContains(Set<CuboidRegion> 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<RegionWrapper> getMask(PlotPlayer player) {
HashSet<RegionWrapper> regions = new HashSet<>();
public static HashSet<CuboidRegion> getMask(PlotPlayer player) {
HashSet<CuboidRegion> 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<RegionWrapper> mask) {
for (RegionWrapper region : mask) {
public static boolean regionContains(CuboidRegion selection, HashSet<CuboidRegion> mask) {
for (CuboidRegion region : mask) {
if (intersects(region, selection)) {
return true;
}

View File

@ -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<RegionWrapper> mask;
Set<CuboidRegion> mask;
if (plotPlayer == null) {
Player player = (Player) actor;
Location location = player.getLocation();

View File

@ -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);
}

View File

@ -27,10 +27,6 @@ public class Location implements Cloneable, Comparable<Location> {
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);
}

View File

@ -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<Plot> connected_cache;
private static HashSet<RegionWrapper> regions_cache;
@Deprecated private static Set<Plot> connected_cache;
private static Set<CuboidRegion> regions_cache;
@NotNull private final PlotId id;
@ -865,7 +867,7 @@ public class Plot {
return false;
}
}
final HashSet<RegionWrapper> regions = this.getRegions();
final Set<CuboidRegion> regions = this.getRegions();
final Set<Plot> plots = this.getConnectedPlots();
final ArrayDeque<Plot> 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<RegionWrapper> regions = new ArrayDeque<>(this.getRegions());
final ArrayDeque<CuboidRegion> 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<int[]>() {
@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<BlockVector2> 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<RegionWrapper> getRegions() {
@NotNull public Set<CuboidRegion> 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<Plot> plots = this.getConnectedPlots();
HashSet<RegionWrapper> regions = regions_cache = new HashSet<>();
HashSet<PlotId> visited = new HashSet<>();
Set<CuboidRegion> regions = regions_cache = new HashSet<>();
Set<PlotId> 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<RegionWrapper> regions = this.getRegions();
RegionWrapper max = null;
public CuboidRegion getLargestRegion() {
Set<CuboidRegion> 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<Location> 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<RegionWrapper> regions = new ArrayDeque<>(this.getRegions());
final ArrayDeque<CuboidRegion> 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<RegionWrapper> regions = new ArrayDeque<>(this.getRegions());
final ArrayDeque<CuboidRegion> 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);

View File

@ -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<String, Object> meta;
private QuadMap<PlotCluster> 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<Plot> 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<PlotCluster>(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));
}
};
}

View File

@ -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;
}

View File

@ -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};
}
}

View File

@ -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<PlotArea> map = this.plotAreaGrid.get(plotArea.worldname);
if (map == null) {
map = new QuadMap<PlotArea>(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) {

View File

@ -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();

View File

@ -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<RegionWrapper> regions = Sets.newHashSet(
new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE,
Integer.MAX_VALUE));
private Set<CuboidRegion> 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<RegionWrapper> getRegions() {
@NotNull @Override public Set<CuboidRegion> getRegions() {
return regions;
}

View File

@ -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;

View File

@ -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 {

View File

@ -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<BlockVector2> task, final Runnable whenDone) {
TaskManager.runTaskAsync(() -> {
HashSet<BlockVector2> 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<int[]> task,
final Runnable whenDone, final int allocate) {
final ArrayList<RegionWrapper> regions = new ArrayList<>(plot.getRegions());
final ArrayList<CuboidRegion> 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);
}
};

View File

@ -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<RegionWrapper> regions) {
@NotNull public static Location[] getCorners(String world, Collection<CuboidRegion> 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);
}

View File

@ -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<RegionWrapper> regions,
public abstract void getCompoundTag(String world, Set<CuboidRegion> regions,
RunnableVal<CompoundTag> whenDone);
public void getCompoundTag(final Plot plot, final RunnableVal<CompoundTag> whenDone) {

View File

@ -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);

View File

@ -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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
this.objects.add(area);
}
public RegionWrapper getRegion(T value) {
public CuboidRegion getRegion(T value) {
return null;
}
public QuadMap<T> newInstance(int newsize, int x, int z, int min) {
try {
return new QuadMap<T>(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<T> {
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<T> {
}
}
} 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<T> {
this.skip = map.skip == null ? map : map.skip;
}
public Set<T> get(RegionWrapper region) {
public Set<T> get(CuboidRegion region) {
HashSet<T> 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<T> {
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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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;