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.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);
}

View File

@ -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();
}

View File

@ -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