Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/Bukkit-Patches/0012-Console-Command-Completion.patch

79 Zeilen
3.2 KiB
Diff

From e0673d1050250f5e32ac173a12b3c65cab315b40 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 df5f6ef..4c3e421 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 {
@@ -224,6 +225,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();
@@ -239,7 +242,7 @@ public class SimpleCommandMap implements CommandMap {
continue;
}
- completions.add('/' + name);
+ completions.add(prefix + name);
}
for (Map.Entry<String, Command> commandEntry : knownCommands.entrySet()) {
@@ -252,7 +255,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