From 8d0787746324172f680add66c6c4a62a961ca1c8 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 21 Dec 2018 17:31:27 +1000 Subject: [PATCH] Pass the exception converter through more. --- .../sk89q/worldedit/command/WorldEditCommands.java | 5 ++++- .../worldedit/command/util/AsyncCommandHelper.java | 12 +++++++++--- .../worldedit/util/paste/ActorCallbackPaste.java | 5 +++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java index 639acd50b..81add21d7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java @@ -112,7 +112,10 @@ public class WorldEditCommands { if (args.hasFlag('p')) { actor.checkPermission("worldedit.report.pastebin"); - ActorCallbackPaste.pastebin(we.getSupervisor(), actor, result, "WorldEdit report: %s.report"); + ActorCallbackPaste.pastebin( + we.getSupervisor(), actor, result, "WorldEdit report: %s.report", + WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter() + ); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandHelper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandHelper.java index 0f521336d..f3b707435 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandHelper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandHelper.java @@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.util.command.parametric.ExceptionConverter; import com.sk89q.worldedit.util.task.FutureForwardingTask; import com.sk89q.worldedit.util.task.Supervisor; import com.sk89q.worldedit.world.World; @@ -35,17 +36,20 @@ public class AsyncCommandHelper { private final ListenableFuture future; private final Supervisor supervisor; private final Actor sender; + private final ExceptionConverter exceptionConverter; @Nullable private Object[] formatArgs; - private AsyncCommandHelper(ListenableFuture future, Supervisor supervisor, Actor sender) { + private AsyncCommandHelper(ListenableFuture future, Supervisor supervisor, Actor sender, ExceptionConverter exceptionConverter) { checkNotNull(future); checkNotNull(supervisor); checkNotNull(sender); + checkNotNull(exceptionConverter); this.future = future; this.supervisor = supervisor; this.sender = sender; + this.exceptionConverter = exceptionConverter; } public AsyncCommandHelper formatUsing(Object... args) { @@ -78,6 +82,7 @@ public class AsyncCommandHelper { Futures.addCallback( future, new MessageFutureCallback.Builder(sender) + .exceptionConverter(exceptionConverter) .onSuccess(format(success)) .onFailure(format(failure)) .build()); @@ -89,6 +94,7 @@ public class AsyncCommandHelper { Futures.addCallback( future, new MessageFutureCallback.Builder(sender) + .exceptionConverter(exceptionConverter) .onFailure(format(failure)) .build()); return this; @@ -128,8 +134,8 @@ public class AsyncCommandHelper { return this; } - public static AsyncCommandHelper wrap(ListenableFuture future, Supervisor supervisor, Actor sender) { - return new AsyncCommandHelper(future, supervisor, sender); + public static AsyncCommandHelper wrap(ListenableFuture future, Supervisor supervisor, Actor sender, ExceptionConverter exceptionConverter) { + return new AsyncCommandHelper(future, supervisor, sender, exceptionConverter); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java index 2eb306686..a643146c7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java @@ -24,6 +24,7 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.sk89q.worldedit.command.util.AsyncCommandHelper; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.util.command.parametric.ExceptionConverter; import com.sk89q.worldedit.util.task.Supervisor; import java.net.URL; @@ -46,10 +47,10 @@ public class ActorCallbackPaste { * @param content The content * @param successMessage The message, formatted with {@link String#format(String, Object...)} on success */ - public static void pastebin(Supervisor supervisor, final Actor sender, String content, final String successMessage) { + public static void pastebin(Supervisor supervisor, final Actor sender, String content, final String successMessage, final ExceptionConverter exceptionConverter) { ListenableFuture future = new EngineHubPaste().paste(content); - AsyncCommandHelper.wrap(future, supervisor, sender) + AsyncCommandHelper.wrap(future, supervisor, sender, exceptionConverter) .registerWithSupervisor("Submitting content to a pastebin service...") .sendMessageAfterDelay("(Please wait... sending output to pastebin...)");