use of dev.frankheijden.insights.api.objects.chunk.ChunkLocation in project Insights by InsightsPlugin.
the class PlayerTrackerTask method run.
@Override
public void run() {
var worldStorage = plugin.getWorldStorage();
Set<ChunkLocation> locations = new HashSet<>();
for (Map.Entry<UUID, Player> entry : plugin.getPlayerList()) {
var location = entry.getValue().getLocation();
var world = location.getWorld();
Set<Long> loadedChunks = worldStorage.getWorld(world.getUID()).getChunks();
int chunkX = location.getBlockX() >> 4;
int chunkZ = location.getBlockZ() >> 4;
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
var loc = new ChunkLocation(world, chunkX + x, chunkZ + z);
if (!loadedChunks.contains(loc.getKey()) && !this.scanLocations.containsKey(loc)) {
locations.add(loc);
}
}
}
}
if (locations.isEmpty()) {
return;
}
plugin.getServer().getScheduler().runTask(plugin, () -> {
long now = System.nanoTime();
for (ChunkLocation loc : locations) {
var world = loc.getWorld();
if (world.isChunkLoaded(loc.getX(), loc.getZ())) {
this.scanLocations.put(loc, now);
var chunk = world.getChunkAt(loc.getX(), loc.getZ());
plugin.getChunkContainerExecutor().submit(chunk, ScanOptions.all()).whenComplete((s, e) -> {
if (s == null) {
plugin.getLogger().warning("Error occurred while scanning " + loc);
}
this.scanLocations.remove(loc);
});
}
}
});
}
use of dev.frankheijden.insights.api.objects.chunk.ChunkLocation 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.ChunkLocation 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