use of dev.frankheijden.insights.api.concurrent.storage.ChunkStorage in project Insights by InsightsPlugin.
the class InsightsListener method handleChunkAddition.
private Optional<Storage> handleChunkAddition(Player player, Chunk chunk, Consumer<Storage> storageConsumer) {
UUID worldUid = chunk.getWorld().getUID();
long chunkKey = ChunkUtils.getKey(chunk);
WorldStorage worldStorage = plugin.getWorldStorage();
ChunkStorage chunkStorage = worldStorage.getWorld(worldUid);
Optional<Storage> storageOptional = chunkStorage.get(chunkKey);
// If the chunk is not known
if (storageOptional.isEmpty()) {
// Notify the user scan started
if (plugin.getSettings().canReceiveAreaScanNotifications(player)) {
plugin.getMessages().getMessage(Messages.Key.AREA_SCAN_STARTED).addTemplates(Messages.tagOf("area", "chunk")).sendTo(player);
}
// Submit the chunk for scanning
plugin.getChunkContainerExecutor().submit(chunk).thenAccept(storageConsumer).exceptionally(th -> {
plugin.getLogger().log(Level.SEVERE, th, th::getMessage);
return null;
});
}
return storageOptional;
}
Aggregations