.
Some checks failed
Build and Deploy artifact / build (push) Failing after 1m0s

This commit is contained in:
kento2 2026-08-10 11:58:39 +02:00
parent 79d70c27da
commit a87b4be38b
7 changed files with 42 additions and 16 deletions

View file

@ -2,6 +2,7 @@ package de.kentoj.kencommandapi.api.invocation;
import de.kentoj.kencommandapi.api.argument.CommandArgument;
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
import de.kentoj.kencommandapi.api.platform.MessageStyle;
import java.util.Map;
@ -9,6 +10,8 @@ public interface CommandContext<T> {
T sender();
<S extends MessageStyle> S style();
<V> CommandArgument<T, V> getParsedArgument(String id);
/**

View file

@ -1,10 +1,8 @@
package de.kentoj.kencommandapi.api.invocation;
import de.kentoj.kencommandapi.api.platform.MessageStyle;
import java.util.concurrent.CompletableFuture;
public interface CommandExecutor<T> {
CompletableFuture<?> execute(MessageStyle style, CommandContext<T> ctx);
CompletableFuture<?> execute(CommandContext<T> ctx);
}

View file

@ -1,15 +1,13 @@
package de.kentoj.kencommandapi.api.invocation;
import de.kentoj.kencommandapi.api.platform.MessageStyle;
import java.util.concurrent.CompletableFuture;
public interface SyncCommandExecutor<T> extends CommandExecutor<T> {
void executeSync(MessageStyle style, CommandContext<T> ctx);
void executeSync(CommandContext<T> ctx);
default CompletableFuture<?> execute(MessageStyle style, CommandContext<T> ctx) {
this.executeSync(style, ctx);
default CompletableFuture<?> execute(CommandContext<T> ctx) {
this.executeSync(ctx);
return CompletableFuture.completedFuture(null);
}
}

View file

@ -4,15 +4,18 @@ import de.kentoj.kencommandapi.api.argument.CommandArgument;
import de.kentoj.kencommandapi.api.argument.CommandArgumentImpl;
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
import de.kentoj.kencommandapi.api.invocation.CommandContext;
import de.kentoj.kencommandapi.api.platform.MessageStyle;
import java.util.Map;
public class CommandContextBuilder<T> {
private final T sender;
private final MessageStyle style;
private final Map<String, CommandArgument<T, ?>> parsedArgument;
public CommandContextBuilder(T sender, Map<String, CommandArgument<T, ?>> parsedArgument) {
public CommandContextBuilder(T sender, MessageStyle style, Map<String, CommandArgument<T, ?>> parsedArgument) {
this.sender = sender;
this.style = style;
this.parsedArgument = parsedArgument;
}
@ -21,6 +24,6 @@ public class CommandContextBuilder<T> {
}
public CommandContext<T> build() {
return new CommandContextImpl<>(sender, parsedArgument);
return new CommandContextImpl<>(sender, style, parsedArgument);
}
}

View file

@ -2,13 +2,27 @@ package de.kentoj.kencommandapi.internal;
import de.kentoj.kencommandapi.api.argument.CommandArgument;
import de.kentoj.kencommandapi.api.invocation.CommandContext;
import de.kentoj.kencommandapi.api.platform.MessageStyle;
import java.util.Map;
record CommandContextImpl<T>(
T sender,
Map<String, CommandArgument<T, ?>> parsedArguments
) implements CommandContext<T> {
class CommandContextImpl<T> implements CommandContext<T> {
private final T sender;
private final MessageStyle style;
private final Map<String, CommandArgument<T, ?>> parsedArguments;
CommandContextImpl(T sender, MessageStyle style, Map<String, CommandArgument<T, ?>> parsedArguments) {
this.sender = sender;
this.style = style;
this.parsedArguments = parsedArguments;
}
@SuppressWarnings("unchecked")
@Override
public <S extends MessageStyle> S style() {
return (S) style;
}
@Override
public <V> CommandArgument<T, V> getParsedArgument(String id) {
try {
@ -18,4 +32,14 @@ record CommandContextImpl<T>(
throw new RuntimeException("requested argument with wrong type", e);
}
}
@Override
public Map<String, CommandArgument<T, ?>> parsedArguments() {
return Map.of();
}
@Override
public T sender() {
return sender;
}
}

View file

@ -25,7 +25,7 @@ public class NodeTreeWalker<T> {
Iterator<String> iter
) {
var cursor = new Cursor(iter);
var ctxBuilder = new CommandContextBuilder<>(sender, new HashMap<>());
var ctxBuilder = new CommandContextBuilder<>(sender, rootLiteral.style(), new HashMap<>());
Literal<T> literal = rootLiteral;
String token;