mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Lambda's and References and Cleanups! Oh My!
This commit is contained in:
parent
1424998327
commit
acc8eb0a99
@ -5,7 +5,7 @@ import org.bukkit.World;
|
||||
|
||||
public abstract class PaperChunkCallback {
|
||||
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);
|
||||
|
@ -152,10 +152,10 @@ public class Fawe {
|
||||
* The platform specific implementation
|
||||
*/
|
||||
private final IFawe IMP;
|
||||
private Thread thread = Thread.currentThread();
|
||||
private Thread thread;
|
||||
|
||||
private Fawe(final IFawe implementation) {
|
||||
this.INSTANCE = this;
|
||||
INSTANCE = this;
|
||||
this.IMP = implementation;
|
||||
this.thread = Thread.currentThread();
|
||||
/*
|
||||
@ -164,26 +164,18 @@ public class Fawe {
|
||||
this.setupConfigs();
|
||||
TaskManager.IMP = this.IMP.getTaskManager();
|
||||
|
||||
TaskManager.IMP.async(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TaskManager.IMP.async(() -> {
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
if (Settings.IMP.METRICS) {
|
||||
try {
|
||||
this.stats = new BStats();
|
||||
this.IMP.startMetrics();
|
||||
TaskManager.IMP.later(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
stats.start();
|
||||
}
|
||||
}, 1);
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
TaskManager.IMP.later(() -> stats.start(), 1);
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -216,7 +208,7 @@ public class Fawe {
|
||||
WEManager.IMP.managers.addAll(Fawe.this.IMP.getMaskManagers());
|
||||
WEManager.IMP.managers.add(new PlotSquaredFeature());
|
||||
Fawe.debug("Plugin 'PlotSquared' found. Using it now.");
|
||||
} catch (Throwable e) {}
|
||||
} catch (Throwable ignored) {}
|
||||
}, 0);
|
||||
|
||||
TaskManager.IMP.repeat(timer, 1);
|
||||
@ -224,8 +216,8 @@ public class Fawe {
|
||||
if (!Settings.IMP.UPDATE.equalsIgnoreCase("false")) {
|
||||
// Delayed updating
|
||||
updater = new Updater();
|
||||
TaskManager.IMP.async(() -> update());
|
||||
TaskManager.IMP.repeatAsync(() -> update(), 36000);
|
||||
TaskManager.IMP.async(this::update);
|
||||
TaskManager.IMP.repeatAsync(this::update, 36000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -452,16 +444,13 @@ public class Fawe {
|
||||
final MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
|
||||
final NotificationEmitter ne = (NotificationEmitter) memBean;
|
||||
|
||||
ne.addNotificationListener(new NotificationListener() {
|
||||
@Override
|
||||
public void handleNotification(final Notification notification, final Object handback) {
|
||||
ne.addNotificationListener((notification, handback) -> {
|
||||
final long heapSize = Runtime.getRuntime().totalMemory();
|
||||
final long heapMaxSize = Runtime.getRuntime().maxMemory();
|
||||
if (heapSize < heapMaxSize) {
|
||||
return;
|
||||
}
|
||||
MemUtil.memoryLimitedTask();
|
||||
}
|
||||
}, null, null);
|
||||
|
||||
final List<MemoryPoolMXBean> memPools = ManagementFactory.getMemoryPoolMXBeans();
|
||||
|
@ -111,12 +111,7 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> impl
|
||||
map.forEachChunk(new RunnableVal<FaweChunk>() {
|
||||
@Override
|
||||
public void run(final FaweChunk chunk) {
|
||||
pool.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
chunk.optimize();
|
||||
}
|
||||
});
|
||||
pool.submit(chunk::optimize);
|
||||
}
|
||||
});
|
||||
pool.awaitQuiescence(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
@ -300,8 +295,8 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> impl
|
||||
|
||||
@Override
|
||||
public boolean supports(Capability capability) {
|
||||
switch (capability) {
|
||||
case CHANGE_TASKS: return true;
|
||||
if (capability == Capability.CHANGE_TASKS) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -416,12 +411,7 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> impl
|
||||
public boolean queueChunkLoad(final int cx, final int cz) {
|
||||
CHUNK chunk = getCachedChunk(getWorld(), cx, cz);
|
||||
if (chunk == null) {
|
||||
SetQueue.IMP.addTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadChunk(getWorld(), cx, cz, true);
|
||||
}
|
||||
});
|
||||
SetQueue.IMP.addTask(() -> loadChunk(getWorld(), cx, cz, true));
|
||||
return true;
|
||||
}
|
||||
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) {
|
||||
operation.value = getCachedChunk(getWorld(), cx, cz);
|
||||
if (operation.value == null) {
|
||||
SetQueue.IMP.addTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SetQueue.IMP.addTask(() -> {
|
||||
operation.value = loadChunk(getWorld(), cx, cz, true);
|
||||
if (operation.value != null) TaskManager.IMP.async(operation);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
|
@ -40,15 +40,12 @@ public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> ex
|
||||
public void runTasks() {
|
||||
super.runTasks();
|
||||
if (!getRelighter().isEmpty()) {
|
||||
TaskManager.IMP.async(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TaskManager.IMP.async(() -> {
|
||||
if (getSettings().IMP.LIGHTING.REMOVE_FIRST) {
|
||||
getRelighter().removeAndRelight(hasSky());
|
||||
} else {
|
||||
getRelighter().fixLightingSafe(hasSky());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -133,9 +133,7 @@ public class SchematicStreamer extends NBTStreamer {
|
||||
addReader("Schematic.Biomes.#", biomeReader); // FAWE stores as a byte[] (4x smaller)
|
||||
|
||||
// Tiles
|
||||
addReader("Schematic.TileEntities.#", new BiConsumer<Integer, CompoundTag>() {
|
||||
@Override
|
||||
public void accept(Integer index, CompoundTag value) {
|
||||
addReader("Schematic.TileEntities.#", (BiConsumer<Integer, CompoundTag>) (index, value) -> {
|
||||
if (fc == null) {
|
||||
setupClipboard(0);
|
||||
}
|
||||
@ -143,12 +141,9 @@ public class SchematicStreamer extends NBTStreamer {
|
||||
int y = value.getInt("y");
|
||||
int z = value.getInt("z");
|
||||
fc.setTile(x, y, z, value);
|
||||
}
|
||||
});
|
||||
// Entities
|
||||
addReader("Schematic.Entities.#", new BiConsumer<Integer, CompoundTag>() {
|
||||
@Override
|
||||
public void accept(Integer index, CompoundTag compound) {
|
||||
addReader("Schematic.Entities.#", (BiConsumer<Integer, CompoundTag>) (index, compound) -> {
|
||||
if (fc == null) {
|
||||
setupClipboard(0);
|
||||
}
|
||||
@ -166,7 +161,6 @@ public class SchematicStreamer extends NBTStreamer {
|
||||
} else {
|
||||
Fawe.debug("Invalid entity: " + id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -345,60 +339,23 @@ public class SchematicStreamer extends NBTStreamer {
|
||||
}
|
||||
|
||||
public void addDimensionReaders() {
|
||||
addReader("Schematic.Height", new BiConsumer<Integer, Short>() {
|
||||
@Override
|
||||
public void accept(Integer index, Short value) {
|
||||
height = (value);
|
||||
}
|
||||
});
|
||||
addReader("Schematic.Width", new BiConsumer<Integer, Short>() {
|
||||
@Override
|
||||
public void accept(Integer index, Short value) {
|
||||
width = (value);
|
||||
}
|
||||
});
|
||||
addReader("Schematic.Length", new BiConsumer<Integer, Short>() {
|
||||
@Override
|
||||
public void accept(Integer index, Short value) {
|
||||
length = (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);
|
||||
}
|
||||
});
|
||||
addReader("Schematic.Height",
|
||||
(BiConsumer<Integer, Short>) (index, value) -> height = (value));
|
||||
addReader("Schematic.Width", (BiConsumer<Integer, Short>) (index, value) -> width = (value));
|
||||
addReader("Schematic.Length",
|
||||
(BiConsumer<Integer, Short>) (index, value) -> length = (value));
|
||||
addReader("Schematic.WEOriginX",
|
||||
(BiConsumer<Integer, Integer>) (index, value) -> originX = (value));
|
||||
addReader("Schematic.WEOriginY",
|
||||
(BiConsumer<Integer, Integer>) (index, value) -> originY = (value));
|
||||
addReader("Schematic.WEOriginZ",
|
||||
(BiConsumer<Integer, Integer>) (index, value) -> originZ = (value));
|
||||
addReader("Schematic.WEOffsetX",
|
||||
(BiConsumer<Integer, Integer>) (index, value) -> offsetX = (value));
|
||||
addReader("Schematic.WEOffsetY",
|
||||
(BiConsumer<Integer, Integer>) (index, value) -> offsetY = (value));
|
||||
addReader("Schematic.WEOffsetZ",
|
||||
(BiConsumer<Integer, Integer>) (index, value) -> offsetZ = (value));
|
||||
}
|
||||
|
||||
private int height;
|
||||
|
@ -91,9 +91,7 @@ public class MCAChunk extends FaweChunk<Void> {
|
||||
|
||||
public void write(NBTOutputStream nbtOut) throws IOException {
|
||||
nbtOut.writeNamedTagName("", NBTConstants.TYPE_COMPOUND);
|
||||
nbtOut.writeLazyCompoundTag("Level", new NBTOutputStream.LazyWrite() {
|
||||
@Override
|
||||
public void write(NBTOutputStream out) throws IOException {
|
||||
nbtOut.writeLazyCompoundTag("Level", out -> {
|
||||
out.writeNamedTag("V", (byte) 1);
|
||||
out.writeNamedTag("xPos", getX());
|
||||
out.writeNamedTag("zPos", getZ());
|
||||
@ -135,7 +133,6 @@ public class MCAChunk extends FaweChunk<Void> {
|
||||
out.writeNamedTag("Data", data[layer]);
|
||||
out.writeEndTag();
|
||||
}
|
||||
}
|
||||
});
|
||||
nbtOut.writeEndTag();
|
||||
}
|
||||
@ -464,74 +461,43 @@ public class MCAChunk extends FaweChunk<Void> {
|
||||
skyLight = new byte[16][];
|
||||
blockLight = new byte[16][];
|
||||
NBTStreamer streamer = new NBTStreamer(nis);
|
||||
streamer.addReader(".Level.InhabitedTime", new BiConsumer<Integer, Long>() {
|
||||
@Override
|
||||
public void accept(Integer index, Long value) {
|
||||
inhabitedTime = value;
|
||||
}
|
||||
});
|
||||
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) {
|
||||
streamer.addReader(".Level.InhabitedTime",
|
||||
(BiConsumer<Integer, Long>) (index, value) -> inhabitedTime = value);
|
||||
streamer.addReader(".Level.LastUpdate",
|
||||
(BiConsumer<Integer, Long>) (index, value) -> lastUpdate = value);
|
||||
streamer.addReader(".Level.Sections.#", (BiConsumer<Integer, CompoundTag>) (index, tag) -> {
|
||||
int layer = tag.getByte("Y");
|
||||
ids[layer] = tag.getByteArray("Blocks");
|
||||
data[layer] = tag.getByteArray("Data");
|
||||
skyLight[layer] = tag.getByteArray("SkyLight");
|
||||
blockLight[layer] = tag.getByteArray("BlockLight");
|
||||
}
|
||||
});
|
||||
streamer.addReader(".Level.TileEntities.#", new BiConsumer<Integer, CompoundTag>() {
|
||||
@Override
|
||||
public void accept(Integer index, CompoundTag tile) {
|
||||
int x = tile.getInt("x") & 15;
|
||||
streamer.addReader(".Level.TileEntities.#",
|
||||
(BiConsumer<Integer, CompoundTag>) (index, tile) -> {
|
||||
int x1 = tile.getInt("x") & 15;
|
||||
int y = tile.getInt("y");
|
||||
int z = tile.getInt("z") & 15;
|
||||
short pair = MathMan.tripleBlockCoord(x, y, z);
|
||||
int z1 = tile.getInt("z") & 15;
|
||||
short pair = MathMan.tripleBlockCoord(x1, y, z1);
|
||||
tiles.put(pair, tile);
|
||||
}
|
||||
});
|
||||
streamer.addReader(".Level.Entities.#", new BiConsumer<Integer, CompoundTag>() {
|
||||
@Override
|
||||
public void accept(Integer index, CompoundTag entityTag) {
|
||||
streamer.addReader(".Level.Entities.#",
|
||||
(BiConsumer<Integer, CompoundTag>) (index, entityTag) -> {
|
||||
if (entities == null) {
|
||||
entities = new HashMap<>();
|
||||
}
|
||||
long least = entityTag.getLong("UUIDLeast");
|
||||
long most = entityTag.getLong("UUIDMost");
|
||||
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) {
|
||||
streamer.addReader(".Level.xPos", new BiConsumer<Integer, Integer>() {
|
||||
@Override
|
||||
public void accept(Integer index, Integer value) {
|
||||
MCAChunk.this.setLoc(getParent(), value, getZ());
|
||||
}
|
||||
});
|
||||
streamer.addReader(".Level.zPos", new BiConsumer<Integer, Integer>() {
|
||||
@Override
|
||||
public void accept(Integer index, Integer value) {
|
||||
MCAChunk.this.setLoc(getParent(), getX(), value);
|
||||
}
|
||||
});
|
||||
streamer.addReader(".Level.xPos",
|
||||
(BiConsumer<Integer, Integer>) (index, value) -> MCAChunk.this.setLoc(getParent(), value, getZ()));
|
||||
streamer.addReader(".Level.zPos",
|
||||
(BiConsumer<Integer, Integer>) (index, value) -> MCAChunk.this.setLoc(getParent(), getX(), value));
|
||||
}
|
||||
streamer.readFully();
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import com.boydti.fawe.object.brush.visualization.VirtualWorld;
|
||||
import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard;
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
import com.boydti.fawe.object.task.SimpleAsyncNotifyQueue;
|
||||
import com.boydti.fawe.object.task.ThrowableSupplier;
|
||||
import com.boydti.fawe.regions.FaweMaskManager;
|
||||
import com.boydti.fawe.util.*;
|
||||
import com.boydti.fawe.wrappers.FakePlayer;
|
||||
@ -17,8 +16,7 @@ import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
|
||||
import com.boydti.fawe.wrappers.PlayerWrapper;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
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.event.platform.CommandEvent;
|
||||
import com.sk89q.worldedit.extension.platform.*;
|
||||
@ -41,7 +39,6 @@ import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
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) {
|
||||
if (task != null) {
|
||||
Runnable newTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CommandManager.getInstance().handleCommandTask(new ThrowableSupplier<Throwable>() {
|
||||
@Override
|
||||
public Object get() throws Throwable {
|
||||
Runnable newTask = () -> CommandManager.getInstance().handleCommandTask(() -> {
|
||||
task.run();
|
||||
return null;
|
||||
}
|
||||
}, context.getLocals());
|
||||
}
|
||||
};
|
||||
setMeta("cmdConfirm", newTask);
|
||||
} else {
|
||||
setMeta("cmdConfirm", new CommandEvent(getPlayer(), command));
|
||||
@ -365,15 +354,15 @@ public abstract class FawePlayer<T> extends Metadatable {
|
||||
}
|
||||
} catch (EmptyClipboardException e) {
|
||||
}
|
||||
if (player != null && session != null) {
|
||||
if (player != null) {
|
||||
Clipboard clip = doc.toClipboard();
|
||||
ClipboardHolder holder = new ClipboardHolder(clip);
|
||||
getSession().setClipboard(holder);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
} catch (Exception event) {
|
||||
Fawe.debug("====== INVALID CLIPBOARD ======");
|
||||
MainUtil.handleError(ignore, false);
|
||||
MainUtil.handleError(event, false);
|
||||
Fawe.debug("===============---=============");
|
||||
Fawe.debug("This shouldn't result in any failure");
|
||||
Fawe.debug("File: " + file.getName() + " (len:" + file.length() + ")");
|
||||
|
@ -73,12 +73,10 @@ public class SetQueue {
|
||||
|
||||
public SetQueue() {
|
||||
tasks = new ConcurrentLinkedDeque<>();
|
||||
activeQueues = new ConcurrentLinkedDeque();
|
||||
activeQueues = new ConcurrentLinkedDeque<>();
|
||||
inactiveQueues = new ConcurrentLinkedDeque<>();
|
||||
if (TaskManager.IMP == null) return;
|
||||
TaskManager.IMP.repeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TaskManager.IMP.repeat(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
boolean empty = (inactiveQueues.isEmpty() && activeQueues.isEmpty());
|
||||
@ -187,7 +185,6 @@ public class SetQueue {
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@ -264,7 +261,7 @@ public class SetQueue {
|
||||
|
||||
public void flush(FaweQueue queue) {
|
||||
int parallelThreads;
|
||||
if (Fawe.get().isMainThread()) {
|
||||
if (Fawe.isMainThread()) {
|
||||
parallelThreads = Settings.IMP.QUEUE.PARALLEL_THREADS;
|
||||
Settings.IMP.QUEUE.PARALLEL_THREADS = 1;
|
||||
} else {
|
||||
|
@ -124,16 +124,12 @@ public abstract class TaskManager {
|
||||
}
|
||||
for (i = 0; i < threads.length; i++) {
|
||||
final Runnable[] toRun = split[i];
|
||||
Thread thread = threads[i] = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int j = 0; j < toRun.length; j++) {
|
||||
Runnable run = toRun[j];
|
||||
Thread thread = threads[i] = new Thread(() -> {
|
||||
for (Runnable run : toRun) {
|
||||
if (run != null) {
|
||||
run.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
@ -420,7 +416,7 @@ public abstract class TaskManager {
|
||||
} catch (InterruptedException e) {
|
||||
MainUtil.handleError(e);
|
||||
}
|
||||
if (run.value != null && run.value instanceof RuntimeException) {
|
||||
if (run.value instanceof RuntimeException) {
|
||||
throw (RuntimeException) run.value;
|
||||
}
|
||||
return (T) run.value;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
@ -146,7 +146,7 @@ public class WEManager {
|
||||
}
|
||||
if (!tmpMasks.isEmpty()) {
|
||||
masks = tmpMasks;
|
||||
regions = masks.stream().map(mask -> mask.getRegion()).collect(Collectors.toSet());
|
||||
regions = masks.stream().map(FaweMask::getRegion).collect(Collectors.toSet());
|
||||
} else {
|
||||
regions.addAll(backupRegions);
|
||||
}
|
||||
@ -155,7 +155,7 @@ public class WEManager {
|
||||
} else {
|
||||
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) {
|
||||
final long start = System.currentTimeMillis();
|
||||
return this.delay(player, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
return this.delay(player, () -> {
|
||||
try {
|
||||
if ((System.currentTimeMillis() - start) > 1000) {
|
||||
BBC.WORLDEDIT_RUN.send(FawePlayer.wrap(player));
|
||||
}
|
||||
TaskManager.IMP.task(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final long start = System.currentTimeMillis();
|
||||
TaskManager.IMP.task(() -> {
|
||||
final long start1 = System.currentTimeMillis();
|
||||
player.executeCommand(command.substring(1));
|
||||
TaskManager.IMP.later(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SetQueue.IMP.addEmptyTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if ((System.currentTimeMillis() - start) > 1000) {
|
||||
TaskManager.IMP.later(() -> SetQueue.IMP.addEmptyTask(() -> {
|
||||
if ((System.currentTimeMillis() - start1) > 1000) {
|
||||
BBC.WORLDEDIT_COMPLETE.send(FawePlayer.wrap(player));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
}), 2);
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
MainUtil.handleError(e);
|
||||
}
|
||||
}
|
||||
}, false, false);
|
||||
}
|
||||
|
||||
|
@ -167,45 +167,33 @@ public class TaskBuilder extends Metadatable {
|
||||
}
|
||||
|
||||
public TaskBuilder abortIfTrue(final Runnable run) {
|
||||
tasks.add(RunnableTask.adapt(new Task<Boolean, Boolean>() {
|
||||
@Override
|
||||
public Boolean run(Boolean previous) {
|
||||
tasks.add(RunnableTask.adapt((Task<Boolean, Boolean>) previous -> {
|
||||
if (previous == Boolean.TRUE) run.run();
|
||||
return previous == Boolean.TRUE;
|
||||
}
|
||||
}, TaskType.ABORT));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder abortIfNull(final Runnable run) {
|
||||
tasks.add(RunnableTask.adapt(new Task<Boolean, Object>() {
|
||||
@Override
|
||||
public Boolean run(Object previous) {
|
||||
tasks.add(RunnableTask.adapt((Task<Boolean, Object>) previous -> {
|
||||
if (previous == null) run.run();
|
||||
return previous == null;
|
||||
}
|
||||
}, TaskType.ABORT));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder abortIfEqual(final Runnable run, final Object other) {
|
||||
tasks.add(RunnableTask.adapt(new Task<Boolean, Object>() {
|
||||
@Override
|
||||
public Boolean run(Object previous) {
|
||||
tasks.add(RunnableTask.adapt((Task<Boolean, Object>) previous -> {
|
||||
if (Objects.equals(previous, other)) run.run();
|
||||
return Objects.equals(previous, other);
|
||||
}
|
||||
}, TaskType.ABORT));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder abortIfNotEqual(final Runnable run, final Object other) {
|
||||
tasks.add(RunnableTask.adapt(new Task<Boolean, Object>() {
|
||||
@Override
|
||||
public Boolean run(Object previous) {
|
||||
tasks.add(RunnableTask.adapt((Task<Boolean, Object>) previous -> {
|
||||
if (!Objects.equals(previous, other)) run.run();
|
||||
return !Objects.equals(previous, other);
|
||||
}
|
||||
}, TaskType.ABORT));
|
||||
return this;
|
||||
}
|
||||
@ -215,12 +203,7 @@ public class TaskBuilder extends Metadatable {
|
||||
* - As opposed to trying to using the current thread
|
||||
*/
|
||||
public void buildAsync() {
|
||||
TaskManager.IMP.async(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
build();
|
||||
}
|
||||
});
|
||||
TaskManager.IMP.async(this::build);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -240,20 +223,10 @@ public class TaskBuilder extends Metadatable {
|
||||
case SYNC:
|
||||
case ABORT:
|
||||
case SYNC_PARALLEL:
|
||||
TaskManager.IMP.later(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
build();
|
||||
}
|
||||
}, task.getDelay(result));
|
||||
TaskManager.IMP.later(this::build, task.getDelay(result));
|
||||
return;
|
||||
default:
|
||||
TaskManager.IMP.laterAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
build();
|
||||
}
|
||||
}, task.getDelay(result));
|
||||
TaskManager.IMP.laterAsync(this::build, task.getDelay(result));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -274,12 +247,7 @@ public class TaskBuilder extends Metadatable {
|
||||
case ASYNC:
|
||||
case ASYNC_PARALLEL:
|
||||
if (Fawe.isMainThread()) {
|
||||
TaskManager.IMP.async(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
build();
|
||||
}
|
||||
});
|
||||
TaskManager.IMP.async(this::build);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@ -484,9 +452,7 @@ public class TaskBuilder extends Metadatable {
|
||||
|
||||
public Object execSplit(final Object previous) {
|
||||
this.value = previous;
|
||||
final Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Thread thread = new Thread(() -> {
|
||||
try {
|
||||
synchronized (asyncWaitLock) {
|
||||
asyncWaitLock.notifyAll();
|
||||
@ -502,7 +468,6 @@ public class TaskBuilder extends Metadatable {
|
||||
synchronized (syncWaitLock) {
|
||||
syncWaitLock.notifyAll();
|
||||
}
|
||||
}
|
||||
});
|
||||
try {
|
||||
synchronized (asyncWaitLock) {
|
||||
|
@ -166,7 +166,7 @@ public class RegionVisitor implements Operation {
|
||||
} catch (Throwable ignore) {
|
||||
}
|
||||
try {
|
||||
for (; ; ) {
|
||||
while (true) {
|
||||
apply(trailIter.next());
|
||||
apply(trailIter.next());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user