From 6127cdced1894c533064b7036cce49b19765d0db Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 15 Mar 2024 18:49:20 -0700 Subject: [PATCH] Reduce complexity. --- .../bentobox/blueprints/BlueprintPaster.java | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java index 6ea748515..00a067a97 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java @@ -237,25 +237,7 @@ public class BlueprintPaster { 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<>(); - // Paste blocks - while (count < pasteSpeed) { - if (!it.hasNext()) { - break; - } - Entry entry = it.next(); - Location pasteTo = location.clone().add(entry.getKey()); - // pos1 and pos2 update - updatePos(pasteTo); - - BlueprintBlock block = entry.getValue(); - blockMap.put(pasteTo, block); - count++; - } - if (!blockMap.isEmpty()) { - currentTask = useNMS ? paster.pasteBlocks(island, world, blockMap) - : fallback.pasteBlocks(island, world, blockMap); - } + pasteBlocksNow(it, count, pasteSpeed, useNMS); } else { if (pasteState.equals(PasteState.BLOCKS)) { // Blocks done @@ -272,6 +254,29 @@ public class BlueprintPaster { } + private void pasteBlocksNow(Iterator> it, int count, int pasteSpeed, boolean useNMS) { + Map blockMap = new HashMap<>(); + // Paste blocks + while (count < pasteSpeed) { + if (!it.hasNext()) { + break; + } + Entry entry = it.next(); + Location pasteTo = location.clone().add(entry.getKey()); + // pos1 and pos2 update + updatePos(pasteTo); + + BlueprintBlock block = entry.getValue(); + blockMap.put(pasteTo, block); + count++; + } + if (!blockMap.isEmpty()) { + currentTask = useNMS ? paster.pasteBlocks(island, world, blockMap) + : fallback.pasteBlocks(island, world, blockMap); + } + + } + private void loadChunk() { long timer = System.currentTimeMillis(); pasteState = PasteState.CHUNK_LOADING;