use of dev.frankheijden.insights.api.objects.chunk.ChunkPart in project Insights by InsightsPlugin.
the class CommandScanWorld method handleScan.
/**
* Scans chunks in the world of a player.
*/
public void handleScan(Player player, Set<? extends ScanObject<?>> items, ScanOptions options, boolean displayZeros, boolean groupByChunk) {
World world = player.getWorld();
// Generate chunk parts
Chunk[] chunks = world.getLoadedChunks();
List<ChunkPart> chunkParts = new ArrayList<>(chunks.length);
for (Chunk chunk : chunks) {
chunkParts.add(ChunkLocation.of(chunk).toPart());
}
if (groupByChunk) {
ScanTask.scanAndDisplayGroupedByChunk(plugin, player, chunkParts, chunkParts.size(), options, items, false);
} else {
ScanTask.scanAndDisplay(plugin, player, chunkParts, chunkParts.size(), options, items, displayZeros);
}
}
use of dev.frankheijden.insights.api.objects.chunk.ChunkPart in project Insights by InsightsPlugin.
the class Cuboid method toChunkParts.
/**
* Converts this cuboid into a List of ChunkParts.
*/
public List<ChunkPart> toChunkParts() {
ChunkVector minV = ChunkVector.from(this.min);
int minX = this.min.x >> 4;
int minZ = this.min.z >> 4;
ChunkVector maxV = ChunkVector.from(this.max);
int maxX = this.max.x >> 4;
int maxZ = this.max.z >> 4;
List<ChunkPart> parts = new ArrayList<>(maxX - minX + 1 + maxZ - minZ + 1);
for (int x = minX; x <= maxX; x++) {
int xmin = (x == minX) ? minV.getX() : 0;
int ymin = minV.getY();
int xmax = (x == maxX) ? maxV.getX() : 15;
for (int z = minZ; z <= maxZ; z++) {
int zmin = (z == minZ) ? minV.getZ() : 0;
int ymax = maxV.getY();
int zmax = (z == maxZ) ? maxV.getZ() : 15;
ChunkLocation loc = new ChunkLocation(world, x, z);
ChunkVector vmin = new ChunkVector(xmin, ymin, zmin);
ChunkVector vmax = new ChunkVector(xmax, ymax, zmax);
parts.add(new ChunkPart(loc, new ChunkCuboid(vmin, vmax)));
}
}
return parts;
}
use of dev.frankheijden.insights.api.objects.chunk.ChunkPart in project Insights by InsightsPlugin.
the class PistonListener method handlePistonBlock.
private boolean handlePistonBlock(Block from, Block to) {
Optional<Region> regionOptional = plugin.getAddonManager().getRegion(to.getLocation());
// Always allow piston pushes within the same chunk
if (regionOptional.isEmpty() && BlockUtils.isSameChunk(from, to))
return false;
Material material = from.getType();
Optional<Limit> limitOptional = plugin.getLimits().getFirstLimit(material, limit -> true);
// If no limit is present, allow the block to be moved.
if (limitOptional.isEmpty())
return false;
Chunk chunk = to.getChunk();
UUID worldUid = chunk.getWorld().getUID();
long chunkKey = ChunkUtils.getKey(chunk);
boolean queued;
Optional<Storage> storageOptional;
if (regionOptional.isPresent()) {
String key = regionOptional.get().getKey();
queued = plugin.getAddonScanTracker().isQueued(key);
storageOptional = plugin.getAddonStorage().get(key);
} else {
queued = plugin.getWorldChunkScanTracker().isQueued(worldUid, chunkKey);
storageOptional = plugin.getWorldStorage().getWorld(worldUid).get(chunkKey);
}
// If the area is already queued, cancel the event and wait for the area to complete scanning.
if (queued)
return true;
// If the storage is not present, scan it & cancel the event.
if (storageOptional.isEmpty()) {
if (regionOptional.isPresent()) {
Region region = regionOptional.get();
plugin.getAddonScanTracker().add(region.getAddon());
List<ChunkPart> chunkParts = region.toChunkParts();
ScanTask.scan(plugin, chunkParts, chunkParts.size(), ScanOptions.scanOnly(), info -> {
}, storage -> {
plugin.getAddonScanTracker().remove(region.getAddon());
plugin.getAddonStorage().put(region.getKey(), storage);
});
} else {
plugin.getChunkContainerExecutor().submit(chunk);
}
return true;
}
// Else, the storage is present, and we can apply a limit.
Storage storage = storageOptional.get();
Limit limit = limitOptional.get();
LimitInfo limitInfo = limit.getLimit(material);
// Cache doesn't need to updated here just yet, needs to be done in MONITOR event phase.
return storage.count(limit, ScanObject.of(material)) + 1 > limitInfo.getLimit();
}
use of dev.frankheijden.insights.api.objects.chunk.ChunkPart in project Insights by InsightsPlugin.
the class LazyChunkPartRadiusIteratorTest method determineChunkParts.
@ParameterizedTest(name = "Chunk[{0}, {1}], Radius = {2}")
@MethodSource("radiusGenerator")
void determineChunkParts(int chunkX, int chunkZ, int radius) {
World world = Mockito.mock(World.class);
int edge = (2 * radius) + 1;
int chunkCount = edge * edge;
List<ChunkPart> expectedChunkParts = new ArrayList<>(chunkCount);
for (int x = chunkX - radius; x <= chunkX + radius; x++) {
for (int z = chunkZ - radius; z <= chunkZ + radius; z++) {
expectedChunkParts.add(new ChunkLocation(world, x, z).toPart());
}
}
List<ChunkPart> actualChunkParts = new ArrayList<>(chunkCount);
LazyChunkPartRadiusIterator it = new LazyChunkPartRadiusIterator(world, chunkX, chunkZ, radius);
while (it.hasNext()) {
actualChunkParts.add(it.next());
if (actualChunkParts.size() > expectedChunkParts.size()) {
fail("Expected ChunkPart count exceeded of " + expectedChunkParts.size());
}
}
assertThat(actualChunkParts).containsExactlyInAnyOrderElementsOf(expectedChunkParts);
}
Aggregations