This commit is contained in:
parent
79d70c27da
commit
a87b4be38b
7 changed files with 42 additions and 16 deletions
|
|
@ -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);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue