diff --git a/core/src/main/java/com/boydti/fawe/Fawe.java b/core/src/main/java/com/boydti/fawe/Fawe.java index 0a0a95db..24aa0813 100644 --- a/core/src/main/java/com/boydti/fawe/Fawe.java +++ b/core/src/main/java/com/boydti/fawe/Fawe.java @@ -154,7 +154,7 @@ import javax.management.NotificationListener; public class Fawe { /** * The FAWE instance; - */ + */ private static Fawe INSTANCE; /** @@ -566,8 +566,8 @@ public class Fawe { return this.thread; } - public boolean isMainThread() { - return Thread.currentThread() == thread; + public static boolean isMainThread() { + return INSTANCE != null ? INSTANCE.thread == Thread.currentThread() : true; } /** diff --git a/core/src/main/java/com/boydti/fawe/object/FaweQueue.java b/core/src/main/java/com/boydti/fawe/object/FaweQueue.java index 9197a52d..46afea33 100644 --- a/core/src/main/java/com/boydti/fawe/object/FaweQueue.java +++ b/core/src/main/java/com/boydti/fawe/object/FaweQueue.java @@ -410,7 +410,7 @@ public abstract class FaweQueue { */ public void flush(int time) { if (size() > 0) { - if (Fawe.get().isMainThread()) { + if (Fawe.isMainThread()) { SetQueue.IMP.flush(this); } else { if (enqueue()) { diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 7eaac963..be16a5fe 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -5,13 +5,20 @@ import com.boydti.fawe.config.Settings; import com.boydti.fawe.database.DBHandler; import com.boydti.fawe.database.RollbackDatabase; import com.boydti.fawe.object.FaweInputStream; +import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.IntegerPair; import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.util.MainUtil; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; +import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.world.World; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -97,6 +104,13 @@ public class DiskStorageHistory extends FaweStreamChangeSet { initFiles(folder); } + public DiskStorageHistory(File folder, String world, UUID uuid, int i) { + super(world); + this.uuid = uuid; + this.index = i; + initFiles(folder); + } + private void initFiles(File folder) { nbtfFile = new File(folder, index + ".nbtf"); nbttFile = new File(folder, index + ".nbtt"); @@ -129,6 +143,12 @@ public class DiskStorageHistory extends FaweStreamChangeSet { enttFile.delete(); } + public void undo(FawePlayer fp) { + EditSession session = toEditSession(fp); + session.undo(session); + deleteFiles(); + } + public UUID getUUID() { return uuid; } diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java b/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java index 358f631a..3404ff4d 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java @@ -7,7 +7,6 @@ import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FaweQueue; -import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.RunnableVal2; import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.MainUtil; @@ -51,14 +50,14 @@ public abstract class FaweChangeSet implements ChangeSet { public FaweChangeSet(String world) { this.worldName = world; - this.mainThread = Fawe.get().isMainThread(); + this.mainThread = (Fawe.get() != null) ? Fawe.isMainThread() : true; this.layers = FaweChunk.HEIGHT >> 4; } public FaweChangeSet(World world) { this.world = world; this.worldName = Fawe.imp().getWorldName(world); - this.mainThread = Fawe.get().isMainThread(); + this.mainThread = Fawe.isMainThread(); this.layers = (this.world.getMaxY() + 1) >> 4; } @@ -88,7 +87,7 @@ public abstract class FaweChangeSet implements ChangeSet { public boolean flush() { try { - if (!Fawe.get().isMainThread()) { + if (!Fawe.isMainThread()) { while (waitingAsync.get() > 0) { synchronized (lockAsync) { lockAsync.wait(1000); @@ -130,7 +129,7 @@ public abstract class FaweChangeSet implements ChangeSet { public void delete() {}; public EditSession toEditSession(FawePlayer player) { - EditSession editSession = new EditSessionBuilder(world).player(player).autoQueue(false).fastmode(false).checkMemory(false).changeSet(this).allowedRegions(RegionWrapper.GLOBAL().toArray()).build(); + EditSession editSession = new EditSessionBuilder(getWorld()).player(player).autoQueue(false).fastmode(false).checkMemory(false).changeSet(this).limitUnlimited().allowedRegionsEverywhere().build(); editSession.setSize(1); return editSession; } diff --git a/core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java b/core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java index 2fdfb718..d352ee9e 100644 --- a/core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java +++ b/core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java @@ -17,7 +17,7 @@ public class SlowExtent extends AbstractDelegateExtent { @Override public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { - if (!Fawe.get().isMainThread()) try { + if (!Fawe.isMainThread()) try { Thread.sleep(sleep); } catch (InterruptedException e) { e.printStackTrace(); diff --git a/core/src/main/java/com/boydti/fawe/util/TaskManager.java b/core/src/main/java/com/boydti/fawe/util/TaskManager.java index 66226f0b..4e6c0574 100644 --- a/core/src/main/java/com/boydti/fawe/util/TaskManager.java +++ b/core/src/main/java/com/boydti/fawe/util/TaskManager.java @@ -191,7 +191,7 @@ public abstract class TaskManager { * @param r */ public void taskNowAsync(final Runnable r) { - taskNow(r, Fawe.get().isMainThread()); + taskNow(r, Fawe.isMainThread()); } /** @@ -297,7 +297,7 @@ public abstract class TaskManager { } public void taskWhenFree(Runnable run) { - if (Fawe.get().isMainThread()) { + if (Fawe.isMainThread()) { run.run(); } else { SetQueue.IMP.addTask(run); diff --git a/core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java b/core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java index 66208896..0c0eb807 100644 --- a/core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java +++ b/core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java @@ -257,7 +257,7 @@ public class TaskBuilder extends Metadatable { return; case SYNC: case SYNC_PARALLEL: - if (!Fawe.get().isMainThread()) { + if (!Fawe.isMainThread()) { TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Object value) { @@ -270,7 +270,7 @@ public class TaskBuilder extends Metadatable { case SYNC_WHEN_FREE: case ASYNC: case ASYNC_PARALLEL: - if (Fawe.get().isMainThread()) { + if (Fawe.isMainThread()) { TaskManager.IMP.async(new Runnable() { @Override public void run() { diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index c2b516af..374b019a 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -1308,7 +1308,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting queue.dequeue(); return; } - if (Fawe.get().isMainThread()) { + if (Fawe.isMainThread()) { SetQueue.IMP.flush(queue); } else { queue.flush(); diff --git a/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java b/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java index 043872ed..df6ea374 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java @@ -33,8 +33,8 @@ import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.changeset.DiskStorageHistory; import com.boydti.fawe.regions.FaweMaskManager; -import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.MainUtil; +import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.SetQueue; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; @@ -75,61 +75,86 @@ public class HistoryCommands { aliases = { "/frb", "frb", "fawerollback", "/fawerollback" }, usage = "