.
This commit is contained in:
parent
76784dba7e
commit
f9c60fdae0
4 changed files with 38 additions and 8 deletions
|
|
@ -1,10 +1,11 @@
|
|||
package de.kencommand.api.parsing;
|
||||
|
||||
import de.kentoj.scrow.bukkit.command.literal.CommandArgument;
|
||||
import de.kencommand.api.processing.CommandContext;
|
||||
import de.kencommand.api.structure.argument.CommandArgument;
|
||||
|
||||
public interface ParsedArgument<T> {
|
||||
public interface ParsedArgument<T, S extends CommandContext<T>, V> {
|
||||
|
||||
T getValue();
|
||||
V getValue();
|
||||
|
||||
CommandArgument<T> getArgument();
|
||||
CommandArgument<T, S, V> getArgument();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@ public interface ArgumentNode<T, S extends CommandContext<T>> {
|
|||
|
||||
<V> void addArgument(CommandArgument<T, S, V> argument);
|
||||
|
||||
Set<CommandArgument<T, S, Object>> getArguments();
|
||||
Set<CommandArgument<T, S, ?>> getArguments();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
* @param <T> type of command sender
|
||||
* @param <S> type of command context
|
||||
*/
|
||||
public interface CommandNode<T, S extends CommandContext<T>> extends LiteralNode<T, S> {
|
||||
public interface CommandNode<T, S extends CommandContext<T>> extends LiteralNode<T, S>, ArgumentNode<T, S> {
|
||||
|
||||
@NotNull String[] getNames();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,36 @@
|
|||
package de.kencommand.impl.structure.node;
|
||||
|
||||
import de.kencommand.api.processing.CommandContext;
|
||||
import de.kencommand.api.processing.CommandExecutor;
|
||||
import de.kencommand.api.structure.argument.CommandArgument;
|
||||
import de.kencommand.api.structure.node.CommandNode;
|
||||
import de.kencommand.api.structure.node.LiteralNode;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class LiteralNodeImpl<T, S extends CommandContext<T>> implements LiteralNode<T, S> {
|
||||
@RequiredArgsConstructor
|
||||
public class CommandNodeImpl<T, S extends CommandContext<T>> implements CommandNode<T, S> {
|
||||
|
||||
@Getter
|
||||
private final String[] names;
|
||||
|
||||
@Getter
|
||||
private final Set<CommandNode<? extends T, ? extends S>> literals = new HashSet<>();
|
||||
@Getter
|
||||
private final Set<CommandArgument<T, S, ?>> arguments = new HashSet<>();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private @Nullable CommandExecutor<? extends S> executor;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String description;
|
||||
|
||||
@Override
|
||||
public void addLiteral(@NotNull CommandNode<? extends T, ? extends S> commandNode) {
|
||||
|
|
@ -31,4 +49,15 @@ public class LiteralNodeImpl<T, S extends CommandContext<T>> implements LiteralN
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
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");
|
||||
}
|
||||
|
||||
arguments.add(argument);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue