diff --git a/build.gradle b/build.gradle index 4085ad48..6c8d8136 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ ext { date = git.head().date.format("yy.MM.dd") revision = "-${git.head().abbreviatedId}" parents = git.head().parentIds; - index = -73; // Offset to mach CI + index = -74; // Offset to mach CI int major, minor, patch; major = minor = patch = 0; for (;parents != null && !parents.isEmpty();index++) { diff --git a/core/src/main/java/com/boydti/fawe/config/BBC.java b/core/src/main/java/com/boydti/fawe/config/BBC.java index d231105b..46eeb66f 100644 --- a/core/src/main/java/com/boydti/fawe/config/BBC.java +++ b/core/src/main/java/com/boydti/fawe/config/BBC.java @@ -204,7 +204,7 @@ public enum BBC { COMMAND_INVALID_SYNTAX("The command was not used properly (no more help available).", "WorldEdit.Command"), - PROGRESS_MESSAGE("[ Queue: %s0 | Dispatched: %s1 ]", "Progress"), + PROGRESS_MESSAGE("%s1/%s0 (%s2%) @%s3cps %s4s left", "Progress"), PROGRESS_FINISHED("[ Done! ]", "Progress"), COMMAND_SYNTAX("&cUsage: &7%s0", "Error"), diff --git a/core/src/main/java/com/boydti/fawe/config/Settings.java b/core/src/main/java/com/boydti/fawe/config/Settings.java index dd70f210..a1830bd5 100644 --- a/core/src/main/java/com/boydti/fawe/config/Settings.java +++ b/core/src/main/java/com/boydti/fawe/config/Settings.java @@ -248,10 +248,16 @@ public class Settings extends Config { public static int DISCARD_AFTER_MS = 60000; public static class PROGRESS { - @Comment("Display constant titles about the progress of a user's edit") - public boolean DISPLAY = false; + @Comment({"Display constant titles about the progress of a user's edit", + " - false = disabled", + " - title = Display progress titles", + " - chat = Display progress in chat" + }) + public String DISPLAY = "false"; @Comment("How often edit progress is displayed") public int INTERVAL = 1; + @Comment("Delay sending progress in milliseconds (so quick edits don't spam)") + public int DELAY = 5000; } } diff --git a/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java b/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java index e2f247ac..0ccd63d7 100644 --- a/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java +++ b/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java @@ -222,6 +222,9 @@ public abstract class MappedFaweQueue exte } public void end(FaweChunk chunk) { + if (getProgressTask() != null) { + getProgressTask().run(ProgressType.DISPATCH, size() + 1); + } chunk.end(); } diff --git a/core/src/main/java/com/boydti/fawe/object/progress/ChatProgressTracker.java b/core/src/main/java/com/boydti/fawe/object/progress/ChatProgressTracker.java new file mode 100644 index 00000000..1c6b3a90 --- /dev/null +++ b/core/src/main/java/com/boydti/fawe/object/progress/ChatProgressTracker.java @@ -0,0 +1,26 @@ +package com.boydti.fawe.object.progress; + +import com.boydti.fawe.config.BBC; +import com.boydti.fawe.object.FawePlayer; + +public class ChatProgressTracker extends DefaultProgressTracker { + public ChatProgressTracker(FawePlayer player) { + super(player); + setInterval(getDelay() / 50); + } + + @Override + public void sendTask() { + super.sendTask(); + } + + @Override + public void doneTask() { + super.doneTask(); + } + + @Override + public void sendTile(String title, String sub) { + getPlayer().sendMessage(BBC.getPrefix() + title + sub); + } +} \ No newline at end of file diff --git a/core/src/main/java/com/boydti/fawe/object/progress/DefaultProgressTracker.java b/core/src/main/java/com/boydti/fawe/object/progress/DefaultProgressTracker.java index e4659b41..235bab1f 100644 --- a/core/src/main/java/com/boydti/fawe/object/progress/DefaultProgressTracker.java +++ b/core/src/main/java/com/boydti/fawe/object/progress/DefaultProgressTracker.java @@ -15,38 +15,71 @@ public class DefaultProgressTracker extends RunnableVal2 64) { + if (totalQueue > 64 && !done) { + done = true; done(); } return; } // Only send a message after 64 chunks (i.e. ignore smaller edits) - if (totalQueue > 64) { - send(); + long now = System.currentTimeMillis(); + if (now - start > delay) { + long currentTick = now / 50; + if (currentTick > lastTick + interval) { + lastTick = currentTick; + send(); + } } } @@ -62,26 +95,30 @@ public class DefaultProgressTracker extends RunnableVal2 lastTick + Settings.IMP.QUEUE.PROGRESS.INTERVAL) { - lastTick = currentTick; - TaskManager.IMP.task(new Runnable() { // Run on main thread - @Override - public void run() { - sendTask(); - } - }); - } + TaskManager.IMP.task(new Runnable() { // Run on main thread + @Override + public void run() { + sendTask(); + } + }); } public void doneTask() { - player.sendTitle("", BBC.PROGRESS_FINISHED.s()); + sendTile("", BBC.PROGRESS_FINISHED.s()); } public void sendTask() { - String queue = StringMan.padRight("" + amountQueue, 3); - String dispatch = StringMan.padRight("" + amountDispatch, 3); - player.sendTitle("", BBC.PROGRESS_MESSAGE.format(queue, dispatch)); + String queue = StringMan.padRight("" + totalQueue, 3); + String dispatch = StringMan.padLeft("" + amountDispatch, 3); + int total = amountDispatch != 0 ? amountDispatch : amountQueue; + int speed = total != 0 ? (int) (total / Math.max((System.currentTimeMillis() - start) / 1000d, 1)) : 0; + String speedStr = StringMan.padRight("" + speed, 3); + String percent = StringMan.padRight("" + (amountDispatch != 0 ? (amountDispatch * 100) / totalQueue : 0), 3); + int remaining = speed != 0 ? amountQueue / speed : -1; + sendTile("", BBC.PROGRESS_MESSAGE.format(queue, dispatch, percent, StringMan.padLeft("" + speed, 3), StringMan.padLeft("" + remaining, 3))); + } + + public void sendTile(String title, String sub) { + player.sendTitle(title, sub); } } diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index 1788e400..1a0d0439 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -54,6 +54,7 @@ import com.boydti.fawe.object.extent.SlowExtent; import com.boydti.fawe.object.extent.SourceMaskExtent; import com.boydti.fawe.object.function.block.LegacyBlockReplace; import com.boydti.fawe.object.mask.ResettableMask; +import com.boydti.fawe.object.progress.ChatProgressTracker; import com.boydti.fawe.object.progress.DefaultProgressTracker; import com.boydti.fawe.object.visitor.FastChunkIterator; import com.boydti.fawe.util.ExtentTraverser; @@ -269,8 +270,16 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting } this.queue = queue; this.queue.addEditSession(this); - if (Settings.IMP.QUEUE.PROGRESS.DISPLAY && player != null) { - this.queue.setProgressTask(new DefaultProgressTracker(player)); + if (!Settings.IMP.QUEUE.PROGRESS.DISPLAY.equalsIgnoreCase("false") && player != null) { + switch (Settings.IMP.QUEUE.PROGRESS.DISPLAY.toLowerCase()) { + case "chat": + this.queue.setProgressTask(new ChatProgressTracker(player)); + break; + case "title": + case "true": + default: + this.queue.setProgressTask(new DefaultProgressTracker(player)); + } } this.bypassAll = wrapExtent(new FastWorldEditExtent(world, queue), bus, event, Stage.BEFORE_CHANGE); this.bypassHistory = (this.extent = wrapExtent(bypassAll, bus, event, Stage.BEFORE_REORDER));