diff --git a/src/main/java/net/minestom/server/command/CommandProcessor.java b/src/main/java/net/minestom/server/command/CommandProcessor.java index 4de2e97e4..0bbf3afd5 100644 --- a/src/main/java/net/minestom/server/command/CommandProcessor.java +++ b/src/main/java/net/minestom/server/command/CommandProcessor.java @@ -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. + *
+ * 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; + } } diff --git a/src/main/java/net/minestom/server/listener/TabCompleteListener.java b/src/main/java/net/minestom/server/listener/TabCompleteListener.java index 52040000e..d845548a8 100644 --- a/src/main/java/net/minestom/server/listener/TabCompleteListener.java +++ b/src/main/java/net/minestom/server/listener/TabCompleteListener.java @@ -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); }