Permalink
Browse files

Pass the exception converter through more.

  • Loading branch information...
me4502 committed Dec 21, 2018
1 parent ea30578 commit 8d0787746324172f680add66c6c4a62a961ca1c8
@@ -112,7 +112,10 @@ public void report(Actor actor, CommandContext args) throws WorldEditException {

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

@@ -24,6 +24,7 @@
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 @@
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 AsyncCommandHelper thenRespondWith(String success, String failure) {
Futures.addCallback(
future,
new MessageFutureCallback.Builder(sender)
.exceptionConverter(exceptionConverter)
.onSuccess(format(success))
.onFailure(format(failure))
.build());
@@ -89,6 +94,7 @@ public AsyncCommandHelper thenTellErrorsOnly(String failure) {
Futures.addCallback(
future,
new MessageFutureCallback.Builder(sender)
.exceptionConverter(exceptionConverter)
.onFailure(format(failure))
.build());
return this;
@@ -128,8 +134,8 @@ public AsyncCommandHelper forRegionDataSave(World world, boolean silent) {
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);
}

}
@@ -24,6 +24,7 @@
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 @@ private 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<URL> 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...)");

0 comments on commit 8d07877

Please sign in to comment.