From 44dc926c49b009e55be94267f5a9994367f4103e Mon Sep 17 00:00:00 2001 From: wizjany Date: Thu, 19 Sep 2019 20:53:47 -0400 Subject: [PATCH] Fix console command usage. --- .../command/CommandLoggingHandler.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java index 5dd010c61..9f2335d57 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java @@ -28,6 +28,7 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; import org.enginehub.piston.CommandParameters; +import org.enginehub.piston.exception.CommandException; import org.enginehub.piston.gen.CommandCallListener; import org.enginehub.piston.inject.Key; @@ -73,15 +74,23 @@ public class CommandLoggingHandler implements CommandCallListener, AutoCloseable logMode = loggingAnnotation.value(); } - Optional playerOpt = parameters.injectedValue(Key.of(Actor.class)); - Optional worldOpt = parameters.injectedValue(Key.of(World.class)); + Optional actorOpt = parameters.injectedValue(Key.of(Actor.class)); - if (!playerOpt.isPresent() || !worldOpt.isPresent()) { + if (!actorOpt.isPresent()) { return; } + Actor actor = actorOpt.get(); - Actor actor = playerOpt.get(); - World world = worldOpt.get(); + World world; + try { + Optional worldOpt = parameters.injectedValue(Key.of(World.class)); + if (!worldOpt.isPresent()) { + return; + } + world = worldOpt.get(); + } catch (CommandException ex) { + return; + } builder.append("WorldEdit: ").append(actor.getName()); builder.append(" (in \"").append(world.getName()).append("\")");