Merge pull request #84 from Archy-X/master

Add onWrite method with CommandSender in CommandProcessor
This commit is contained in:
TheMode 2020-12-28 19:58:53 +01:00 committed by GitHub
commit f77ec96f25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
}