.
This commit is contained in:
parent
678762f797
commit
fc431bf8df
17 changed files with 160 additions and 114 deletions
17
src/main/java/de/kencommand/api/KenCommandApi.java
Normal file
17
src/main/java/de/kencommand/api/KenCommandApi.java
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package de.kencommand.api;
|
||||
|
||||
import de.kencommand.api.processing.CommandExecutor;
|
||||
import de.kencommand.api.processing.ParsedArgument;
|
||||
import de.kencommand.api.structure.node.CommandNode;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public interface KenCommandApi<T> {
|
||||
|
||||
void invoke(CommandNode<T> node, T sender, String[] args);
|
||||
|
||||
CommandExecutor<T> processLiterals(CommandNode<T> node, Iterator<String> argsIterator);
|
||||
|
||||
Map<String, ParsedArgument<T, ?>> parseArguments(CommandNode<T> node, Iterator<String> argsIterator);
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package de.kencommand.api.parsing;
|
||||
|
||||
import de.kencommand.api.processing.CommandContext;
|
||||
import de.kencommand.api.structure.argument.CommandArgument;
|
||||
|
||||
public interface ParsedArgument<T, S extends CommandContext<T>, V> {
|
||||
|
||||
V getValue();
|
||||
|
||||
CommandArgument<T, S, V> getArgument();
|
||||
}
|
||||
|
|
@ -1,34 +1,17 @@
|
|||
package de.kencommand.api.processing;
|
||||
|
||||
import de.kencommand.api.parsing.ParsedArgument;
|
||||
import de.kentoj.scrow.bukkit.command.exception.CommandInvocationException;
|
||||
import de.kentoj.scrow.bukkit.command.literal.CommandArgument;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface CommandContext<T> {
|
||||
|
||||
T getSender();
|
||||
|
||||
/**
|
||||
* @return Object that is parsed from the raw argument
|
||||
* @throws CommandInvocationException if no value given and no default value supplied
|
||||
* @throws RuntimeException if no value given and no default value supplied
|
||||
*/
|
||||
<T> ParsedArgument<T> getArgData(String name);
|
||||
<V> ParsedArgument<T, V> getParsedArgument(String name);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <T> T getArgData(CommandArgument<T> arg) {
|
||||
return (T) getArgData(arg.getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <T> T getArg(String name) {
|
||||
return (T) getArgData(name).getValue();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <T> T getArg(CommandArgument<T> arg) {
|
||||
return (T) getArgData(arg.getName()).getValue();
|
||||
default <V> V getArg(String name) {
|
||||
return (V) getParsedArgument(name).getValue();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package de.kencommand.api.processing;
|
||||
|
||||
public interface CommandExecutor<S> {
|
||||
public interface CommandExecutor<T> {
|
||||
|
||||
void execute(S ctx);
|
||||
void execute(CommandContext<T> ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package de.kencommand.api.processing;
|
||||
|
||||
import de.kencommand.api.structure.argument.CommandArgument;
|
||||
|
||||
public interface ParsedArgument<T, V> {
|
||||
|
||||
V getValue();
|
||||
|
||||
CommandArgument<T, V> getArgument();
|
||||
}
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
package de.kencommand.api.structure.argument;
|
||||
|
||||
import de.kencommand.api.processing.CommandContext;
|
||||
|
||||
public interface ArgumentType<V> {
|
||||
|
||||
V parseInput(String string);
|
||||
|
||||
SuggestionProvider<Object, CommandContext<Object>> defaultSuggestionProvider();
|
||||
SuggestionProvider<?> defaultSuggestionProvider();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import de.kencommand.api.processing.CommandContext;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface CommandArgument<T, S extends CommandContext<T>, V> {
|
||||
public interface CommandArgument<T, V> {
|
||||
|
||||
String getId();
|
||||
|
||||
|
|
@ -14,10 +14,10 @@ public interface CommandArgument<T, S extends CommandContext<T>, V> {
|
|||
|
||||
@Nullable T getDefaultValue();
|
||||
|
||||
void setSuggestionProvider(@Nullable SuggestionProvider<T, S> suggestionProvider);
|
||||
void setSuggestionProvider(@Nullable SuggestionProvider<T> suggestionProvider);
|
||||
|
||||
/**
|
||||
* @return the explicitly set SuggestionProvider or the default suggestions for the type if unset/null
|
||||
*/
|
||||
@NotNull SuggestionProvider<T, S> getSuggestionProvider();
|
||||
@NotNull SuggestionProvider<T> getSuggestionProvider();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import de.kencommand.api.processing.CommandContext;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
public interface SuggestionProvider<T, S extends CommandContext<T>> {
|
||||
public interface SuggestionProvider<T> {
|
||||
|
||||
Set<String> suggest(S context);
|
||||
Set<String> suggest(CommandContext<T> context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package de.kencommand.api.structure.node;
|
||||
|
||||
import de.kencommand.api.processing.CommandContext;
|
||||
import de.kencommand.api.structure.argument.CommandArgument;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface ArgumentNode<T, S extends CommandContext<T>> {
|
||||
public interface ArgumentNode<T> {
|
||||
|
||||
<V> void addArgument(CommandArgument<T, S, V> argument);
|
||||
<V> void addArgument(CommandArgument<T, V> argument);
|
||||
|
||||
Set<CommandArgument<T, S, ?>> getArguments();
|
||||
Set<CommandArgument<T, ?>> getArguments();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
package de.kencommand.api.structure.node;
|
||||
|
||||
import de.kencommand.api.processing.CommandContext;
|
||||
import de.kencommand.api.processing.CommandExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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>, ArgumentNode<T, S> {
|
||||
public interface CommandNode<T> extends ArgumentNode<T>, LiteralNode<T> {
|
||||
|
||||
@NotNull String[] getNames();
|
||||
|
||||
void setExecutor(@Nullable CommandExecutor<? extends S> executor);
|
||||
void setExecutor(@Nullable CommandExecutor<T> executor);
|
||||
|
||||
@Nullable CommandExecutor<? extends S> getExecutor();
|
||||
@Nullable CommandExecutor<T> getExecutor();
|
||||
|
||||
void setDescription(@Nullable String description);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
package de.kencommand.api.structure.node;
|
||||
|
||||
import de.kencommand.api.processing.CommandContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface LiteralNode<T, S extends CommandContext<T>> {
|
||||
public interface LiteralNode<T> {
|
||||
|
||||
void addLiteral(@NotNull CommandNode<? extends T, ? extends S> commandNode);
|
||||
void addLiteral(@NotNull CommandNode<T> commandNode);
|
||||
|
||||
CommandNode<T, S> getLiteral(@NotNull String name);
|
||||
@Nullable CommandNode<T> getLiteral(@NotNull String name);
|
||||
|
||||
@NotNull Set<CommandNode<? extends T, ? extends S>> getLiterals();
|
||||
@NotNull Set<CommandNode<T>> getLiterals();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue