From 1ac133ecc52da74c6f87e3cf308fc4ad39df4518 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Thu, 13 Apr 2017 17:57:47 -0700 Subject: [PATCH] SPIGOT-3182: Fix tab-completion in command blocks without leading slash --- nms-patches/MinecraftServer.patch | 2 +- .../java/org/bukkit/craftbukkit/CraftServer.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/nms-patches/MinecraftServer.patch b/nms-patches/MinecraftServer.patch index a60fd8bfe3..9806f0f7d2 100644 --- a/nms-patches/MinecraftServer.patch +++ b/nms-patches/MinecraftServer.patch @@ -568,7 +568,7 @@ return arraylist; } + */ -+ return server.tabComplete(icommandlistener, s, blockposition); ++ return server.tabComplete(icommandlistener, s, blockposition, flag); + // CraftBukkit end } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 39d4daec28..50e1349a6c 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1532,14 +1532,14 @@ public final class CraftServer implements Server { return warningState; } - public List tabComplete(net.minecraft.server.ICommandListener sender, String message, BlockPosition pos) { + public List tabComplete(net.minecraft.server.ICommandListener sender, String message, BlockPosition pos, boolean forceCommand) { if (!(sender instanceof EntityPlayer)) { return ImmutableList.of(); } List offers; Player player = ((EntityPlayer) sender).getBukkitEntity(); - if (message.startsWith("/")) { + if (message.startsWith("/") || forceCommand) { offers = tabCompleteCommand(player, message, pos); } else { offers = tabCompleteChat(player, message); @@ -1554,10 +1554,14 @@ public final class CraftServer implements Server { public List tabCompleteCommand(Player player, String message, BlockPosition pos) { List completions = null; try { + if (message.startsWith("/")) { + // Trim leading '/' if present (won't always be present in command blocks) + message = message.substring(1); + } if (pos == null) { - completions = getCommandMap().tabComplete(player, message.substring(1)); + completions = getCommandMap().tabComplete(player, message); } else { - completions = getCommandMap().tabComplete(player, message.substring(1), new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ())); + completions = getCommandMap().tabComplete(player, message, new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ())); } } catch (CommandException ex) { player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to tab-complete this command");