3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-17 03:50:08 +01:00
Paper/Bukkit-Patches/0012-Console-Command-Completion.patch
2013-08-03 18:45:50 +10:00

79 Zeilen
3.2 KiB
Diff

From f9a4d23f040aa2b30d09b6e563fb90a87c85731a Mon Sep 17 00:00:00 2001
From: Phillip Schichtel <quick_wango@code-infection.de>
Date: Mon, 29 Apr 2013 23:07:42 +0200
Subject: [PATCH] Console Command Completion
Implement command tab completion in the console. Adds BUKKIT-4168
To accomplish this 2 changes to Bukkit were required:
- the player check in Command.tabComplete() had to be removed
- the SimpleCommandMap prepends the / only for players
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
index 5416c71..2f189ca 100644
--- a/src/main/java/org/bukkit/command/Command.java
+++ b/src/main/java/org/bukkit/command/Command.java
@@ -78,18 +78,13 @@ public abstract class Command {
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
- if (!(sender instanceof Player) || args.length == 0) {
- return ImmutableList.of();
- }
-
String lastWord = args[args.length - 1];
- Player senderPlayer = (Player) sender;
-
ArrayList<String> matchedPlayers = new ArrayList<String>();
+ final boolean noPlayer = !(sender instanceof Player);
for (Player player : sender.getServer().getOnlinePlayers()) {
String name = player.getName();
- if (senderPlayer.canSee(player) && StringUtil.startsWithIgnoreCase(name, lastWord)) {
+ if (noPlayer || ((Player) sender).canSee(player) && StringUtil.startsWithIgnoreCase(name, lastWord)) {
matchedPlayers.add(name);
}
}
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
index f567dc0..f716782 100644
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
@@ -16,6 +16,7 @@ import java.util.regex.Pattern;
import org.apache.commons.lang.Validate;
import org.bukkit.Server;
import org.bukkit.command.defaults.*;
+import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
public class SimpleCommandMap implements CommandMap {
@@ -226,6 +227,8 @@ public class SimpleCommandMap implements CommandMap {
ArrayList<String> completions = new ArrayList<String>();
Map<String, Command> knownCommands = this.knownCommands;
+ final String prefix = (sender instanceof Player ? "/" : "");
+
for (VanillaCommand command : fallbackCommands) {
String name = command.getName();
@@ -241,7 +244,7 @@ public class SimpleCommandMap implements CommandMap {
continue;
}
- completions.add('/' + name);
+ completions.add(prefix + name);
}
for (Map.Entry<String, Command> commandEntry : knownCommands.entrySet()) {
@@ -254,7 +257,7 @@ public class SimpleCommandMap implements CommandMap {
String name = commandEntry.getKey(); // Use the alias, not command name
if (StringUtil.startsWithIgnoreCase(name, cmdLine)) {
- completions.add('/' + name);
+ completions.add(prefix + name);
}
}
--
1.8.1.2