SPIGOT-3182: Fix tab-completion in command blocks without leading slash

This commit is contained in:
Pokechu22 2017-04-13 17:57:47 -07:00
parent d219213e2b
commit 1ac133ecc5
2 changed files with 9 additions and 5 deletions

View File

@ -568,7 +568,7 @@
return arraylist; return arraylist;
} }
+ */ + */
+ return server.tabComplete(icommandlistener, s, blockposition); + return server.tabComplete(icommandlistener, s, blockposition, flag);
+ // CraftBukkit end + // CraftBukkit end
} }

View File

@ -1532,14 +1532,14 @@ public final class CraftServer implements Server {
return warningState; return warningState;
} }
public List<String> tabComplete(net.minecraft.server.ICommandListener sender, String message, BlockPosition pos) { public List<String> tabComplete(net.minecraft.server.ICommandListener sender, String message, BlockPosition pos, boolean forceCommand) {
if (!(sender instanceof EntityPlayer)) { if (!(sender instanceof EntityPlayer)) {
return ImmutableList.of(); return ImmutableList.of();
} }
List<String> offers; List<String> offers;
Player player = ((EntityPlayer) sender).getBukkitEntity(); Player player = ((EntityPlayer) sender).getBukkitEntity();
if (message.startsWith("/")) { if (message.startsWith("/") || forceCommand) {
offers = tabCompleteCommand(player, message, pos); offers = tabCompleteCommand(player, message, pos);
} else { } else {
offers = tabCompleteChat(player, message); offers = tabCompleteChat(player, message);
@ -1554,10 +1554,14 @@ public final class CraftServer implements Server {
public List<String> tabCompleteCommand(Player player, String message, BlockPosition pos) { public List<String> tabCompleteCommand(Player player, String message, BlockPosition pos) {
List<String> completions = null; List<String> completions = null;
try { try {
if (message.startsWith("/")) {
// Trim leading '/' if present (won't always be present in command blocks)
message = message.substring(1);
}
if (pos == null) { if (pos == null) {
completions = getCommandMap().tabComplete(player, message.substring(1)); completions = getCommandMap().tabComplete(player, message);
} else { } 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) { } catch (CommandException ex) {
player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to tab-complete this command"); player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to tab-complete this command");