Add async command suggestions

This commit is contained in:
Mariell Hoversholm
2020-07-14 23:55:34 +02:00
parent 4c3d9de5fe
commit 9c8c851d12
5 changed files with 68 additions and 42 deletions

View File

@@ -2,6 +2,7 @@ package com.velocitypowered.api.command;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
@@ -29,6 +30,18 @@ public interface Command {
return ImmutableList.of();
}
/**
* Provides tab complete suggestions for a command for a specified {@link CommandSource}.
*
* @param source the source to run the command for
* @param currentArgs the current, partial arguments for this command
* @return tab complete suggestions
*/
default CompletableFuture<List<String>> suggestAsync(CommandSource source,
String @NonNull [] currentArgs) {
return CompletableFuture.completedFuture(suggest(source, currentArgs));
}
/**
* Tests to check if the {@code source} has permission to use this command with the provided
* {@code args}.

View File

@@ -2,6 +2,7 @@ package com.velocitypowered.api.command;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
@@ -29,13 +30,19 @@ public interface RawCommand extends Command {
* @param currentLine the current, partial command line for this command
* @return tab complete suggestions
*/
default List<String> suggest(CommandSource source, String currentLine) {
return ImmutableList.of();
default CompletableFuture<List<String>> suggest(CommandSource source, String currentLine) {
return CompletableFuture.completedFuture(ImmutableList.of());
}
@Override
default CompletableFuture<List<String>> suggestAsync(CommandSource source,
String @NonNull [] currentArgs) {
return suggest(source, String.join(" ", currentArgs));
}
@Override
default List<String> suggest(CommandSource source, String @NonNull [] currentArgs) {
return suggest(source, String.join(" ", currentArgs));
return suggestAsync(source, currentArgs).join();
}
@Override