API Breaking

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.
This commit is contained in:
MattBDev
2020-02-12 17:04:21 -05:00
parent 6dd85e48ba
commit ceec0ec0b9
10 changed files with 82 additions and 354 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,7 @@ public abstract class TaskManager {
public static TaskManager IMP;
private ForkJoinPool pool = new ForkJoinPool();
private final ForkJoinPool pool = new ForkJoinPool();
/**
* Run a repeating task on the main thread
@ -307,6 +307,22 @@ public abstract class TaskManager {
throw new RuntimeException(e);
}
}
/**
* 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>

View File

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

View File

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

View File

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