From c74e2a73016e1e6b7ebf025e40438e16b90b41a3 Mon Sep 17 00:00:00 2001 From: DemonWav Date: Thu, 25 Aug 2016 09:48:52 +1000 Subject: [PATCH] SPIGOT-215: Implement infrastructure for Location tab completes --- nms-patches/MinecraftServer.patch | 2 +- .../java/org/bukkit/craftbukkit/CraftServer.java | 13 +++++++++---- .../craftbukkit/command/VanillaCommandWrapper.java | 7 ++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/nms-patches/MinecraftServer.patch b/nms-patches/MinecraftServer.patch index ac22754f22..909dba27d5 100644 --- a/nms-patches/MinecraftServer.patch +++ b/nms-patches/MinecraftServer.patch @@ -568,7 +568,7 @@ return arraylist; } + */ -+ return server.tabComplete(icommandlistener, s); // PAIL : todo args ++ return server.tabComplete(icommandlistener, s, blockposition); + // CraftBukkit end } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index bb956bc06c..a741f1eb2d 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -29,6 +29,7 @@ import org.bukkit.BanList; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; +import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.UnsafeValues; @@ -1528,7 +1529,7 @@ public final class CraftServer implements Server { return warningState; } - public List tabComplete(net.minecraft.server.ICommandListener sender, String message) { + public List tabComplete(net.minecraft.server.ICommandListener sender, String message, BlockPosition pos) { if (!(sender instanceof EntityPlayer)) { return ImmutableList.of(); } @@ -1536,7 +1537,7 @@ public final class CraftServer implements Server { List offers; Player player = ((EntityPlayer) sender).getBukkitEntity(); if (message.startsWith("/")) { - offers = tabCompleteCommand(player, message); + offers = tabCompleteCommand(player, message, pos); } else { offers = tabCompleteChat(player, message); } @@ -1547,10 +1548,14 @@ public final class CraftServer implements Server { return tabEvent.isCancelled() ? Collections.EMPTY_LIST : tabEvent.getCompletions(); } - public List tabCompleteCommand(Player player, String message) { + public List tabCompleteCommand(Player player, String message, BlockPosition pos) { List completions = null; try { - completions = getCommandMap().tabComplete(player, message.substring(1)); + if (pos == null) { + completions = getCommandMap().tabComplete(player, message.substring(1)); + } else { + completions = getCommandMap().tabComplete(player, message.substring(1), 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"); getLogger().log(Level.SEVERE, "Exception when " + player.getName() + " attempted to tab complete " + message, ex); diff --git a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java index 0930d30dd7..dcc2ab070a 100644 --- a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java +++ b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java @@ -7,6 +7,7 @@ import net.minecraft.server.*; import org.apache.commons.lang.Validate; import org.apache.logging.log4j.Level; +import org.bukkit.Location; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; @@ -38,11 +39,11 @@ public final class VanillaCommandWrapper extends VanillaCommand { } @Override - public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { + public List tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException { Validate.notNull(sender, "Sender cannot be null"); Validate.notNull(args, "Arguments cannot be null"); Validate.notNull(alias, "Alias cannot be null"); - return (List) vanillaCommand.tabComplete(MinecraftServer.getServer(), getListener(sender), args, new BlockPosition(0, 0, 0)); + return (List) vanillaCommand.tabComplete(MinecraftServer.getServer(), getListener(sender), args, new BlockPosition(location.getX(), location.getY(), location.getZ())); } public static CommandSender lastSender = null; // Nasty :( @@ -72,7 +73,7 @@ public final class VanillaCommandWrapper extends VanillaCommand { if (i > -1) { List list = ((List)PlayerSelector.getPlayers(icommandlistener, as[i], Entity.class)); String s2 = as[i]; - + icommandlistener.a(CommandObjectiveExecutor.EnumCommandResult.AFFECTED_ENTITIES, list.size()); Iterator iterator = list.iterator();