From b07d72808b32b85373523ee57a7823ac601f859d Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 22 Jul 2017 17:48:10 +1000 Subject: [PATCH] Might fix #652 --- .../boydti/fawe/bukkit/v0/BukkitQueue_0.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java index c7258cde..d146ad5a 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java @@ -4,6 +4,7 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.bukkit.BukkitPlayer; import com.boydti.fawe.bukkit.FaweBukkit; +import com.boydti.fawe.config.Settings; import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.object.FaweChunk; @@ -216,6 +217,8 @@ public abstract class BukkitQueue_0 extends NMSMa private volatile boolean timingsEnabled; private static boolean alertTimingsChange = true; + private volatile int parallelThreads; + private static Field fieldTimingsEnabled; private static Field fieldAsyncCatcherEnabled; private static Method methodCheck; @@ -236,6 +239,10 @@ public abstract class BukkitQueue_0 extends NMSMa public void startSet(boolean parallel) { ChunkListener.physicsFreeze = true; if (parallel) { + if (Fawe.get().isMainThread()) { + parallelThreads = Settings.IMP.QUEUE.PARALLEL_THREADS; + Settings.IMP.QUEUE.PARALLEL_THREADS = 1; + } try { if (fieldAsyncCatcherEnabled != null) { fieldAsyncCatcherEnabled.set(null, false); @@ -257,6 +264,28 @@ public abstract class BukkitQueue_0 extends NMSMa } } + @Override + public void endSet(boolean parallel) { + ChunkListener.physicsFreeze = false; + if (parallel) { + if (Fawe.get().isMainThread() && parallelThreads != 0) { + Settings.IMP.QUEUE.PARALLEL_THREADS = parallelThreads; + } + try { + if (fieldAsyncCatcherEnabled != null) { + fieldAsyncCatcherEnabled.set(null, true); + } + if (fieldTimingsEnabled != null && timingsEnabled) { + fieldTimingsEnabled.set(null, true); + methodCheck.invoke(null); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + parallelThreads = 0; + } + @Override public void sendBlockUpdate(final FaweChunk chunk, FawePlayer... players) { if (players.length == 0) { @@ -294,22 +323,4 @@ public abstract class BukkitQueue_0 extends NMSMa } }); } - - @Override - public void endSet(boolean parallel) { - ChunkListener.physicsFreeze = false; - if (parallel) { - try { - if (fieldAsyncCatcherEnabled != null) { - fieldAsyncCatcherEnabled.set(null, true); - } - if (fieldTimingsEnabled != null && timingsEnabled) { - fieldTimingsEnabled.set(null, true); - methodCheck.invoke(null); - } - } catch (Throwable e) { - e.printStackTrace(); - } - } - } }