.
This commit is contained in:
parent
c2aec2842a
commit
5cec83b992
34 changed files with 269 additions and 58 deletions
|
|
@ -2,7 +2,7 @@ package de.kentoj.kencommandapi;
|
|||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||
import de.kentoj.kencommandapi.api.processing.ParsedArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.types.IntegerArgumentType;
|
||||
import de.kentoj.kencommandapi.api.types.IntegerArgumentType;
|
||||
import de.kentoj.kencommandapi.impl.AbstractKenCommandApi;
|
||||
import de.kentoj.kencommandapi.impl.processing.CommandContextImpl;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package de.kentoj.kencommandapi.api;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
|
||||
public interface KenCommandApi<T, S extends CommandContext<T, ?>> {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package de.kentoj.kencommandapi.api.structure.argument;
|
||||
package de.kentoj.kencommandapi.api.argument;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
|
||||
|
|
@ -7,4 +7,8 @@ public interface ArgumentType<T, S extends CommandContext<T, ?>, V> {
|
|||
V parseInput(String string);
|
||||
|
||||
SuggestionProvider<T, S> defaultSuggestionProvider();
|
||||
|
||||
default boolean isGreedy() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package de.kentoj.kencommandapi.api.structure.argument;
|
||||
package de.kentoj.kencommandapi.api.argument;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package de.kentoj.kencommandapi.api.structure.argument;
|
||||
package de.kentoj.kencommandapi.api.argument;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.kencommandapi.api.structure.argument.suggestion;
|
||||
package de.kentoj.kencommandapi.api.argument.suggestion;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.SuggestionProvider;
|
||||
import de.kentoj.kencommandapi.api.argument.SuggestionProvider;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.kencommandapi.api.structure.node;
|
||||
package de.kentoj.kencommandapi.api.nodes;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package de.kentoj.kencommandapi.api.structure.node;
|
||||
package de.kentoj.kencommandapi.api.nodes;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandExecutor;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package de.kentoj.kencommandapi.api.structure.node;
|
||||
package de.kentoj.kencommandapi.api.nodes;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package de.kentoj.kencommandapi.api.processing;
|
||||
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
|
||||
public interface CommandContext<T, S extends CommandContext<T, ?>> {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package de.kentoj.kencommandapi.api.processing;
|
||||
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
|
||||
public interface ParsedArgument<T, S extends CommandContext<T, ?>, V> {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package de.kentoj.kencommandapi.api.structure.argument.types;
|
||||
package de.kentoj.kencommandapi.api.types;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.SuggestionProvider;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.suggestion.NoSuggestionProvider;
|
||||
import de.kentoj.kencommandapi.api.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.argument.SuggestionProvider;
|
||||
import de.kentoj.kencommandapi.api.argument.suggestion.NoSuggestionProvider;
|
||||
|
||||
public class IntegerArgumentType<T, S extends CommandContext<T, ?>> implements ArgumentType<T, S, Integer> {
|
||||
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
package de.kentoj.kencommandapi.api.structure.argument.types;
|
||||
package de.kentoj.kencommandapi.api.types;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.SuggestionProvider;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.suggestion.NoSuggestionProvider;
|
||||
import lombok.Getter;
|
||||
import de.kentoj.kencommandapi.api.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.argument.SuggestionProvider;
|
||||
import de.kentoj.kencommandapi.api.argument.suggestion.NoSuggestionProvider;
|
||||
|
||||
public class StringArgumentType<T, S extends CommandContext<T, ?>> implements ArgumentType<T, S, String> {
|
||||
|
||||
|
|
@ -4,9 +4,9 @@ import de.kentoj.kencommandapi.api.KenCommandApi;
|
|||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||
import de.kentoj.kencommandapi.api.processing.ParsedArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.kencommandapi.impl.processing.ParsedArgumentImpl;
|
||||
import de.kentoj.kencommandapi.impl.structure.CommandArgumentImpl;
|
||||
import de.kentoj.kencommandapi.impl.structure.CommandNodeImpl;
|
||||
|
|
@ -16,6 +16,7 @@ import java.util.Arrays;
|
|||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public abstract class AbstractKenCommandApi<T, S extends CommandContext<T, ?>> implements KenCommandApi<T, S> {
|
||||
|
|
@ -85,9 +86,23 @@ public abstract class AbstractKenCommandApi<T, S extends CommandContext<T, ?>> i
|
|||
continue;
|
||||
}
|
||||
|
||||
var parsedArg = arg.getType().parseInput(iter.next());
|
||||
var rawArgument = getRawArgument(arg, iter);
|
||||
var parsedArg = arg.getType().parseInput(rawArgument);
|
||||
parsedArguments.put(arg.getId(), new ParsedArgumentImpl<>(parsedArg, arg));
|
||||
}
|
||||
return parsedArguments;
|
||||
}
|
||||
|
||||
private String getRawArgument(CommandArgument<T, S, Object> arg, Iterator<String> iter) {
|
||||
var rawArgument = "";
|
||||
if (arg.getType().isGreedy()) {
|
||||
while (iter.hasNext()) {
|
||||
//noinspection StringConcatenationInLoop
|
||||
rawArgument += iter.next();
|
||||
}
|
||||
} else {
|
||||
rawArgument = iter.next();
|
||||
}
|
||||
return rawArgument;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package de.kentoj.kencommandapi.impl.processing;
|
|||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.ParsedArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.kencommandapi.impl.processing;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package de.kentoj.kencommandapi.impl.structure;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.SuggestionProvider;
|
||||
import de.kentoj.kencommandapi.api.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.argument.SuggestionProvider;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
package de.kentoj.kencommandapi.impl.structure;
|
||||
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CommandNodeImpl<T, S extends CommandContext<T, ?>> implements CommandNode<T, S> {
|
||||
|
|
@ -19,7 +20,7 @@ public class CommandNodeImpl<T, S extends CommandContext<T, ?>> implements Comma
|
|||
@Getter
|
||||
private final Set<CommandNode<T, S>> literals = new HashSet<>();
|
||||
@Getter
|
||||
private final Set<CommandArgument<T, S, ?>> arguments = new HashSet<>();
|
||||
private final List<CommandArgument<T, S, ?>> arguments = new HashSet<>();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
|
@ -59,9 +60,10 @@ public class CommandNodeImpl<T, S extends CommandContext<T, ?>> implements Comma
|
|||
public <V> void addArgument(CommandArgument<T, S, V> argument) {
|
||||
if (arguments.stream()
|
||||
.anyMatch(arg -> arg.getId().equals(argument.getId()))
|
||||
) {
|
||||
throw new IllegalArgumentException("argument with same identifier is already added");
|
||||
}
|
||||
) throw new IllegalArgumentException("argument with same identifier is already added");
|
||||
if (arguments.getLast().getType().isGreedy())
|
||||
throw new IllegalStateException("can't append argument to a node, whose last argument type is greedy: "
|
||||
+ arguments.getLast().getType().getClass().getCanonicalName());
|
||||
|
||||
arguments.add(argument);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue