geforkt von Mirrors/Paper
SPIGOT-215: Implement infrastructure for Location tab completes
By: DemonWav <demonwav@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
02b060f77a
Commit
359e6edb63
@ -8,6 +8,7 @@ import java.util.Set;
|
|||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.minecart.CommandMinecart;
|
import org.bukkit.entity.minecart.CommandMinecart;
|
||||||
@ -83,6 +84,22 @@ public abstract class Command {
|
|||||||
* @throws IllegalArgumentException if sender, alias, or args is null
|
* @throws IllegalArgumentException if sender, alias, or args is null
|
||||||
*/
|
*/
|
||||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
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(sender, "Sender cannot be null");
|
||||||
Validate.notNull(args, "Arguments cannot be null");
|
Validate.notNull(args, "Arguments cannot be null");
|
||||||
Validate.notNull(alias, "Alias cannot be null");
|
Validate.notNull(alias, "Alias cannot be null");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.bukkit.command;
|
package org.bukkit.command;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
public interface CommandMap {
|
public interface CommandMap {
|
||||||
|
|
||||||
@ -90,7 +91,6 @@ public interface CommandMap {
|
|||||||
*/
|
*/
|
||||||
public Command getCommand(String name);
|
public Command getCommand(String name);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks for the requested command and executes an appropriate
|
* Looks for the requested command and executes an appropriate
|
||||||
* tab-completer if found. This method will also tab-complete partial
|
* 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
|
* @throws IllegalArgumentException if either sender or cmdLine are null
|
||||||
*/
|
*/
|
||||||
public List<String> tabComplete(CommandSender sender, String cmdLine) throws IllegalArgumentException;
|
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;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import java.util.Map;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.defaults.*;
|
import org.bukkit.command.defaults.*;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -161,6 +162,10 @@ public class SimpleCommandMap implements CommandMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<String> tabComplete(CommandSender sender, String cmdLine) {
|
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(sender, "Sender cannot be null");
|
||||||
Validate.notNull(cmdLine, "Command line cannot 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);
|
String[] args = PATTERN_ON_SPACE.split(argLine, -1);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return target.tabComplete(sender, commandName, args);
|
return target.tabComplete(sender, commandName, args, location);
|
||||||
} catch (CommandException ex) {
|
} catch (CommandException ex) {
|
||||||
throw ex;
|
throw ex;
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren