From b4bff6fc3d3f80a7e297624f5d9dbf3ec7d6f6aa Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 17 Jul 2018 06:49:40 +1000 Subject: [PATCH] SPIGOT-4026: Clicking on command error suggestion should return verbatim input --- nms-patches/CommandDispatcher.patch | 24 ++++++++++++------- .../command/VanillaCommandWrapper.java | 8 +++---- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/nms-patches/CommandDispatcher.patch b/nms-patches/CommandDispatcher.patch index f9842a44d3..0c03bf60ff 100644 --- a/nms-patches/CommandDispatcher.patch +++ b/nms-patches/CommandDispatcher.patch @@ -33,7 +33,7 @@ this.b.setConsumer((commandcontext, flag, i) -> { ((CommandListenerWrapper) commandcontext.getSource()).a(commandcontext, flag, i); }); -@@ -114,7 +126,58 @@ +@@ -114,8 +126,63 @@ } @@ -73,6 +73,11 @@ + } + public int a(CommandListenerWrapper commandlistenerwrapper, String s) { +- String s1 = s; ++ return this.a(commandlistenerwrapper, s, s); ++ } ++ ++ public int a(CommandListenerWrapper commandlistenerwrapper, String s, String label) { + // Some commands use the worldserver variable but we leave it full of null values, + // so we must temporarily populate it with the world of the commandsender + WorldServer[] prev = MinecraftServer.getServer().worldServer; @@ -88,11 +93,12 @@ + } + server.worldServer[pos] = world; + } ++ String s1 = label; + // CraftBukkit end - String s1 = s; if (s.startsWith("/")) { -@@ -126,7 +189,6 @@ + s = s.substring(1); +@@ -126,7 +193,6 @@ byte b0; try { @@ -100,7 +106,7 @@ ChatComponentText chatcomponenttext; try { -@@ -135,54 +197,59 @@ +@@ -135,54 +201,59 @@ return i; } catch (CommandException commandexception) { commandlistenerwrapper.sendFailureMessage(commandexception.a()); @@ -152,17 +158,17 @@ } catch (Exception exception) { - chatcomponenttext = new ChatComponentText; - } -+ ChatMessage chatmessage1 = new ChatMessage("command.failed", new Object[0]); - +- - chatcomponenttext.(exception.getMessage() == null ? exception.getClass().getName() : exception.getMessage()); - ChatComponentText chatcomponenttext1 = chatcomponenttext; ++ ChatMessage chatmessage1 = new ChatMessage("command.failed", new Object[0]); + +- if (CommandDispatcher.a.isDebugEnabled()) { +- StackTraceElement[] astacktraceelement = exception.getStackTrace(); + chatcomponenttext = new ChatComponentText(exception.getMessage() == null ? exception.getClass().getName() : exception.getMessage()); + if (CommandDispatcher.a.isDebugEnabled()) { + StackTraceElement[] astacktraceelement = exception.getStackTrace(); -- if (CommandDispatcher.a.isDebugEnabled()) { -- StackTraceElement[] astacktraceelement = exception.getStackTrace(); -- - for (int k = 0; k < Math.min(astacktraceelement.length, 3); ++k) { - chatcomponenttext1.a("\n\n").a(astacktraceelement[k].getMethodName()).a("\n ").a(astacktraceelement[k].getFileName()).a(":").a(String.valueOf(astacktraceelement[k].getLineNumber())); + for (int k = 0; k < Math.min(astacktraceelement.length, 3); ++k) { diff --git a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java index 5de49fe00e..f6bc346c33 100644 --- a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java +++ b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java @@ -43,7 +43,7 @@ public final class VanillaCommandWrapper extends BukkitCommand { if (!testPermission(sender)) return true; CommandListenerWrapper icommandlistener = getListener(sender); - dispatcher.a(icommandlistener, toDispatcher(args)); + dispatcher.a(icommandlistener, toDispatcher(args, getName()), toDispatcher(args, commandLabel)); return true; } @@ -54,7 +54,7 @@ public final class VanillaCommandWrapper extends BukkitCommand { Validate.notNull(alias, "Alias cannot be null"); CommandListenerWrapper icommandlistener = getListener(sender); - ParseResults parsed = dispatcher.a().parse(toDispatcher(args), icommandlistener); + ParseResults parsed = dispatcher.a().parse(toDispatcher(args, getName()), icommandlistener); List results = new ArrayList<>(); dispatcher.a().getCompletionSuggestions(parsed).thenAccept((suggestions) -> { @@ -91,7 +91,7 @@ public final class VanillaCommandWrapper extends BukkitCommand { return "minecraft.command." + ((vanillaCommand.getRedirect() == null) ? vanillaCommand.getName() : vanillaCommand.getRedirect().getName()); } - private String toDispatcher(String[] args) { - return getName() + ((args.length > 0) ? " " + Joiner.on(' ').join(args) : ""); + private String toDispatcher(String[] args, String name) { + return "/" + name + ((args.length > 0) ? " " + Joiner.on(' ').join(args) : ""); } }