3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-08 04:20:06 +01:00
Removed LoggingChangeSet since it wasn't functional and the majority of it was commented out.
Migrated a lot of RunnableVal implementations to Suppliers for improved readability and a very small speed improvement.
Dieser Commit ist enthalten in:
MattBDev 2020-02-12 17:04:21 -05:00
Ursprung 6dd85e48ba
Commit ceec0ec0b9
10 geänderte Dateien mit 82 neuen und 354 gelöschten Zeilen

Datei anzeigen

@ -4,6 +4,7 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import java.util.function.Supplier;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot; import org.bukkit.ChunkSnapshot;
import org.bukkit.World; import org.bukkit.World;
@ -71,23 +72,16 @@ public class AsyncChunk implements Chunk {
if (Fawe.isMainThread()) { if (Fawe.isMainThread()) {
return world.getChunkAt(x, z).getChunkSnapshot(includeMaxblocky, includeBiome, includeBiomeTempRain); return world.getChunkAt(x, z).getChunkSnapshot(includeMaxblocky, includeBiome, includeBiomeTempRain);
} }
return whenLoaded(new RunnableVal<ChunkSnapshot>() { return whenLoaded(() -> world.getChunkAt(x, z).getChunkSnapshot(includeBiome, includeBiome, includeBiomeTempRain));
@Override
public void run(ChunkSnapshot value) {
this.value = world.getChunkAt(x, z).getChunkSnapshot(includeBiome, includeBiome, includeBiomeTempRain);
}
});
} }
private <T> T whenLoaded(RunnableVal<T> task) { private <T> T whenLoaded(Supplier<T> task) {
if (Fawe.isMainThread()) { if (Fawe.isMainThread()) {
task.run(); return task.get();
return task.value;
} }
if (world.isWorld()) { if (world.isWorld()) {
if (world.isChunkLoaded(x, z)) { if (world.isChunkLoaded(x, z)) {
task.run(); return task.get();
return task.value;
} }
} }
return TaskManager.IMP.sync(task); return TaskManager.IMP.sync(task);
@ -98,12 +92,7 @@ public class AsyncChunk implements Chunk {
if (!isLoaded()) { if (!isLoaded()) {
return new Entity[0]; return new Entity[0];
} }
return whenLoaded(new RunnableVal<Entity[]>() { return whenLoaded(() -> world.getChunkAt(x, z).getEntities());
@Override
public void run(Entity[] value) {
world.getChunkAt(x, z).getEntities();
}
});
} }
@Override @Override
@ -111,12 +100,7 @@ public class AsyncChunk implements Chunk {
if (!isLoaded()) { if (!isLoaded()) {
return new BlockState[0]; return new BlockState[0];
} }
return TaskManager.IMP.sync(new RunnableVal<BlockState[]>() { return TaskManager.IMP.sync(() -> world.getChunkAt(x, z).getTileEntities());
@Override
public void run(BlockState[] value) {
this.value = world.getChunkAt(x, z).getTileEntities();
}
});
} }
@Override @Override
@ -124,12 +108,7 @@ public class AsyncChunk implements Chunk {
if (!isLoaded()) { if (!isLoaded()) {
return new BlockState[0]; return new BlockState[0];
} }
return TaskManager.IMP.sync(new RunnableVal<BlockState[]>() { return TaskManager.IMP.sync(() -> world.getChunkAt(x, z).getTileEntities(useSnapshot));
@Override
public void run(BlockState[] value) {
this.value = world.getChunkAt(x, z).getTileEntities(useSnapshot);
}
});
} }
@Override @Override
@ -139,12 +118,7 @@ public class AsyncChunk implements Chunk {
@Override @Override
public boolean load(final boolean generate) { public boolean load(final boolean generate) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(() -> world.loadChunk(x, z, generate));
@Override
public void run(Boolean value) {
this.value = world.loadChunk(x, z, generate);
}
});
} }
@Override @Override

Datei anzeigen

@ -20,7 +20,6 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.Supplier;
import org.bukkit.BlockChangeDelegate; import org.bukkit.BlockChangeDelegate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -156,12 +155,7 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public WorldBorder getWorldBorder() { public WorldBorder getWorldBorder() {
return TaskManager.IMP.sync(new RunnableVal<WorldBorder>() { return TaskManager.IMP.sync(() -> parent.getWorldBorder());
@Override
public void run(WorldBorder value) {
this.value = parent.getWorldBorder();
}
});
} }
@Override @Override
@ -340,12 +334,7 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public boolean loadChunk(final int x, final int z, final boolean generate) { public boolean loadChunk(final int x, final int z, final boolean generate) {
if (!isChunkLoaded(x, z)) { if (!isChunkLoaded(x, z)) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(() -> parent.loadChunk(x, z, generate));
@Override
public void run(Boolean value) {
this.value = parent.loadChunk(x, z, generate);
}
});
} }
return true; return true;
} }
@ -353,12 +342,7 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public boolean unloadChunk(final Chunk chunk) { public boolean unloadChunk(final Chunk chunk) {
if (chunk.isLoaded()) { if (chunk.isLoaded()) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(() -> parent.unloadChunk(chunk));
@Override
public void run(Boolean value) {
this.value = parent.unloadChunk(chunk);
}
});
} }
return true; return true;
} }
@ -371,12 +355,7 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public boolean unloadChunk(int x, int z, boolean save) { public boolean unloadChunk(int x, int z, boolean save) {
if (isChunkLoaded(x, z)) { if (isChunkLoaded(x, z)) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(() -> parent.unloadChunk(x, z, save));
@Override
public void run(Boolean value) {
this.value = parent.unloadChunk(x, z, save);
}
});
} }
return true; return true;
} }
@ -384,24 +363,14 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public boolean unloadChunkRequest(int x, int z) { public boolean unloadChunkRequest(int x, int z) {
if (isChunkLoaded(x, z)) { if (isChunkLoaded(x, z)) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(() -> parent.unloadChunkRequest(x, z));
@Override
public void run(Boolean value) {
this.value = parent.unloadChunkRequest(x, z);
}
});
} }
return true; return true;
} }
@Override @Override
public boolean regenerateChunk(final int x, final int z) { public boolean regenerateChunk(final int x, final int z) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(() -> parent.regenerateChunk(x, z));
@Override
public void run(Boolean value) {
this.value = parent.regenerateChunk(x, z);
}
});
} }
@Override @Override
@ -412,32 +381,17 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public Item dropItem(final Location location, final ItemStack item) { public Item dropItem(final Location location, final ItemStack item) {
return TaskManager.IMP.sync(new RunnableVal<Item>() { return TaskManager.IMP.sync(() -> parent.dropItem(location, item));
@Override
public void run(Item value) {
this.value = parent.dropItem(location, item);
}
});
} }
@Override @Override
public Item dropItemNaturally(final Location location, final ItemStack item) { public Item dropItemNaturally(final Location location, final ItemStack item) {
return TaskManager.IMP.sync(new RunnableVal<Item>() { return TaskManager.IMP.sync(() -> parent.dropItemNaturally(location, item));
@Override
public void run(Item value) {
this.value = parent.dropItemNaturally(location, item);
}
});
} }
@Override @Override
public Arrow spawnArrow(final Location location, final Vector direction, final float speed, final float spread) { public Arrow spawnArrow(final Location location, final Vector direction, final float speed, final float spread) {
return TaskManager.IMP.sync(new RunnableVal<Arrow>() { return TaskManager.IMP.sync(() -> parent.spawnArrow(location, direction, speed, spread));
@Override
public void run(Arrow value) {
this.value = parent.spawnArrow(location, direction, speed, spread);
}
});
} }
@Override @Override
@ -447,22 +401,12 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public boolean generateTree(final Location location, final TreeType type) { public boolean generateTree(final Location location, final TreeType type) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(() -> parent.generateTree(location, type));
@Override
public void run(Boolean value) {
this.value = parent.generateTree(location, type);
}
});
} }
@Override @Override
public boolean generateTree(final Location loc, final TreeType type, final BlockChangeDelegate delegate) { public boolean generateTree(final Location loc, final TreeType type, final BlockChangeDelegate delegate) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(() -> parent.generateTree(loc, type, delegate));
@Override
public void run(Boolean value) {
this.value = parent.generateTree(loc, type, delegate);
}
});
} }
@Override @Override
@ -472,93 +416,48 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public LightningStrike strikeLightning(final Location loc) { public LightningStrike strikeLightning(final Location loc) {
return TaskManager.IMP.sync(new RunnableVal<LightningStrike>() { return TaskManager.IMP.sync(() -> parent.strikeLightning(loc));
@Override
public void run(LightningStrike value) {
this.value = parent.strikeLightning(loc);
}
});
} }
@Override @Override
public LightningStrike strikeLightningEffect(final Location loc) { public LightningStrike strikeLightningEffect(final Location loc) {
return TaskManager.IMP.sync(new RunnableVal<LightningStrike>() { return TaskManager.IMP.sync(() -> parent.strikeLightningEffect(loc));
@Override
public void run(LightningStrike value) {
this.value = parent.strikeLightningEffect(loc);
}
});
} }
@Override @Override
public List getEntities() { public List getEntities() {
return TaskManager.IMP.sync(new RunnableVal<List<Entity>>() { return TaskManager.IMP.sync(() -> parent.getEntities());
@Override
public void run(List<Entity> value) {
this.value = parent.getEntities();
}
});
} }
@Override @Override
public List<LivingEntity> getLivingEntities() { public List<LivingEntity> getLivingEntities() {
return TaskManager.IMP.sync(new RunnableVal<List<LivingEntity>>() { return TaskManager.IMP.sync(() -> parent.getLivingEntities());
@Override
public void run(List<LivingEntity> value) {
this.value = parent.getLivingEntities();
}
});
} }
@Override @Override
@Deprecated @Deprecated
public <T extends Entity> Collection<T> getEntitiesByClass(final Class<T>... classes) { public <T extends Entity> Collection<T> getEntitiesByClass(final Class<T>... classes) {
return TaskManager.IMP.sync(new RunnableVal<Collection<T>>() { return TaskManager.IMP.sync(() -> parent.getEntitiesByClass(classes));
@Override
public void run(Collection<T> value) {
this.value = parent.getEntitiesByClass(classes);
}
});
} }
@Override @Override
public <T extends Entity> Collection<T> getEntitiesByClass(final Class<T> cls) { public <T extends Entity> Collection<T> getEntitiesByClass(final Class<T> cls) {
return TaskManager.IMP.sync(new RunnableVal<Collection<T>>() { return TaskManager.IMP.sync(() -> parent.getEntitiesByClass(cls));
@Override
public void run(Collection<T> value) {
this.value = parent.getEntitiesByClass(cls);
}
});
} }
@Override @Override
public Collection<Entity> getEntitiesByClasses(final Class<?>... classes) { public Collection<Entity> getEntitiesByClasses(final Class<?>... classes) {
return TaskManager.IMP.sync(new RunnableVal<Collection<Entity>>() { return TaskManager.IMP.sync(() -> parent.getEntitiesByClasses(classes));
@Override
public void run(Collection<Entity> value) {
this.value = parent.getEntitiesByClasses(classes);
}
});
} }
@Override @Override
public List<Player> getPlayers() { public List<Player> getPlayers() {
return TaskManager.IMP.sync(new RunnableVal<List<Player>>() { return TaskManager.IMP.sync(() -> parent.getPlayers());
@Override
public void run(List<Player> value) {
this.value = parent.getPlayers();
}
});
} }
@Override @Override
public Collection<Entity> getNearbyEntities(final Location location, final double x, final double y, final double z) { public Collection<Entity> getNearbyEntities(final Location location, final double x, final double y, final double z) {
return TaskManager.IMP.sync(new RunnableVal<Collection<Entity>>() { return TaskManager.IMP.sync(() -> parent.getNearbyEntities(location, x, y, z));
@Override
public void run(Collection<Entity> value) {
this.value = parent.getNearbyEntities(location, x, y, z);
}
});
} }
@Override @Override
@ -578,12 +477,7 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public boolean setSpawnLocation(final int x, final int y, final int z) { public boolean setSpawnLocation(final int x, final int y, final int z) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(() -> parent.setSpawnLocation(x, y, z));
@Override
public void run(Boolean value) {
this.value = parent.setSpawnLocation(x, y, z);
}
});
} }
@Override @Override
@ -658,23 +552,16 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public boolean createExplosion(final double x, final double y, final double z, final float power, final boolean setFire, final boolean breakBlocks) { public boolean createExplosion(final double x, final double y, final double z, final float power, final boolean setFire, final boolean breakBlocks) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(
@Override () ->
public void run(Boolean value) { parent.createExplosion(x, y, z, power, setFire, breakBlocks));
this.value = parent.createExplosion(x, y, z, power, setFire, breakBlocks);
}
});
} }
@Override @Override
public boolean createExplosion(double x, double y, double z, float power, boolean setFire, public boolean createExplosion(double x, double y, double z, float power, boolean setFire,
boolean breakBlocks, @Nullable Entity source) { boolean breakBlocks, @Nullable Entity source) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(
@Override () -> parent.createExplosion(x, y, z, power, setFire, breakBlocks, source));
public void run(Boolean value) {
this.value = parent.createExplosion(x, y, z, power, setFire, breakBlocks, source);
}
});
} }
@Override @Override
@ -730,32 +617,17 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public <T extends Entity> T spawn(final Location location, final Class<T> clazz) throws IllegalArgumentException { public <T extends Entity> T spawn(final Location location, final Class<T> clazz) throws IllegalArgumentException {
return TaskManager.IMP.sync(new RunnableVal<T>() { return TaskManager.IMP.sync(() -> parent.spawn(location, clazz));
@Override
public void run(T value) {
this.value = parent.spawn(location, clazz);
}
});
} }
@Override @Override
public <T extends Entity> T spawn(Location location, Class<T> clazz, Consumer<T> function) throws IllegalArgumentException { public <T extends Entity> T spawn(Location location, Class<T> clazz, Consumer<T> function) throws IllegalArgumentException {
return TaskManager.IMP.sync(new RunnableVal<T>() { return TaskManager.IMP.sync(() -> parent.spawn(location, clazz, function));
@Override
public void run(T value) {
this.value = parent.spawn(location, clazz, function);
}
});
} }
@Override @Override
public FallingBlock spawnFallingBlock(Location location, MaterialData data) throws IllegalArgumentException { public FallingBlock spawnFallingBlock(Location location, MaterialData data) throws IllegalArgumentException {
return TaskManager.IMP.sync(new RunnableVal<FallingBlock>() { return TaskManager.IMP.sync(() -> parent.spawnFallingBlock(location, data));
@Override
public void run(FallingBlock value) {
this.value = parent.spawnFallingBlock(location, data);
}
});
} }
@Override @Override
@ -801,12 +673,8 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public ChunkSnapshot getEmptyChunkSnapshot(final int x, final int z, final boolean includeBiome, final boolean includeBiomeTempRain) { public ChunkSnapshot getEmptyChunkSnapshot(final int x, final int z, final boolean includeBiome, final boolean includeBiomeTempRain) {
return TaskManager.IMP.sync(new RunnableVal<ChunkSnapshot>() { return TaskManager.IMP.sync(
@Override () -> parent.getEmptyChunkSnapshot(x, z, includeBiome, includeBiomeTempRain));
public void run(ChunkSnapshot value) {
this.value = parent.getEmptyChunkSnapshot(x, z, includeBiome, includeBiomeTempRain);
}
});
} }
@Override @Override
@ -1254,52 +1122,27 @@ public class AsyncWorld extends PassthroughExtent implements World {
@Override @Override
public int getEntityCount() { public int getEntityCount() {
return TaskManager.IMP.sync(new RunnableVal<Integer>() { return TaskManager.IMP.sync(() -> parent.getEntityCount());
@Override
public void run(Integer value) {
this.value = parent.getEntityCount();
}
});
} }
@Override @Override
public int getTileEntityCount() { public int getTileEntityCount() {
return TaskManager.IMP.sync(new RunnableVal<Integer>() { return TaskManager.IMP.sync(() -> parent.getTileEntityCount());
@Override
public void run(Integer value) {
this.value = parent.getTileEntityCount();
}
});
} }
@Override @Override
public int getTickableTileEntityCount() { public int getTickableTileEntityCount() {
return TaskManager.IMP.sync(new RunnableVal<Integer>() { return TaskManager.IMP.sync(() -> parent.getTickableTileEntityCount());
@Override
public void run(Integer value) {
this.value = parent.getTickableTileEntityCount();
}
});
} }
@Override @Override
public int getChunkCount() { public int getChunkCount() {
return TaskManager.IMP.sync(new RunnableVal<Integer>() { return TaskManager.IMP.sync(() -> parent.getChunkCount());
@Override
public void run(Integer value) {
this.value = parent.getChunkCount();
}
});
} }
@Override @Override
public int getPlayerCount() { public int getPlayerCount() {
return TaskManager.IMP.sync(new RunnableVal<Integer>() { return TaskManager.IMP.sync(() -> parent.getPlayerCount());
@Override
public void run(Integer value) {
this.value = parent.getPlayerCount();
}
});
} }
@Override @Override

Datei anzeigen

@ -1,66 +0,0 @@
package com.boydti.fawe.logging;
import com.boydti.fawe.object.changeset.AbstractDelegateChangeSet;
import com.boydti.fawe.object.changeset.AbstractChangeSet;
import com.sk89q.worldedit.entity.Player;
//import org.primesoft.blockshub.IBlocksHubApi;
//import org.primesoft.blockshub.api.IPlayer;
//import org.primesoft.blockshub.api.IWorld;
public class LoggingChangeSet extends AbstractDelegateChangeSet {
private static boolean initialized = false;
public static AbstractChangeSet wrap(Player player, AbstractChangeSet parent) {
if (!initialized) {
initialized = true;
// api = (IBlocksHubApi) Fawe.imp().getBlocksHubApi();
}
// if (api == null) {
return parent;
// }
// return new LoggingChangeSet(player, parent);
}
// public static IBlocksHubApi api;
//
// private final MutableVector3 loc;
// private final IPlayer player;
// private IWorld world;
// private final MutableBlockData oldBlock;
// private final MutableBlockData newBlock;
private LoggingChangeSet(Player player, AbstractChangeSet parent) {
super(parent);
// String world = player.getLocation().world;
// try {
// Class<?> classBukkitWorld = Class.forName("org.primesoft.blockshub.platform.bukkit.BukkitWorld");
// Class<?> classAsyncWorld = Class.forName("com.boydti.fawe.bukkit.wrapper.AsyncWorld");
// Object asyncWorld = classAsyncWorld.getConstructor(String.class, boolean.class).newInstance(world, false);
// Constructor<?> constructor = classBukkitWorld.getDeclaredConstructors()[0];
// constructor.setAccessible(true);
// this.world = (IWorld) constructor.newInstance(asyncWorld);
// } catch (Throwable ignore) {
// this.world = api.getWorld(world);
// }
// this.loc = new MutableVector3();
// this.oldBlock = new MutableBlockData();
// this.newBlock = new MutableBlockData();
// this.player = api.getPlayer(player.getUUID());
}
@Override
public void add(int x, int y, int z, int combinedId4DataFrom, int combinedId4DataTo) {
// Mutable (avoids object creation)
// loc.x = x;
// loc.y = y;
// loc.z = z;
// oldBlock.id = FaweCache.IMP.getId(combinedId4DataFrom);
// oldBlock.data = FaweCache.IMP.getData(combinedId4DataFrom);
// newBlock.id = FaweCache.IMP.getId(combinedId4DataTo);
// newBlock.data = FaweCache.IMP.getData(combinedId4DataTo);
// // Log to BlocksHub and parent
// api.logBlock(loc, player, world, oldBlock, newBlock);
parent.add(x, y, z, combinedId4DataFrom, combinedId4DataTo);
}
}

Datei anzeigen

@ -4,9 +4,10 @@ import com.sk89q.worldedit.entity.MapMetadatable;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public class Metadatable implements MapMetadatable { public class Metadatable implements MapMetadatable {
private final ConcurrentHashMap<String, Object> meta = new ConcurrentHashMap<>(); private final ConcurrentMap<String, Object> meta = new ConcurrentHashMap<>();
@Override @Override
public Map<String, Object> getRawMeta() { public Map<String, Object> getRawMeta() {

Datei anzeigen

@ -13,7 +13,6 @@ import com.boydti.fawe.beta.implementation.queue.ParallelQueueExtent;
import com.sk89q.worldedit.util.Identifiable; import com.sk89q.worldedit.util.Identifiable;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.logging.LoggingChangeSet;
import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory; import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory;
import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.HistoryExtent; import com.boydti.fawe.object.HistoryExtent;
@ -80,7 +79,7 @@ public class EditSessionBuilder {
public EditSessionBuilder(@Nonnull World world) { public EditSessionBuilder(@Nonnull World world) {
checkNotNull(world); checkNotNull(world);
this.world = world; this.world = world;
this.worldName = Fawe.imp().getWorldName(world); this.worldName = world.getName();
} }
public EditSessionBuilder(World world, String worldName) { public EditSessionBuilder(World world, String worldName) {
@ -389,13 +388,7 @@ public class EditSessionBuilder {
if (command != null && changeSet instanceof RollbackOptimizedHistory) { if (command != null && changeSet instanceof RollbackOptimizedHistory) {
((RollbackOptimizedHistory) changeSet).setCommand(this.command); ((RollbackOptimizedHistory) changeSet).setCommand(this.command);
} }
if (changeSet instanceof NullChangeSet && Fawe.imp().getBlocksHubApi() != null && player != null) {
changeSet = LoggingChangeSet.wrap(player, changeSet);
}
if (!(changeSet instanceof NullChangeSet)) { if (!(changeSet instanceof NullChangeSet)) {
if (!(changeSet instanceof LoggingChangeSet) && player != null && Fawe.imp().getBlocksHubApi() != null) {
changeSet = LoggingChangeSet.wrap(player, changeSet);
}
if (this.blockBag != null) { if (this.blockBag != null) {
System.out.println("TODO implement block bag as IBatchProcessor"); System.out.println("TODO implement block bag as IBatchProcessor");
changeSet = new BlockBagChangeSet(changeSet, blockBag, limit.INVENTORY_MODE == 1); changeSet = new BlockBagChangeSet(changeSet, blockBag, limit.INVENTORY_MODE == 1);

Datei anzeigen

@ -89,6 +89,7 @@ import net.jpountz.lz4.LZ4Factory;
import net.jpountz.lz4.LZ4FastDecompressor; import net.jpountz.lz4.LZ4FastDecompressor;
import net.jpountz.lz4.LZ4InputStream; import net.jpountz.lz4.LZ4InputStream;
import net.jpountz.lz4.LZ4Utils; import net.jpountz.lz4.LZ4Utils;
import org.jetbrains.annotations.NotNull;
public class MainUtil { public class MainUtil {
@ -371,15 +372,11 @@ public class MainUtil {
return new FaweInputStream(new FastBufferedInputStream(is)); return new FaweInputStream(new FastBufferedInputStream(is));
} }
public static URL upload(UUID uuid, String file, String extension, final RunnableVal<OutputStream> writeTask) { public static URL upload(UUID uuid, String file, String extension, @NotNull final RunnableVal<OutputStream> writeTask) {
return upload(Settings.IMP.WEB.URL, uuid != null, uuid != null ? uuid.toString() : null, file, extension, writeTask); return upload(Settings.IMP.WEB.URL, uuid != null, uuid != null ? uuid.toString() : null, file, extension, writeTask);
} }
public static URL upload(String urlStr, boolean save, String uuid, String file, String extension, final RunnableVal<OutputStream> writeTask) { public static URL upload(String urlStr, boolean save, String uuid, String file, String extension, @NotNull final RunnableVal<OutputStream> writeTask) {
if (writeTask == null) {
getLogger(MainUtil.class).debug("Write task cannot be null");
return null;
}
String filename = (file == null ? "plot" : file) + (extension != null ? "." + extension : ""); String filename = (file == null ? "plot" : file) + (extension != null ? "." + extension : "");
uuid = uuid == null ? UUID.randomUUID().toString() : uuid; uuid = uuid == null ? UUID.randomUUID().toString() : uuid;
final String website; final String website;

Datei anzeigen

@ -22,7 +22,7 @@ public abstract class TaskManager {
public static TaskManager IMP; public static TaskManager IMP;
private ForkJoinPool pool = new ForkJoinPool(); private final ForkJoinPool pool = new ForkJoinPool();
/** /**
* Run a repeating task on the main thread * Run a repeating task on the main thread
@ -308,6 +308,22 @@ public abstract class TaskManager {
} }
} }
/**
* Run a task on the main thread when the TPS is high enough, and wait for execution to finish:<br>
* - Useful if you need to access something from the Bukkit API from another thread<br>
* - Usually wait time is around 25ms<br>
*/
public <T> T syncWhenFree(@NotNull final Supplier<T> supplier) {
if (Fawe.isMainThread()) {
return supplier.get();
}
try {
return Fawe.get().getQueueHandler().sync(supplier).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
/** /**
* Quickly run a task on the main thread, and wait for execution to finish:<br> * Quickly run a task on the main thread, and wait for execution to finish:<br>
* - Useful if you need to access something from the Bukkit API from another thread<br> * - Useful if you need to access something from the Bukkit API from another thread<br>

Datei anzeigen

@ -66,22 +66,12 @@ public class AsyncPlayer extends PlayerProxy {
@Override @Override
public boolean ascendLevel() { public boolean ascendLevel() {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(() -> getBasePlayer().ascendLevel());
@Override
public void run(Boolean value) {
this.value = getBasePlayer().ascendLevel();
}
});
} }
@Override @Override
public boolean descendLevel() { public boolean descendLevel() {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(() -> getBasePlayer().descendLevel());
@Override
public void run(Boolean value) {
this.value = getBasePlayer().descendLevel();
}
});
} }
@Override @Override
@ -175,34 +165,25 @@ public class AsyncPlayer extends PlayerProxy {
@Override @Override
public Location getBlockTrace(int range, boolean useLastBlock) { public Location getBlockTrace(int range, boolean useLastBlock) {
return TaskManager.IMP.sync(new RunnableVal<Location>() { return TaskManager.IMP.sync(() -> {
@Override
public void run(Location value) {
TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D); TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D);
this.value = useLastBlock ? tb.getAnyTargetBlock() : tb.getTargetBlock(); return useLastBlock ? tb.getAnyTargetBlock() : tb.getTargetBlock();
}
}); });
} }
@Override @Override
public Location getBlockTraceFace(int range, boolean useLastBlock) { public Location getBlockTraceFace(int range, boolean useLastBlock) {
return TaskManager.IMP.sync(new RunnableVal<Location>() { return TaskManager.IMP.sync(() -> {
@Override
public void run(Location value) {
TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D); TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D);
this.value = useLastBlock ? tb.getAnyTargetBlockFace() : tb.getTargetBlockFace(); return useLastBlock ? tb.getAnyTargetBlockFace() : tb.getTargetBlockFace();
}
}); });
} }
@Override @Override
public Location getSolidBlockTrace(int range) { public Location getSolidBlockTrace(int range) {
return TaskManager.IMP.sync(new RunnableVal<Location>() { return TaskManager.IMP.sync(() -> {
@Override
public void run(Location value) {
TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D); TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D);
this.value = tb.getSolidTargetBlock(); return tb.getSolidTargetBlock();
}
}); });
} }

Datei anzeigen

@ -243,22 +243,12 @@ public class WorldWrapper extends AbstractWorld {
@Override @Override
public List<? extends Entity> getEntities(Region region) { public List<? extends Entity> getEntities(Region region) {
return TaskManager.IMP.sync(new RunnableVal<List<? extends Entity>>() { return TaskManager.IMP.sync(() -> parent.getEntities(region));
@Override
public void run(List<? extends Entity> value) {
this.value = parent.getEntities(region);
}
});
} }
@Override @Override
public List<? extends Entity> getEntities() { public List<? extends Entity> getEntities() {
return TaskManager.IMP.sync(new RunnableVal<List<? extends Entity>>() { return TaskManager.IMP.sync(parent::getEntities);
@Override
public void run(List<? extends Entity> value) {
this.value = parent.getEntities();
}
});
} }
@Override @Override

Datei anzeigen

@ -3,7 +3,6 @@ package com.sk89q.worldedit.extension.platform.binding;
import com.boydti.fawe.config.Caption; import com.boydti.fawe.config.Caption;
import com.boydti.fawe.database.DBHandler; import com.boydti.fawe.database.DBHandler;
import com.boydti.fawe.database.RollbackDatabase; import com.boydti.fawe.database.RollbackDatabase;
import com.boydti.fawe.logging.LoggingChangeSet;
import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.TextureUtil; import com.boydti.fawe.util.TextureUtil;
import com.boydti.fawe.util.image.ImageUtil; import com.boydti.fawe.util.image.ImageUtil;