Add LocationArgument to cloud-bukkit (#63)

*  Add LocationArgument to cloud-bukkit

* 🎨 Use the Bukkit CommandSender from the command context in LocationArgument

* 🐛 Fixed quoted parsing in StringArgument

* 📚 Fix code style

Co-authored-by: jmp <jasonpenilla2@me.com>
This commit is contained in:
Alexander Söderberg 2020-10-18 00:22:48 +02:00
parent 1249b74e83
commit 79aefb05b5
14 changed files with 653 additions and 14 deletions

View file

@ -464,30 +464,28 @@ public final class CommandTree<C> {
commandContext.store("__parsing_argument__", i + 2);
}
}
}
// END: Compound arguments
// START: Flags
if (child.getValue() instanceof FlagArgument) {
} else if (child.getValue() instanceof FlagArgument) {
/* Remove all but last */
while (commandQueue.size() > 1) {
commandContext.store(FlagArgument.FLAG_META, commandQueue.remove());
}
}
// END: Flags
// START: Array arguments
if (child.getValue() != null && GenericTypeReflector.erase(child.getValue().getValueType().getType()).isArray()) {
} else if (child.getValue() != null
&& GenericTypeReflector.erase(child.getValue().getValueType().getType()).isArray()) {
while (commandQueue.size() > 1) {
commandQueue.remove();
}
} else if (child.getValue() != null) {
for (int i = 0; i < child.getValue().getParser().getRequestedArgumentCount() - 1 && commandQueue.size()> 1; i++) {
commandContext.store(
String.format("%s_%d", child.getValue().getName(), i),
commandQueue.remove()
);
}
}
// END: Array arguments
if (child.getValue() != null) {
if (commandQueue.isEmpty()) {
return Collections.emptyList();
// return child.getValue().getParser().suggestions(commandContext, "");
} else if (child.isLeaf() && commandQueue.size() < 2) {
return child.getValue().getSuggestionsProvider().apply(commandContext, commandQueue.peek());
} else if (child.isLeaf()) {

View file

@ -39,6 +39,11 @@ import java.util.Queue;
@FunctionalInterface
public interface ArgumentParser<C, T> {
/**
* Default amount of arguments that the parser expects to consume
*/
int DEFAULT_ARGUMENT_COUNT = 1;
/**
* Parse command input into a command result
*
@ -75,4 +80,14 @@ public interface ArgumentParser<C, T> {
return false;
}
/**
* Get the amount of arguments that this parsers seeks to
* consume
*
* @return The number of arguments tha the parser expects
*/
default int getRequestedArgumentCount() {
return DEFAULT_ARGUMENT_COUNT;
}
}

View file

@ -190,7 +190,18 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
this.max = max;
}
static @NonNull List<@NonNull String> getSuggestions(final long min, final long max, final @NonNull String input) {
/**
* Get integer suggestions. This supports both positive and negative numbers
*
* @param min Minimum value
* @param max Maximum value
* @param input Input
* @return List of suggestions
*/
public static @NonNull List<@NonNull String> getSuggestions(
final long min,
final long max,
final @NonNull String input) {
final Set<Long> numbers = new TreeSet<>();
try {