aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-API-Patches/0015-Add-Location-support-to-tab-completers-vanilla-featu.patch
blob: 18cdb659ebd8387cd6d706e6ba16c1807c9a8a33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
From 5866613ee6d1fdcdf75c97983d6f28e6cf1e2342 Mon Sep 17 00:00:00 2001
From: DemonWav <demonwav@gmail.com>
Date: Sat, 30 Jan 2016 18:58:09 -0600
Subject: [PATCH] Add Location support to tab completers (vanilla feature
 missing in CraftBukkit)


diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
index 548d570..3d0c5a5 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;
@@ -109,6 +110,31 @@ public abstract class Command {
         return matchedPlayers;
     }
 
+    // PaperSpigot start - location tab-completes
+    /**
+     * Executed on tab completion for this command, returning a list of options the player can tab through. This method
+     * returns the {@link Location} of the block the player is looking at at the time of the tab complete.
+     * <p>
+     * Commands that want to use the Location information in their tab-complete implementations need to override this
+     * method. The Location provided by this method is the block that the player is currently looking at when the player
+     * attempts the tab complete. For this to be valid, the block must be highlighted by the player (i.e. the player is
+     * close enough to interact with the block).
+     *
+     * @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 location of the block the player is looking at
+     * @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 {
+        // Simply default to the standard tab-complete, subclasses can override this if needed
+        System.out.println("wat");
+        return tabComplete(sender, alias, args);
+    }
+    // PaperSpigot end
+
     /**
      * Returns the name of this command
      *
diff --git a/src/main/java/org/bukkit/command/PluginCommand.java b/src/main/java/org/bukkit/command/PluginCommand.java
index 3bfa31f..597d7c2 100644
--- a/src/main/java/org/bukkit/command/PluginCommand.java
+++ b/src/main/java/org/bukkit/command/PluginCommand.java
@@ -1,10 +1,11 @@
 package org.bukkit.command;
 
-import java.util.List;
-
 import org.apache.commons.lang.Validate;
+import org.bukkit.Location;
 import org.bukkit.plugin.Plugin;
 
+import java.util.List;
+
 /**
  * Represents a {@link Command} belonging to a plugin
  */
@@ -122,6 +123,15 @@ public final class PluginCommand extends Command implements PluginIdentifiableCo
      */
     @Override
     public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException {
+        return tabComplete(sender, alias, args, null); // PaperSpigot - The code from this method has been (slightly modified) moved to the Location method.
+    }
+
+    // PaperSpigot start - location tab-completes
+    /**
+     * This code was copied from tabComplete(CommandSender sender, String alias, String[] args)
+     */
+    @Override
+    public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws CommandException, IllegalArgumentException {
         Validate.notNull(sender, "Sender cannot be null");
         Validate.notNull(args, "Arguments cannot be null");
         Validate.notNull(alias, "Alias cannot be null");
@@ -129,10 +139,10 @@ public final class PluginCommand extends Command implements PluginIdentifiableCo
         List<String> completions = null;
         try {
             if (completer != null) {
-                completions = completer.onTabComplete(sender, this, alias, args);
+                completions = completer.onTabComplete(sender, this, alias, args, location); // PaperSpigot - add location argument
             }
             if (completions == null && executor instanceof TabCompleter) {
-                completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
+                completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args, location); // PaperSpigot - add location argument
             }
         } catch (Throwable ex) {
             StringBuilder message = new StringBuilder();
@@ -149,6 +159,7 @@ public final class PluginCommand extends Command implements PluginIdentifiableCo
         }
         return completions;
     }
+    // PaperSpigot end
 
     @Override
     public String toString() {
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
index a300ae7..12d9232 100644
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
@@ -12,6 +12,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;
@@ -167,6 +168,14 @@ public class SimpleCommandMap implements CommandMap {
     }
 
     public List<String> tabComplete(CommandSender sender, String cmdLine) {
+        return tabComplete(sender, cmdLine, null); // PaperSpigot - location tab-completes, code moved below
+    }
+
+    // PaperSpigot start - location tab-completes
+    /*
+        this code was copied, except for the noted change, from tabComplete(CommandSender sender, String cmdLine)
+     */
+    public List<String> tabComplete(CommandSender sender, String cmdLine, Location location) {
         Validate.notNull(sender, "Sender cannot be null");
         Validate.notNull(cmdLine, "Command line cannot null");
 
@@ -211,13 +220,14 @@ 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); // PaperSpigot - add location argument
         } catch (CommandException ex) {
             throw ex;
         } catch (Throwable ex) {
             throw new CommandException("Unhandled exception executing tab-completer for '" + cmdLine + "' in " + target, ex);
         }
     }
+    // PaperSpigot end
 
     public Collection<Command> getCommands() {
         return Collections.unmodifiableCollection(knownCommands.values());
diff --git a/src/main/java/org/bukkit/command/TabCompleter.java b/src/main/java/org/bukkit/command/TabCompleter.java
index 6d61e3a..2cb971c 100644
--- a/src/main/java/org/bukkit/command/TabCompleter.java
+++ b/src/main/java/org/bukkit/command/TabCompleter.java
@@ -1,5 +1,7 @@
 package org.bukkit.command;
 
+import org.bukkit.Location;
+
 import java.util.List;
 
 /**
@@ -19,4 +21,10 @@ public interface TabCompleter {
      *     to default to the command executor
      */
     public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args);
+
+    // PaperSpigot start - location tab-completes
+    default List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args, Location location) {
+        return onTabComplete(sender, command, alias, args);
+    }
+    // PaperSpigot end
 }
-- 
2.7.1