Add CommandSender as param in onDynamicWrite

This commit is contained in:
themode 2021-01-05 18:04:28 +01:00
parent 45c148974e
commit 3a7ae11c56
5 changed files with 9 additions and 26 deletions

View File

@ -57,12 +57,12 @@ public interface CommandProcessor {
boolean hasAccess(@NotNull Player player);
/**
* Needed to enable {@link #onWrite(String)} callback.
* Needed to enable {@link #onWrite(CommandSender, String)} callback.
* <p>
* Be aware that enabling it can cost some performance because of how often it will be called.
*
* @return true to enable writing tracking (and server auto completion)
* @see #onWrite(String)
* @see #onWrite(CommandSender, String)
*/
default boolean enableWritingTracking() {
return false;
@ -73,21 +73,6 @@ public interface CommandProcessor {
* <p>
* WARNING: {@link #enableWritingTracking()} needs to return true, you need to override it by default.
*
* @param text the whole player text
* @return the array containing all the suggestion for the current arg (split " "), can be null
* @see #enableWritingTracking()
*/
@Nullable
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

View File

@ -254,11 +254,12 @@ public class Command {
* when in a dynamic argument ({@link ArgumentDynamicWord} (when {@link SuggestionType#ASK_SERVER} is used)
* and {@link ArgumentDynamicStringArray}).
*
* @param sender the command sender
* @param text the whole player's text
* @return the array containing all the suggestion for the current arg (split " "), can be null
*/
@Nullable
public String[] onDynamicWrite(@NotNull String text) {
public String[] onDynamicWrite(@NotNull CommandSender sender, @NotNull String text) {
return null;
}

View File

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

View File

@ -80,7 +80,7 @@ public class ReloadExtensionCommand extends Command {
@Nullable
@Override
public String[] onDynamicWrite(@NotNull String text) {
public String[] onDynamicWrite(@NotNull CommandSender sender, @NotNull String text) {
return extensionsName;
}

View File

@ -40,7 +40,7 @@ public class SimpleCommand implements CommandProcessor {
}
@Override
public String[] onWrite(@NotNull String text) {
public String[] onWrite(@NotNull CommandSender sender, @NotNull String text) {
return new String[]{"Complete1", "Complete2"};
}
}