Add onWrite method with CommandSender in CommandProcessor

This commit is contained in:
Archy-X 2020-12-28 10:59:18 -07:00
parent ca3667732f
commit e911612ad6
2 changed files with 20 additions and 1 deletions

View File

@ -81,4 +81,20 @@ public interface CommandProcessor {
default String[] onWrite(@NotNull String text) {
return null;
}
/**
* Allows for tab auto completion, this is called everytime the player press a key in the chat.
* <p>
* WARNING: {@link #enableWritingTracking()} needs to return true, you need to override it by default.
* This does not work if {@link #onWrite(String) is overriden}
*
* @param sender the command sender
* @param text the whole player text
* @return the array containing all the suggestions for the current arg (split " "), can be null
* @see #enableWritingTracking()
*/
@Nullable
default String[] onWrite(@NotNull CommandSender sender, String text) {
return null;
}
}

View File

@ -25,7 +25,10 @@ public class TabCompleteListener {
final CommandProcessor commandProcessor = COMMAND_MANAGER.getCommandProcessor(commandName);
if (commandProcessor != null) {
final int start = findStart(text, split);
final String[] matches = commandProcessor.onWrite(text);
String[] matches = commandProcessor.onWrite(text);
if (matches == null) {
matches = commandProcessor.onWrite(player, text);
}
if (matches != null && matches.length > 0) {
sendTabCompletePacket(packet.transactionId, start, matches, player);
}