summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDemonWav <demonwav@gmail.com>2016-08-25 09:48:22 +1000
committermd_5 <git@md-5.net>2016-08-25 09:48:22 +1000
commita2c8560eac9ba82ba2a0a68e8fab1a82e9338a0f (patch)
treecf04a4d92af8f216e8517a2d30e5217f28112c83 /src
parentb28ed606f6ee1b9b81cb3664f9b8efbdb28280fb (diff)
downloadbukkit-a2c8560eac9ba82ba2a0a68e8fab1a82e9338a0f.tar
bukkit-a2c8560eac9ba82ba2a0a68e8fab1a82e9338a0f.tar.gz
bukkit-a2c8560eac9ba82ba2a0a68e8fab1a82e9338a0f.tar.lz
bukkit-a2c8560eac9ba82ba2a0a68e8fab1a82e9338a0f.tar.xz
bukkit-a2c8560eac9ba82ba2a0a68e8fab1a82e9338a0f.zip
SPIGOT-215: Implement infrastructure for Location tab completes
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/command/Command.java17
-rw-r--r--src/main/java/org/bukkit/command/CommandMap.java19
-rw-r--r--src/main/java/org/bukkit/command/SimpleCommandMap.java7
3 files changed, 41 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
index a02c28d6..5445882c 100644
--- a/src/main/java/org/bukkit/command/Command.java
+++ b/src/main/java/org/bukkit/command/Command.java
@@ -8,6 +8,7 @@ import java.util.Set;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
+import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.entity.minecart.CommandMinecart;
@@ -83,6 +84,22 @@ public abstract class Command {
* @throws IllegalArgumentException if sender, alias, or args is null
*/
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
+ return tabComplete(sender, alias, args, null);
+ }
+
+ /**
+ * Executed on tab completion for this command, returning a list of
+ * options the player can tab through.
+ *
+ * @param sender Source object which is executing this command
+ * @param alias the alias being used
+ * @param args All arguments passed to the command, split via ' '
+ * @param location The position looked at by the sender, or null if none
+ * @return a list of tab-completions for the specified arguments. This
+ * will never be null. List may be immutable.
+ * @throws IllegalArgumentException if sender, alias, or args is null
+ */
+ public List<String> 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");
diff --git a/src/main/java/org/bukkit/command/CommandMap.java b/src/main/java/org/bukkit/command/CommandMap.java
index e7e20d89..30d60247 100644
--- a/src/main/java/org/bukkit/command/CommandMap.java
+++ b/src/main/java/org/bukkit/command/CommandMap.java
@@ -1,6 +1,7 @@
package org.bukkit.command;
import java.util.List;
+import org.bukkit.Location;
public interface CommandMap {
@@ -90,7 +91,6 @@ public interface CommandMap {
*/
public Command getCommand(String name);
-
/**
* Looks for the requested command and executes an appropriate
* tab-completer if found. This method will also tab-complete partial
@@ -106,4 +106,21 @@ public interface CommandMap {
* @throws IllegalArgumentException if either sender or cmdLine are null
*/
public List<String> tabComplete(CommandSender sender, String cmdLine) throws IllegalArgumentException;
+
+ /**
+ * Looks for the requested command and executes an appropriate
+ * tab-completer if found. This method will also tab-complete partial
+ * commands.
+ *
+ * @param sender The command's sender.
+ * @param cmdLine The entire command string to tab-complete, excluding
+ * initial slash.
+ * @param location The position looked at by the sender, or null if none
+ * @return a list of possible tab-completions. This list may be immutable.
+ * Will be null if no matching command of which sender has permission.
+ * @throws CommandException Thrown when the tab-completer for the given
+ * command fails with an unhandled exception
+ * @throws IllegalArgumentException if either sender or cmdLine are null
+ */
+ public List<String> tabComplete(CommandSender sender, String cmdLine, Location location) throws IllegalArgumentException;
}
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
index a0262032..4d475c62 100644
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
@@ -11,6 +11,7 @@ import java.util.Map;
import java.util.regex.Pattern;
import org.apache.commons.lang.Validate;
+import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.command.defaults.*;
import org.bukkit.entity.Player;
@@ -161,6 +162,10 @@ public class SimpleCommandMap implements CommandMap {
}
public List<String> tabComplete(CommandSender sender, String cmdLine) {
+ return tabComplete(sender, cmdLine, null);
+ }
+
+ public List<String> tabComplete(CommandSender sender, String cmdLine, Location location) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(cmdLine, "Command line cannot null");
@@ -205,7 +210,7 @@ public class SimpleCommandMap implements CommandMap {
String[] args = PATTERN_ON_SPACE.split(argLine, -1);
try {
- return target.tabComplete(sender, commandName, args);
+ return target.tabComplete(sender, commandName, args, location);
} catch (CommandException ex) {
throw ex;
} catch (Throwable ex) {