Search in sources :

Example 1 with ChunkStorage

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;
}
Also used : WorldStorage(dev.frankheijden.insights.api.concurrent.storage.WorldStorage) Storage(dev.frankheijden.insights.api.concurrent.storage.Storage) ChunkStorage(dev.frankheijden.insights.api.concurrent.storage.ChunkStorage) WorldStorage(dev.frankheijden.insights.api.concurrent.storage.WorldStorage) AddonStorage(dev.frankheijden.insights.api.concurrent.storage.AddonStorage) DistributionStorage(dev.frankheijden.insights.api.concurrent.storage.DistributionStorage) ChunkStorage(dev.frankheijden.insights.api.concurrent.storage.ChunkStorage) UUID(java.util.UUID)

Aggregations

AddonStorage (dev.frankheijden.insights.api.concurrent.storage.AddonStorage)1 ChunkStorage (dev.frankheijden.insights.api.concurrent.storage.ChunkStorage)1 DistributionStorage (dev.frankheijden.insights.api.concurrent.storage.DistributionStorage)1 Storage (dev.frankheijden.insights.api.concurrent.storage.Storage)1 WorldStorage (dev.frankheijden.insights.api.concurrent.storage.WorldStorage)1 UUID (java.util.UUID)1