Lambda's and References and Cleanups! Oh My!

This commit is contained in:
matt 2019-03-27 12:17:05 -04:00
parent 1424998327
commit acc8eb0a99
12 changed files with 291 additions and 462 deletions

View File

@ -5,7 +5,7 @@ import org.bukkit.World;
public abstract class PaperChunkCallback { public abstract class PaperChunkCallback {
public PaperChunkCallback(World world, int x, int z) { public PaperChunkCallback(World world, int x, int z) {
world.getChunkAtAsync(x, z, chunk -> PaperChunkCallback.this.onLoad(chunk)); world.getChunkAtAsync(x, z, PaperChunkCallback.this::onLoad);
} }
public abstract void onLoad(Chunk chunk); public abstract void onLoad(Chunk chunk);

View File

@ -152,10 +152,10 @@ public class Fawe {
* The platform specific implementation * The platform specific implementation
*/ */
private final IFawe IMP; private final IFawe IMP;
private Thread thread = Thread.currentThread(); private Thread thread;
private Fawe(final IFawe implementation) { private Fawe(final IFawe implementation) {
this.INSTANCE = this; INSTANCE = this;
this.IMP = implementation; this.IMP = implementation;
this.thread = Thread.currentThread(); this.thread = Thread.currentThread();
/* /*
@ -164,26 +164,18 @@ public class Fawe {
this.setupConfigs(); this.setupConfigs();
TaskManager.IMP = this.IMP.getTaskManager(); TaskManager.IMP = this.IMP.getTaskManager();
TaskManager.IMP.async(new Runnable() { TaskManager.IMP.async(() -> {
@Override
public void run() {
MainUtil.deleteOlder(MainUtil.getFile(IMP.getDirectory(), Settings.IMP.PATHS.HISTORY), TimeUnit.DAYS.toMillis(Settings.IMP.HISTORY.DELETE_AFTER_DAYS), false); MainUtil.deleteOlder(MainUtil.getFile(IMP.getDirectory(), Settings.IMP.PATHS.HISTORY), TimeUnit.DAYS.toMillis(Settings.IMP.HISTORY.DELETE_AFTER_DAYS), false);
MainUtil.deleteOlder(MainUtil.getFile(IMP.getDirectory(), Settings.IMP.PATHS.CLIPBOARD), TimeUnit.DAYS.toMillis(Settings.IMP.CLIPBOARD.DELETE_AFTER_DAYS), false); MainUtil.deleteOlder(MainUtil.getFile(IMP.getDirectory(), Settings.IMP.PATHS.CLIPBOARD), TimeUnit.DAYS.toMillis(Settings.IMP.CLIPBOARD.DELETE_AFTER_DAYS), false);
}
}); });
if (Settings.IMP.METRICS) { if (Settings.IMP.METRICS) {
try { try {
this.stats = new BStats(); this.stats = new BStats();
this.IMP.startMetrics(); this.IMP.startMetrics();
TaskManager.IMP.later(new Runnable() { TaskManager.IMP.later(() -> stats.start(), 1);
@Override } catch (Throwable throwable) {
public void run() { throwable.printStackTrace();
stats.start();
}
}, 1);
} catch (Throwable ignore) {
ignore.printStackTrace();
} }
} }
/* /*
@ -216,7 +208,7 @@ public class Fawe {
WEManager.IMP.managers.addAll(Fawe.this.IMP.getMaskManagers()); WEManager.IMP.managers.addAll(Fawe.this.IMP.getMaskManagers());
WEManager.IMP.managers.add(new PlotSquaredFeature()); WEManager.IMP.managers.add(new PlotSquaredFeature());
Fawe.debug("Plugin 'PlotSquared' found. Using it now."); Fawe.debug("Plugin 'PlotSquared' found. Using it now.");
} catch (Throwable e) {} } catch (Throwable ignored) {}
}, 0); }, 0);
TaskManager.IMP.repeat(timer, 1); TaskManager.IMP.repeat(timer, 1);
@ -224,8 +216,8 @@ public class Fawe {
if (!Settings.IMP.UPDATE.equalsIgnoreCase("false")) { if (!Settings.IMP.UPDATE.equalsIgnoreCase("false")) {
// Delayed updating // Delayed updating
updater = new Updater(); updater = new Updater();
TaskManager.IMP.async(() -> update()); TaskManager.IMP.async(this::update);
TaskManager.IMP.repeatAsync(() -> update(), 36000); TaskManager.IMP.repeatAsync(this::update, 36000);
} }
} }
@ -452,16 +444,13 @@ public class Fawe {
final MemoryMXBean memBean = ManagementFactory.getMemoryMXBean(); final MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
final NotificationEmitter ne = (NotificationEmitter) memBean; final NotificationEmitter ne = (NotificationEmitter) memBean;
ne.addNotificationListener(new NotificationListener() { ne.addNotificationListener((notification, handback) -> {
@Override
public void handleNotification(final Notification notification, final Object handback) {
final long heapSize = Runtime.getRuntime().totalMemory(); final long heapSize = Runtime.getRuntime().totalMemory();
final long heapMaxSize = Runtime.getRuntime().maxMemory(); final long heapMaxSize = Runtime.getRuntime().maxMemory();
if (heapSize < heapMaxSize) { if (heapSize < heapMaxSize) {
return; return;
} }
MemUtil.memoryLimitedTask(); MemUtil.memoryLimitedTask();
}
}, null, null); }, null, null);
final List<MemoryPoolMXBean> memPools = ManagementFactory.getMemoryPoolMXBeans(); final List<MemoryPoolMXBean> memPools = ManagementFactory.getMemoryPoolMXBeans();

View File

@ -111,12 +111,7 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> impl
map.forEachChunk(new RunnableVal<FaweChunk>() { map.forEachChunk(new RunnableVal<FaweChunk>() {
@Override @Override
public void run(final FaweChunk chunk) { public void run(final FaweChunk chunk) {
pool.submit(new Runnable() { pool.submit(chunk::optimize);
@Override
public void run() {
chunk.optimize();
}
});
} }
}); });
pool.awaitQuiescence(Long.MAX_VALUE, TimeUnit.MILLISECONDS); pool.awaitQuiescence(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
@ -300,8 +295,8 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> impl
@Override @Override
public boolean supports(Capability capability) { public boolean supports(Capability capability) {
switch (capability) { if (capability == Capability.CHANGE_TASKS) {
case CHANGE_TASKS: return true; return true;
} }
return false; return false;
} }
@ -416,12 +411,7 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> impl
public boolean queueChunkLoad(final int cx, final int cz) { public boolean queueChunkLoad(final int cx, final int cz) {
CHUNK chunk = getCachedChunk(getWorld(), cx, cz); CHUNK chunk = getCachedChunk(getWorld(), cx, cz);
if (chunk == null) { if (chunk == null) {
SetQueue.IMP.addTask(new Runnable() { SetQueue.IMP.addTask(() -> loadChunk(getWorld(), cx, cz, true));
@Override
public void run() {
loadChunk(getWorld(), cx, cz, true);
}
});
return true; return true;
} }
return false; return false;
@ -430,12 +420,9 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> impl
public boolean queueChunkLoad(final int cx, final int cz, RunnableVal<CHUNK> operation) { public boolean queueChunkLoad(final int cx, final int cz, RunnableVal<CHUNK> operation) {
operation.value = getCachedChunk(getWorld(), cx, cz); operation.value = getCachedChunk(getWorld(), cx, cz);
if (operation.value == null) { if (operation.value == null) {
SetQueue.IMP.addTask(new Runnable() { SetQueue.IMP.addTask(() -> {
@Override
public void run() {
operation.value = loadChunk(getWorld(), cx, cz, true); operation.value = loadChunk(getWorld(), cx, cz, true);
if (operation.value != null) TaskManager.IMP.async(operation); if (operation.value != null) TaskManager.IMP.async(operation);
}
}); });
return true; return true;
} else { } else {

View File

@ -40,15 +40,12 @@ public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> ex
public void runTasks() { public void runTasks() {
super.runTasks(); super.runTasks();
if (!getRelighter().isEmpty()) { if (!getRelighter().isEmpty()) {
TaskManager.IMP.async(new Runnable() { TaskManager.IMP.async(() -> {
@Override
public void run() {
if (getSettings().IMP.LIGHTING.REMOVE_FIRST) { if (getSettings().IMP.LIGHTING.REMOVE_FIRST) {
getRelighter().removeAndRelight(hasSky()); getRelighter().removeAndRelight(hasSky());
} else { } else {
getRelighter().fixLightingSafe(hasSky()); getRelighter().fixLightingSafe(hasSky());
} }
}
}); });
} }
} }

View File

@ -133,9 +133,7 @@ public class SchematicStreamer extends NBTStreamer {
addReader("Schematic.Biomes.#", biomeReader); // FAWE stores as a byte[] (4x smaller) addReader("Schematic.Biomes.#", biomeReader); // FAWE stores as a byte[] (4x smaller)
// Tiles // Tiles
addReader("Schematic.TileEntities.#", new BiConsumer<Integer, CompoundTag>() { addReader("Schematic.TileEntities.#", (BiConsumer<Integer, CompoundTag>) (index, value) -> {
@Override
public void accept(Integer index, CompoundTag value) {
if (fc == null) { if (fc == null) {
setupClipboard(0); setupClipboard(0);
} }
@ -143,12 +141,9 @@ public class SchematicStreamer extends NBTStreamer {
int y = value.getInt("y"); int y = value.getInt("y");
int z = value.getInt("z"); int z = value.getInt("z");
fc.setTile(x, y, z, value); fc.setTile(x, y, z, value);
}
}); });
// Entities // Entities
addReader("Schematic.Entities.#", new BiConsumer<Integer, CompoundTag>() { addReader("Schematic.Entities.#", (BiConsumer<Integer, CompoundTag>) (index, compound) -> {
@Override
public void accept(Integer index, CompoundTag compound) {
if (fc == null) { if (fc == null) {
setupClipboard(0); setupClipboard(0);
} }
@ -166,7 +161,6 @@ public class SchematicStreamer extends NBTStreamer {
} else { } else {
Fawe.debug("Invalid entity: " + id); Fawe.debug("Invalid entity: " + id);
} }
}
}); });
} }
@ -345,60 +339,23 @@ public class SchematicStreamer extends NBTStreamer {
} }
public void addDimensionReaders() { public void addDimensionReaders() {
addReader("Schematic.Height", new BiConsumer<Integer, Short>() { addReader("Schematic.Height",
@Override (BiConsumer<Integer, Short>) (index, value) -> height = (value));
public void accept(Integer index, Short value) { addReader("Schematic.Width", (BiConsumer<Integer, Short>) (index, value) -> width = (value));
height = (value); addReader("Schematic.Length",
} (BiConsumer<Integer, Short>) (index, value) -> length = (value));
}); addReader("Schematic.WEOriginX",
addReader("Schematic.Width", new BiConsumer<Integer, Short>() { (BiConsumer<Integer, Integer>) (index, value) -> originX = (value));
@Override addReader("Schematic.WEOriginY",
public void accept(Integer index, Short value) { (BiConsumer<Integer, Integer>) (index, value) -> originY = (value));
width = (value); addReader("Schematic.WEOriginZ",
} (BiConsumer<Integer, Integer>) (index, value) -> originZ = (value));
}); addReader("Schematic.WEOffsetX",
addReader("Schematic.Length", new BiConsumer<Integer, Short>() { (BiConsumer<Integer, Integer>) (index, value) -> offsetX = (value));
@Override addReader("Schematic.WEOffsetY",
public void accept(Integer index, Short value) { (BiConsumer<Integer, Integer>) (index, value) -> offsetY = (value));
length = (value); addReader("Schematic.WEOffsetZ",
} (BiConsumer<Integer, Integer>) (index, value) -> offsetZ = (value));
});
addReader("Schematic.WEOriginX", new BiConsumer<Integer, Integer>() {
@Override
public void accept(Integer index, Integer value) {
originX = (value);
}
});
addReader("Schematic.WEOriginY", new BiConsumer<Integer, Integer>() {
@Override
public void accept(Integer index, Integer value) {
originY = (value);
}
});
addReader("Schematic.WEOriginZ", new BiConsumer<Integer, Integer>() {
@Override
public void accept(Integer index, Integer value) {
originZ = (value);
}
});
addReader("Schematic.WEOffsetX", new BiConsumer<Integer, Integer>() {
@Override
public void accept(Integer index, Integer value) {
offsetX = (value);
}
});
addReader("Schematic.WEOffsetY", new BiConsumer<Integer, Integer>() {
@Override
public void accept(Integer index, Integer value) {
offsetY = (value);
}
});
addReader("Schematic.WEOffsetZ", new BiConsumer<Integer, Integer>() {
@Override
public void accept(Integer index, Integer value) {
offsetZ = (value);
}
});
} }
private int height; private int height;

View File

@ -91,9 +91,7 @@ public class MCAChunk extends FaweChunk<Void> {
public void write(NBTOutputStream nbtOut) throws IOException { public void write(NBTOutputStream nbtOut) throws IOException {
nbtOut.writeNamedTagName("", NBTConstants.TYPE_COMPOUND); nbtOut.writeNamedTagName("", NBTConstants.TYPE_COMPOUND);
nbtOut.writeLazyCompoundTag("Level", new NBTOutputStream.LazyWrite() { nbtOut.writeLazyCompoundTag("Level", out -> {
@Override
public void write(NBTOutputStream out) throws IOException {
out.writeNamedTag("V", (byte) 1); out.writeNamedTag("V", (byte) 1);
out.writeNamedTag("xPos", getX()); out.writeNamedTag("xPos", getX());
out.writeNamedTag("zPos", getZ()); out.writeNamedTag("zPos", getZ());
@ -135,7 +133,6 @@ public class MCAChunk extends FaweChunk<Void> {
out.writeNamedTag("Data", data[layer]); out.writeNamedTag("Data", data[layer]);
out.writeEndTag(); out.writeEndTag();
} }
}
}); });
nbtOut.writeEndTag(); nbtOut.writeEndTag();
} }
@ -464,74 +461,43 @@ public class MCAChunk extends FaweChunk<Void> {
skyLight = new byte[16][]; skyLight = new byte[16][];
blockLight = new byte[16][]; blockLight = new byte[16][];
NBTStreamer streamer = new NBTStreamer(nis); NBTStreamer streamer = new NBTStreamer(nis);
streamer.addReader(".Level.InhabitedTime", new BiConsumer<Integer, Long>() { streamer.addReader(".Level.InhabitedTime",
@Override (BiConsumer<Integer, Long>) (index, value) -> inhabitedTime = value);
public void accept(Integer index, Long value) { streamer.addReader(".Level.LastUpdate",
inhabitedTime = value; (BiConsumer<Integer, Long>) (index, value) -> lastUpdate = value);
} streamer.addReader(".Level.Sections.#", (BiConsumer<Integer, CompoundTag>) (index, tag) -> {
});
streamer.addReader(".Level.LastUpdate", new BiConsumer<Integer, Long>() {
@Override
public void accept(Integer index, Long value) {
lastUpdate = value;
}
});
streamer.addReader(".Level.Sections.#", new BiConsumer<Integer, CompoundTag>() {
@Override
public void accept(Integer index, CompoundTag tag) {
int layer = tag.getByte("Y"); int layer = tag.getByte("Y");
ids[layer] = tag.getByteArray("Blocks"); ids[layer] = tag.getByteArray("Blocks");
data[layer] = tag.getByteArray("Data"); data[layer] = tag.getByteArray("Data");
skyLight[layer] = tag.getByteArray("SkyLight"); skyLight[layer] = tag.getByteArray("SkyLight");
blockLight[layer] = tag.getByteArray("BlockLight"); blockLight[layer] = tag.getByteArray("BlockLight");
}
}); });
streamer.addReader(".Level.TileEntities.#", new BiConsumer<Integer, CompoundTag>() { streamer.addReader(".Level.TileEntities.#",
@Override (BiConsumer<Integer, CompoundTag>) (index, tile) -> {
public void accept(Integer index, CompoundTag tile) { int x1 = tile.getInt("x") & 15;
int x = tile.getInt("x") & 15;
int y = tile.getInt("y"); int y = tile.getInt("y");
int z = tile.getInt("z") & 15; int z1 = tile.getInt("z") & 15;
short pair = MathMan.tripleBlockCoord(x, y, z); short pair = MathMan.tripleBlockCoord(x1, y, z1);
tiles.put(pair, tile); tiles.put(pair, tile);
}
}); });
streamer.addReader(".Level.Entities.#", new BiConsumer<Integer, CompoundTag>() { streamer.addReader(".Level.Entities.#",
@Override (BiConsumer<Integer, CompoundTag>) (index, entityTag) -> {
public void accept(Integer index, CompoundTag entityTag) {
if (entities == null) { if (entities == null) {
entities = new HashMap<>(); entities = new HashMap<>();
} }
long least = entityTag.getLong("UUIDLeast"); long least = entityTag.getLong("UUIDLeast");
long most = entityTag.getLong("UUIDMost"); long most = entityTag.getLong("UUIDMost");
entities.put(new UUID(most, least), entityTag); entities.put(new UUID(most, least), entityTag);
}
});
streamer.addReader(".Level.Biomes", new BiConsumer<Integer, byte[]>() {
@Override
public void accept(Integer index, byte[] value) {
biomes = value;
}
});
streamer.addReader(".Level.HeightMap", new BiConsumer<Integer, int[]>() {
@Override
public void accept(Integer index, int[] value) {
heightMap = value;
}
}); });
streamer.addReader(".Level.Biomes",
(BiConsumer<Integer, byte[]>) (index, value) -> biomes = value);
streamer.addReader(".Level.HeightMap",
(BiConsumer<Integer, int[]>) (index, value) -> heightMap = value);
if (readPos) { if (readPos) {
streamer.addReader(".Level.xPos", new BiConsumer<Integer, Integer>() { streamer.addReader(".Level.xPos",
@Override (BiConsumer<Integer, Integer>) (index, value) -> MCAChunk.this.setLoc(getParent(), value, getZ()));
public void accept(Integer index, Integer value) { streamer.addReader(".Level.zPos",
MCAChunk.this.setLoc(getParent(), value, getZ()); (BiConsumer<Integer, Integer>) (index, value) -> MCAChunk.this.setLoc(getParent(), getX(), value));
}
});
streamer.addReader(".Level.zPos", new BiConsumer<Integer, Integer>() {
@Override
public void accept(Integer index, Integer value) {
MCAChunk.this.setLoc(getParent(), getX(), value);
}
});
} }
streamer.readFully(); streamer.readFully();
} }

View File

@ -9,7 +9,6 @@ import com.boydti.fawe.object.brush.visualization.VirtualWorld;
import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard; import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard;
import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.object.task.SimpleAsyncNotifyQueue; import com.boydti.fawe.object.task.SimpleAsyncNotifyQueue;
import com.boydti.fawe.object.task.ThrowableSupplier;
import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.*; import com.boydti.fawe.util.*;
import com.boydti.fawe.wrappers.FakePlayer; import com.boydti.fawe.wrappers.FakePlayer;
@ -17,8 +16,7 @@ import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
import com.boydti.fawe.wrappers.PlayerWrapper; import com.boydti.fawe.wrappers.PlayerWrapper;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.tool.Tool;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.*; import com.sk89q.worldedit.extension.platform.*;
@ -41,7 +39,6 @@ import java.text.NumberFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
public abstract class FawePlayer<T> extends Metadatable { public abstract class FawePlayer<T> extends Metadatable {
@ -164,18 +161,10 @@ public abstract class FawePlayer<T> extends Metadatable {
private void setConfirmTask(@Nullable Runnable task, CommandContext context, String command) { private void setConfirmTask(@Nullable Runnable task, CommandContext context, String command) {
if (task != null) { if (task != null) {
Runnable newTask = new Runnable() { Runnable newTask = () -> CommandManager.getInstance().handleCommandTask(() -> {
@Override
public void run() {
CommandManager.getInstance().handleCommandTask(new ThrowableSupplier<Throwable>() {
@Override
public Object get() throws Throwable {
task.run(); task.run();
return null; return null;
}
}, context.getLocals()); }, context.getLocals());
}
};
setMeta("cmdConfirm", newTask); setMeta("cmdConfirm", newTask);
} else { } else {
setMeta("cmdConfirm", new CommandEvent(getPlayer(), command)); setMeta("cmdConfirm", new CommandEvent(getPlayer(), command));
@ -365,15 +354,15 @@ public abstract class FawePlayer<T> extends Metadatable {
} }
} catch (EmptyClipboardException e) { } catch (EmptyClipboardException e) {
} }
if (player != null && session != null) { if (player != null) {
Clipboard clip = doc.toClipboard(); Clipboard clip = doc.toClipboard();
ClipboardHolder holder = new ClipboardHolder(clip); ClipboardHolder holder = new ClipboardHolder(clip);
getSession().setClipboard(holder); getSession().setClipboard(holder);
} }
} }
} catch (Exception ignore) { } catch (Exception event) {
Fawe.debug("====== INVALID CLIPBOARD ======"); Fawe.debug("====== INVALID CLIPBOARD ======");
MainUtil.handleError(ignore, false); MainUtil.handleError(event, false);
Fawe.debug("===============---============="); Fawe.debug("===============---=============");
Fawe.debug("This shouldn't result in any failure"); Fawe.debug("This shouldn't result in any failure");
Fawe.debug("File: " + file.getName() + " (len:" + file.length() + ")"); Fawe.debug("File: " + file.getName() + " (len:" + file.length() + ")");

View File

@ -73,12 +73,10 @@ public class SetQueue {
public SetQueue() { public SetQueue() {
tasks = new ConcurrentLinkedDeque<>(); tasks = new ConcurrentLinkedDeque<>();
activeQueues = new ConcurrentLinkedDeque(); activeQueues = new ConcurrentLinkedDeque<>();
inactiveQueues = new ConcurrentLinkedDeque<>(); inactiveQueues = new ConcurrentLinkedDeque<>();
if (TaskManager.IMP == null) return; if (TaskManager.IMP == null) return;
TaskManager.IMP.repeat(new Runnable() { TaskManager.IMP.repeat(() -> {
@Override
public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
boolean empty = (inactiveQueues.isEmpty() && activeQueues.isEmpty()); boolean empty = (inactiveQueues.isEmpty() && activeQueues.isEmpty());
@ -187,7 +185,6 @@ public class SetQueue {
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
}
}, 1); }, 1);
} }
@ -264,7 +261,7 @@ public class SetQueue {
public void flush(FaweQueue queue) { public void flush(FaweQueue queue) {
int parallelThreads; int parallelThreads;
if (Fawe.get().isMainThread()) { if (Fawe.isMainThread()) {
parallelThreads = Settings.IMP.QUEUE.PARALLEL_THREADS; parallelThreads = Settings.IMP.QUEUE.PARALLEL_THREADS;
Settings.IMP.QUEUE.PARALLEL_THREADS = 1; Settings.IMP.QUEUE.PARALLEL_THREADS = 1;
} else { } else {

View File

@ -124,16 +124,12 @@ public abstract class TaskManager {
} }
for (i = 0; i < threads.length; i++) { for (i = 0; i < threads.length; i++) {
final Runnable[] toRun = split[i]; final Runnable[] toRun = split[i];
Thread thread = threads[i] = new Thread(new Runnable() { Thread thread = threads[i] = new Thread(() -> {
@Override for (Runnable run : toRun) {
public void run() {
for (int j = 0; j < toRun.length; j++) {
Runnable run = toRun[j];
if (run != null) { if (run != null) {
run.run(); run.run();
} }
} }
}
}); });
thread.start(); thread.start();
} }
@ -420,7 +416,7 @@ public abstract class TaskManager {
} catch (InterruptedException e) { } catch (InterruptedException e) {
MainUtil.handleError(e); MainUtil.handleError(e);
} }
if (run.value != null && run.value instanceof RuntimeException) { if (run.value instanceof RuntimeException) {
throw (RuntimeException) run.value; throw (RuntimeException) run.value;
} }
return (T) run.value; return (T) run.value;

View File

@ -124,7 +124,7 @@ public class WEManager {
} }
} }
} }
if (!removed) return regions.toArray(new Region[regions.size()]); if (!removed) return regions.toArray(new Region[0]);
masks.clear(); masks.clear();
} }
} }
@ -146,7 +146,7 @@ public class WEManager {
} }
if (!tmpMasks.isEmpty()) { if (!tmpMasks.isEmpty()) {
masks = tmpMasks; masks = tmpMasks;
regions = masks.stream().map(mask -> mask.getRegion()).collect(Collectors.toSet()); regions = masks.stream().map(FaweMask::getRegion).collect(Collectors.toSet());
} else { } else {
regions.addAll(backupRegions); regions.addAll(backupRegions);
} }
@ -155,7 +155,7 @@ public class WEManager {
} else { } else {
player.deleteMeta("lastMask"); player.deleteMeta("lastMask");
} }
return regions.toArray(new Region[regions.size()]); return regions.toArray(new Region[0]);
} }
@ -179,37 +179,23 @@ public class WEManager {
public boolean delay(final FawePlayer<?> player, final String command) { public boolean delay(final FawePlayer<?> player, final String command) {
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
return this.delay(player, new Runnable() { return this.delay(player, () -> {
@Override
public void run() {
try { try {
if ((System.currentTimeMillis() - start) > 1000) { if ((System.currentTimeMillis() - start) > 1000) {
BBC.WORLDEDIT_RUN.send(FawePlayer.wrap(player)); BBC.WORLDEDIT_RUN.send(FawePlayer.wrap(player));
} }
TaskManager.IMP.task(new Runnable() { TaskManager.IMP.task(() -> {
@Override final long start1 = System.currentTimeMillis();
public void run() {
final long start = System.currentTimeMillis();
player.executeCommand(command.substring(1)); player.executeCommand(command.substring(1));
TaskManager.IMP.later(new Runnable() { TaskManager.IMP.later(() -> SetQueue.IMP.addEmptyTask(() -> {
@Override if ((System.currentTimeMillis() - start1) > 1000) {
public void run() {
SetQueue.IMP.addEmptyTask(new Runnable() {
@Override
public void run() {
if ((System.currentTimeMillis() - start) > 1000) {
BBC.WORLDEDIT_COMPLETE.send(FawePlayer.wrap(player)); BBC.WORLDEDIT_COMPLETE.send(FawePlayer.wrap(player));
} }
} }), 2);
});
}
}, 2);
}
}); });
} catch (final Exception e) { } catch (final Exception e) {
MainUtil.handleError(e); MainUtil.handleError(e);
} }
}
}, false, false); }, false, false);
} }

View File

@ -167,45 +167,33 @@ public class TaskBuilder extends Metadatable {
} }
public TaskBuilder abortIfTrue(final Runnable run) { public TaskBuilder abortIfTrue(final Runnable run) {
tasks.add(RunnableTask.adapt(new Task<Boolean, Boolean>() { tasks.add(RunnableTask.adapt((Task<Boolean, Boolean>) previous -> {
@Override
public Boolean run(Boolean previous) {
if (previous == Boolean.TRUE) run.run(); if (previous == Boolean.TRUE) run.run();
return previous == Boolean.TRUE; return previous == Boolean.TRUE;
}
}, TaskType.ABORT)); }, TaskType.ABORT));
return this; return this;
} }
public TaskBuilder abortIfNull(final Runnable run) { public TaskBuilder abortIfNull(final Runnable run) {
tasks.add(RunnableTask.adapt(new Task<Boolean, Object>() { tasks.add(RunnableTask.adapt((Task<Boolean, Object>) previous -> {
@Override
public Boolean run(Object previous) {
if (previous == null) run.run(); if (previous == null) run.run();
return previous == null; return previous == null;
}
}, TaskType.ABORT)); }, TaskType.ABORT));
return this; return this;
} }
public TaskBuilder abortIfEqual(final Runnable run, final Object other) { public TaskBuilder abortIfEqual(final Runnable run, final Object other) {
tasks.add(RunnableTask.adapt(new Task<Boolean, Object>() { tasks.add(RunnableTask.adapt((Task<Boolean, Object>) previous -> {
@Override
public Boolean run(Object previous) {
if (Objects.equals(previous, other)) run.run(); if (Objects.equals(previous, other)) run.run();
return Objects.equals(previous, other); return Objects.equals(previous, other);
}
}, TaskType.ABORT)); }, TaskType.ABORT));
return this; return this;
} }
public TaskBuilder abortIfNotEqual(final Runnable run, final Object other) { public TaskBuilder abortIfNotEqual(final Runnable run, final Object other) {
tasks.add(RunnableTask.adapt(new Task<Boolean, Object>() { tasks.add(RunnableTask.adapt((Task<Boolean, Object>) previous -> {
@Override
public Boolean run(Object previous) {
if (!Objects.equals(previous, other)) run.run(); if (!Objects.equals(previous, other)) run.run();
return !Objects.equals(previous, other); return !Objects.equals(previous, other);
}
}, TaskType.ABORT)); }, TaskType.ABORT));
return this; return this;
} }
@ -215,12 +203,7 @@ public class TaskBuilder extends Metadatable {
* - As opposed to trying to using the current thread * - As opposed to trying to using the current thread
*/ */
public void buildAsync() { public void buildAsync() {
TaskManager.IMP.async(new Runnable() { TaskManager.IMP.async(this::build);
@Override
public void run() {
build();
}
});
} }
/** /**
@ -240,20 +223,10 @@ public class TaskBuilder extends Metadatable {
case SYNC: case SYNC:
case ABORT: case ABORT:
case SYNC_PARALLEL: case SYNC_PARALLEL:
TaskManager.IMP.later(new Runnable() { TaskManager.IMP.later(this::build, task.getDelay(result));
@Override
public void run() {
build();
}
}, task.getDelay(result));
return; return;
default: default:
TaskManager.IMP.laterAsync(new Runnable() { TaskManager.IMP.laterAsync(this::build, task.getDelay(result));
@Override
public void run() {
build();
}
}, task.getDelay(result));
return; return;
} }
} }
@ -274,12 +247,7 @@ public class TaskBuilder extends Metadatable {
case ASYNC: case ASYNC:
case ASYNC_PARALLEL: case ASYNC_PARALLEL:
if (Fawe.isMainThread()) { if (Fawe.isMainThread()) {
TaskManager.IMP.async(new Runnable() { TaskManager.IMP.async(this::build);
@Override
public void run() {
build();
}
});
return; return;
} }
break; break;
@ -484,9 +452,7 @@ public class TaskBuilder extends Metadatable {
public Object execSplit(final Object previous) { public Object execSplit(final Object previous) {
this.value = previous; this.value = previous;
final Thread thread = new Thread(new Runnable() { final Thread thread = new Thread(() -> {
@Override
public void run() {
try { try {
synchronized (asyncWaitLock) { synchronized (asyncWaitLock) {
asyncWaitLock.notifyAll(); asyncWaitLock.notifyAll();
@ -502,7 +468,6 @@ public class TaskBuilder extends Metadatable {
synchronized (syncWaitLock) { synchronized (syncWaitLock) {
syncWaitLock.notifyAll(); syncWaitLock.notifyAll();
} }
}
}); });
try { try {
synchronized (asyncWaitLock) { synchronized (asyncWaitLock) {

View File

@ -166,7 +166,7 @@ public class RegionVisitor implements Operation {
} catch (Throwable ignore) { } catch (Throwable ignore) {
} }
try { try {
for (; ; ) { while (true) {
apply(trailIter.next()); apply(trailIter.next());
apply(trailIter.next()); apply(trailIter.next());
} }