AsyncWorld.java wait for creation to finish

This commit is contained in:
Jesse Boyd 2016-09-03 13:30:38 +10:00
parent 4aeb29ebd3
commit 03b756b4d9
3 changed files with 30 additions and 6 deletions

View File

@ -16,6 +16,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import org.bukkit.BlockChangeDelegate; import org.bukkit.BlockChangeDelegate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -116,6 +117,8 @@ public class AsyncWorld implements World {
return queue; return queue;
} }
private static AtomicBoolean loading = new AtomicBoolean(false);
/** /**
* Create a world async (untested) * Create a world async (untested)
* - Only optimized for 1.10 * - Only optimized for 1.10
@ -123,8 +126,23 @@ public class AsyncWorld implements World {
* @return * @return
*/ */
public static AsyncWorld create(final WorldCreator creator) { 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); BukkitQueue_0 queue = (BukkitQueue_0) SetQueue.IMP.getNewQueue(creator.name(), true, false);
World world = queue.createWorld(creator); World world = queue.createWorld(creator);
synchronized (loading) {
loading.set(false);
loading.notifyAll();
}
return wrap(world); return wrap(world);
} }

View File

@ -32,6 +32,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; 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.regions.Region;
import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
@ -53,6 +54,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -136,11 +138,10 @@ public class FaweAPI {
@Override @Override
public void run(OutputStream value) { public void run(OutputStream value) {
try { try {
value.write(new String("test").getBytes()); GZIPOutputStream gzip = new GZIPOutputStream(value, true);
// GZIPOutputStream gzip = new GZIPOutputStream(value, true); ClipboardWriter writer = format.getWriter(gzip);
// ClipboardWriter writer = format.getWriter(gzip); writer.write(clipboard, null);
// writer.write(clipboard, null); gzip.flush();
// gzip.flush();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -198,7 +198,12 @@ public class WorldWrapper extends LocalWorld {
@Override @Override
public boolean queueBlockBreakEffect(Platform server, Vector position, int blockId, double priority) { 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 @Override