diff --git a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java index 432904244..a11a8cbb4 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java @@ -58,6 +58,7 @@ public class BlueprintPaster { private final BentoBox plugin; private final PasteHandler paster = Util.getPasteHandler(); + private final PasteHandler fallback = new world.bentobox.bentobox.nms.fallback.PasteHandlerImpl(); private final World world; // The minimum block position (x,y,z) private Location pos1; @@ -127,10 +128,20 @@ public class BlueprintPaster { Iterator> it2, Iterator>> it3, int pasteSpeed) {} + /** * The main pasting method */ public CompletableFuture paste() { + return this.paste(false); + } + + /** + * Paste the clipboard + * @param useNMS if true, NMS pasting will be used, otherwise Bukkit API + * @return Future boolean where true is success + */ + public CompletableFuture paste(boolean useNMS) { CompletableFuture result = new CompletableFuture<>(); // Iterators for the various maps to paste final Map blocks = blueprint.getBlocks() == null ? Collections.emptyMap() : blueprint.getBlocks(); @@ -148,12 +159,12 @@ public class BlueprintPaster { Bits bits = new Bits(blocks, attached, entities, blocks.entrySet().iterator(), attached.entrySet().iterator(), entities.entrySet().iterator(), plugin.getSettings().getPasteSpeed()); - pastingTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> pasterTask(result, owner, bits), 0L, 1L); + pastingTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> pasterTask(result, owner, bits, useNMS), 0L, 1L); return result; } - private void pasterTask(CompletableFuture result, Optional owner, Bits bits) { + private void pasterTask(CompletableFuture result, Optional owner, Bits bits, boolean useNMS) { if (!currentTask.isDone()) return; final int pasteSpeed = plugin.getSettings().getPasteSpeed(); @@ -163,10 +174,10 @@ public class BlueprintPaster { loadChunk(); } else if (pasteState.equals(PasteState.BLOCKS) || pasteState.equals(PasteState.ATTACHMENTS)) { - pasteBlocks(bits, count, owner, pasteSpeed); + pasteBlocks(bits, count, owner, pasteSpeed, useNMS); } else if (pasteState.equals(PasteState.ENTITIES)) { - pasteEntities(bits, count, owner, pasteSpeed); + pasteEntities(bits, count, owner, pasteSpeed, useNMS); } else if (pasteState.equals(PasteState.DONE)) { // All done. Cancel task @@ -188,7 +199,7 @@ public class BlueprintPaster { result.complete(true); } - private void pasteEntities(Bits bits, int count, Optional owner, int pasteSpeed) { + private void pasteEntities(Bits bits, int count, Optional owner, int pasteSpeed, boolean useNMS) { if (bits.it3().hasNext()) { Map> entityMap = new HashMap<>(); // Paste entities @@ -206,7 +217,8 @@ public class BlueprintPaster { count++; } if (!entityMap.isEmpty()) { - currentTask = paster.pasteEntities(island, world, entityMap); + currentTask = useNMS ? paster.pasteEntities(island, world, entityMap) + : fallback.pasteEntities(island, world, entityMap); } } else { pasteState = PasteState.DONE; @@ -222,7 +234,7 @@ public class BlueprintPaster { } - private void pasteBlocks(Bits bits, int count, Optional owner, int pasteSpeed) { + private void pasteBlocks(Bits bits, int count, Optional owner, int pasteSpeed, boolean useNMS) { Iterator> it = pasteState.equals(PasteState.BLOCKS) ? bits.it : bits.it2; if (it.hasNext()) { Map blockMap = new HashMap<>(); @@ -241,7 +253,8 @@ public class BlueprintPaster { count++; } if (!blockMap.isEmpty()) { - currentTask = paster.pasteBlocks(island, world, blockMap); + currentTask = useNMS ? paster.pasteBlocks(island, world, blockMap) + : fallback.pasteBlocks(island, world, blockMap); } } else { if (pasteState.equals(PasteState.BLOCKS)) { diff --git a/src/main/java/world/bentobox/bentobox/nms/fallback/PasteHandlerImpl.java b/src/main/java/world/bentobox/bentobox/nms/fallback/PasteHandlerImpl.java index 81aef5a4f..3a082eaa0 100644 --- a/src/main/java/world/bentobox/bentobox/nms/fallback/PasteHandlerImpl.java +++ b/src/main/java/world/bentobox/bentobox/nms/fallback/PasteHandlerImpl.java @@ -8,6 +8,7 @@ import java.util.stream.Collectors; import org.bukkit.Location; import org.bukkit.World; +import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBlock; import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity; import world.bentobox.bentobox.database.objects.Island; @@ -17,6 +18,7 @@ import world.bentobox.bentobox.util.DefaultPasteUtil; public class PasteHandlerImpl implements PasteHandler { @Override public CompletableFuture pasteBlocks(Island island, World world, Map blockMap) { + BentoBox.getInstance().logDebug("fallback paste"); return blockMap.entrySet().stream() .map(entry -> setBlock(island, entry.getKey(), entry.getValue())) .collect( diff --git a/src/main/java/world/bentobox/bentobox/nms/v1_20_R3/PasteHandlerImpl.java b/src/main/java/world/bentobox/bentobox/nms/v1_20_R3/PasteHandlerImpl.java index e06b032fa..a04603f25 100644 --- a/src/main/java/world/bentobox/bentobox/nms/v1_20_R3/PasteHandlerImpl.java +++ b/src/main/java/world/bentobox/bentobox/nms/v1_20_R3/PasteHandlerImpl.java @@ -11,6 +11,7 @@ import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; import net.minecraft.core.BlockPosition; import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.chunk.Chunk; +import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBlock; import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.nms.PasteHandler; @@ -30,6 +31,7 @@ public class PasteHandlerImpl implements PasteHandler { */ @Override public CompletableFuture setBlock(Island island, Location location, BlueprintBlock bpBlock) { + BentoBox.getInstance().logDebug("nms paste"); return Util.getChunkAtAsync(location).thenRun(() -> { Block block = location.getBlock(); // Set the block data - default is AIR