This commit is contained in:
kento2 2026-07-05 00:36:48 +02:00
parent 9aa138058c
commit b234cd9df7
17 changed files with 51 additions and 56 deletions

View file

@ -11,7 +11,7 @@ repositories {
}
dependencies {
api("net.kyori:adventure-api:5.2.0")
compileOnly("net.kyori:adventure-api:5.2.0")
}
publishing {

View file

@ -31,16 +31,14 @@ public class CommandHandler<T> {
var ctx = new CommandContext<>(sender, ((ParseResult.Success<T>) parseResult).getParsedArguments());
assert parseResult.getLiteral().getExecutor() != null;
parseResult.getLiteral().getExecutor().execute(ctx).whenComplete((result, ex) -> {
if (ex != null) {
if (ex != null)
sendMessageMethod.send(sender, rootNode.getMessageStyle().exception(ex));
}
result.ifFailure(failure ->
sendMessageMethod.send(sender, rootNode.getMessageStyle().err(failure))
);
sendMessageMethod.send(sender, rootNode.getMessageStyle().err(failure)));
});
}
public CompletableFuture<List<String>> getSuggestions(RootCommandNode<T> rootNode, T sender, String[] args) {
public List<String> getSuggestions(RootCommandNode<T> rootNode, T sender, String[] args) {
var parseResult = commandParser.parseLiteral(rootNode, sender, args, false);
if (parseResult instanceof ParseResult.ArgumentExpected<T>) {
@ -56,7 +54,7 @@ public class CommandHandler<T> {
return getSuggestions(sender, parseResult.getLiteral(), filter);
}
private CompletableFuture<List<String>> getSuggestions(T sender, CommandNode<T> literal, @Nullable String filter) {
private List<String> getSuggestions(T sender, CommandNode<T> literal, @Nullable String filter) {
var stream = literal.getLiterals().stream()
.filter(lit -> lit.getPermission() != null && hasPermissionMethod.hasPermission(sender, lit.getPermission()))
.map(CommandNode::getNames)
@ -64,6 +62,6 @@ public class CommandHandler<T> {
if (filter != null)
stream = stream.filter(f -> f.toLowerCase().contains(filter.toLowerCase()));
return CompletableFuture.completedFuture(stream.toList());
return stream.toList();
}
}

View file

@ -6,5 +6,5 @@ import java.util.concurrent.CompletableFuture;
public interface CommandExecutor<T> {
CompletableFuture<Result<Void, String>> execute(CommandContext<T> ctx);
CompletableFuture<Result<Object, String>> execute(CommandContext<T> ctx);
}

View file

@ -0,0 +1,14 @@
package de.kentoj.kencommandapi.api.invocation;
import com.leakyabstractions.result.api.Result;
import java.util.concurrent.CompletableFuture;
public interface SyncCommandExecutor<T> extends CommandExecutor<T> {
Result<Object, String> executeSync(CommandContext<T> ctx);
default CompletableFuture<Result<Object, String>> execute(CommandContext<T> ctx) {
return CompletableFuture.completedFuture(this.executeSync(ctx));
}
}

View file

@ -108,7 +108,7 @@ public abstract sealed class ParseResult<T> permits ParseResult.IllegalArgument,
@Override
public String getMessage() {
return "Illegal argument '" + argStr + "' for " + argument.getId() + ":" + message;
return "Illegal argument '" + argStr + "' for " + argument.getId() + ": " + message;
}
}
}

View file

@ -7,7 +7,7 @@ import java.util.concurrent.CompletableFuture;
public class NoSuggestionProvider<T> implements SuggestionProvider<T> {
@Override
public CompletableFuture<List<String>> suggest(T __) {
return CompletableFuture.completedFuture(Collections.emptyList());
public List<String> suggest(T __) {
return Collections.emptyList();
}
}

View file

@ -8,5 +8,5 @@ public interface SuggestionProvider<T> {
/**
* @return an unfiltered(no permission checks or filtering by input) list of strings that may be used for the argument
*/
CompletableFuture<List<String>> suggest(T sender);
List<String> suggest(T sender);
}

View file

@ -44,7 +44,7 @@ public class CommandNodeImpl<T> implements CommandNode<T> {
if (isGreedy()) throw new IllegalStateException("can't add literal to a node with a greedy argument");
for (String name : commandNode.getNames())
if (getLiteral(name) != null)
throw new IllegalArgumentException("literal with same name is already exists");
throw new IllegalArgumentException("literal with same name already exists");
literals.add(commandNode);
}