From 03b756b4d9955a2d156e2ef29b0d89dfe3d035ff Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 3 Sep 2016 13:30:38 +1000 Subject: [PATCH] AsyncWorld.java wait for creation to finish --- .../boydti/fawe/bukkit/wrapper/AsyncWorld.java | 18 ++++++++++++++++++ .../src/main/java/com/boydti/fawe/FaweAPI.java | 11 ++++++----- .../com/boydti/fawe/wrappers/WorldWrapper.java | 7 ++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java index c16f1c02..de5474e6 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java @@ -16,6 +16,7 @@ import java.util.Collection; import java.util.List; import java.util.Set; import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; import org.bukkit.BlockChangeDelegate; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -116,6 +117,8 @@ public class AsyncWorld implements World { return queue; } + private static AtomicBoolean loading = new AtomicBoolean(false); + /** * Create a world async (untested) * - Only optimized for 1.10 @@ -123,8 +126,23 @@ public class AsyncWorld implements World { * @return */ public static AsyncWorld create(final WorldCreator creator) { + if (!loading.compareAndSet(false, true)) { + synchronized (loading) { + while (loading.get()) { + try { + loading.wait(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } BukkitQueue_0 queue = (BukkitQueue_0) SetQueue.IMP.getNewQueue(creator.name(), true, false); World world = queue.createWorld(creator); + synchronized (loading) { + loading.set(false); + loading.notifyAll(); + } return wrap(world); } diff --git a/core/src/main/java/com/boydti/fawe/FaweAPI.java b/core/src/main/java/com/boydti/fawe/FaweAPI.java index e01ed734..315ba8fc 100644 --- a/core/src/main/java/com/boydti/fawe/FaweAPI.java +++ b/core/src/main/java/com/boydti/fawe/FaweAPI.java @@ -32,6 +32,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.World; @@ -53,6 +54,7 @@ import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -136,11 +138,10 @@ public class FaweAPI { @Override public void run(OutputStream value) { try { - value.write(new String("test").getBytes()); -// GZIPOutputStream gzip = new GZIPOutputStream(value, true); -// ClipboardWriter writer = format.getWriter(gzip); -// writer.write(clipboard, null); -// gzip.flush(); + GZIPOutputStream gzip = new GZIPOutputStream(value, true); + ClipboardWriter writer = format.getWriter(gzip); + writer.write(clipboard, null); + gzip.flush(); } catch (IOException e) { e.printStackTrace(); } diff --git a/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java b/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java index aaed3fa7..b1cc7488 100644 --- a/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java +++ b/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java @@ -198,7 +198,12 @@ public class WorldWrapper extends LocalWorld { @Override public boolean queueBlockBreakEffect(Platform server, Vector position, int blockId, double priority) { - return parent.queueBlockBreakEffect(server, position, blockId, priority); + try { + return setBlock(position, EditSession.nullBlock, true); + } catch (WorldEditException e) { + e.printStackTrace(); + return false; + } } @Override