2021-07-23 15:48:51 +00:00
|
|
|
package com.fastasyncworldedit.core.extent;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2021-07-24 15:34:05 +00:00
|
|
|
import com.fastasyncworldedit.core.object.FaweLimit;
|
2021-07-23 15:48:51 +00:00
|
|
|
import com.fastasyncworldedit.core.queue.IChunk;
|
|
|
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
|
|
|
import com.fastasyncworldedit.core.queue.IChunkSet;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.extent.Extent;
|
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2019-10-23 04:23:52 +00:00
|
|
|
import com.sk89q.worldedit.regions.RegionIntersection;
|
2020-07-14 02:50:59 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
2020-09-28 10:13:02 +00:00
|
|
|
import java.util.concurrent.Future;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
public class MultiRegionExtent extends FaweRegionExtent {
|
|
|
|
|
2019-10-23 04:23:52 +00:00
|
|
|
private final RegionIntersection intersection;
|
2018-08-12 14:03:07 +00:00
|
|
|
private final Region[] regions;
|
2020-04-30 20:26:52 +00:00
|
|
|
private Region region;
|
2018-08-12 14:03:07 +00:00
|
|
|
private int index;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param extent the extent
|
|
|
|
*/
|
|
|
|
public MultiRegionExtent(Extent extent, FaweLimit limit, Region[] regions) {
|
|
|
|
super(extent, limit);
|
|
|
|
this.index = 0;
|
|
|
|
this.region = regions[0];
|
|
|
|
this.regions = regions;
|
2019-10-23 04:23:52 +00:00
|
|
|
this.intersection = new RegionIntersection(Arrays.asList(regions));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean contains(int x, int y, int z) {
|
|
|
|
if (region.contains(x, y, z)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < regions.length; i++) {
|
|
|
|
if (i != index) {
|
|
|
|
Region current = regions[i];
|
|
|
|
if (current.contains(x, y, z)) {
|
|
|
|
region = current;
|
|
|
|
index = i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-23 14:35:04 +00:00
|
|
|
@Override
|
|
|
|
public boolean processGet(int chunkX, int chunkZ) {
|
|
|
|
for (Region region : regions) {
|
|
|
|
if (region.containsChunk(chunkX, chunkZ)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Override
|
|
|
|
public boolean contains(int x, int z) {
|
|
|
|
if (region.contains(x, z)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < regions.length; i++) {
|
|
|
|
if (i != index) {
|
|
|
|
Region current = regions[i];
|
|
|
|
if (current.contains(x, z)) {
|
|
|
|
region = current;
|
|
|
|
index = i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Collection<Region> getRegions() {
|
|
|
|
return Arrays.asList(regions);
|
|
|
|
}
|
2019-10-23 04:23:52 +00:00
|
|
|
|
|
|
|
@Override
|
2019-10-23 14:35:04 +00:00
|
|
|
public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) {
|
|
|
|
return intersection.processSet(chunk, get, set);
|
2019-10-23 04:23:52 +00:00
|
|
|
}
|
2020-09-28 10:13:02 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Future<IChunkSet> postProcessSet(IChunk chunk, IChunkGet get, IChunkSet set) {
|
|
|
|
return intersection.postProcessSet(chunk, get, set);
|
|
|
|
}
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|