From 41e9bccc67fbc6751939c7c13e2341a988487bd9 Mon Sep 17 00:00:00 2001 From: tastybento Date: Tue, 17 Mar 2020 23:14:43 -0700 Subject: [PATCH] Load chunks async for every block pasted. This loads every chunk async based on the block or entity being pasted. --- .../bentobox/blueprints/BlueprintPaster.java | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java index b22c458f0..a2be71fb6 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java @@ -242,19 +242,20 @@ public class BlueprintPaster { World world = location.getWorld(); Location pasteTo = location.clone().add(entry.getKey()); BlueprintBlock bpBlock = entry.getValue(); - - Block block = pasteTo.getBlock(); - // Set the block data - default is AIR - BlockData bd; - try { - bd = Bukkit.createBlockData(bpBlock.getBlockData()); - } catch (Exception e) { - bd = convertBlockData(world, bpBlock); - } - block.setBlockData(bd, false); - setBlockState(block, bpBlock); - // pos1 and pos2 update - updatePos(block.getLocation()); + Util.getChunkAtAsync(pasteTo).thenRun(() -> { + Block block = pasteTo.getBlock(); + // Set the block data - default is AIR + BlockData bd; + try { + bd = Bukkit.createBlockData(bpBlock.getBlockData()); + } catch (Exception e) { + bd = convertBlockData(world, bpBlock); + } + block.setBlockData(bd, false); + setBlockState(block, bpBlock); + // pos1 and pos2 update + updatePos(block.getLocation()); + }); } /** @@ -337,22 +338,24 @@ public class BlueprintPaster { list.stream().filter(k -> k.getType() != null).forEach(k -> { // Center, and just a bit high Location center = location.add(new Vector(0.5, 0.5, 0.5)); - LivingEntity e = (LivingEntity)location.getWorld().spawnEntity(center, k.getType()); - if (k.getCustomName() != null) { - String customName = k.getCustomName(); + Util.getChunkAtAsync(center).thenRun(() -> { + LivingEntity e = (LivingEntity)location.getWorld().spawnEntity(center, k.getType()); + if (k.getCustomName() != null) { + String customName = k.getCustomName(); - if (island != null) { - // Parse any placeholders in the entity's name, if the owner's connected (he should) - Player owner = User.getInstance(island.getOwner()).getPlayer(); - if (owner != null) { - customName = plugin.getPlaceholdersManager().replacePlaceholders(owner, customName); + if (island != null) { + // Parse any placeholders in the entity's name, if the owner's connected (he should) + Player owner = User.getInstance(island.getOwner()).getPlayer(); + if (owner != null) { + customName = plugin.getPlaceholdersManager().replacePlaceholders(owner, customName); + } } - } - // Actually set the custom name - e.setCustomName(customName); - } - k.configureEntity(e); + // Actually set the custom name + e.setCustomName(customName); + } + k.configureEntity(e); + }); }); }