Tweaks
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package io.dico.dicore.command.parameter.type;
|
||||
|
||||
import io.dico.dicore.command.CommandException;
|
||||
import io.dico.dicore.command.parameter.ArgumentBuffer;
|
||||
import io.dico.dicore.command.parameter.Parameter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EnumParameterType<E extends Enum> extends SimpleParameterType<E, Void> {
|
||||
private final E[] universe;
|
||||
|
||||
public EnumParameterType(Class<E> returnType) {
|
||||
super(returnType);
|
||||
universe = returnType.getEnumConstants();
|
||||
if (universe == null) {
|
||||
throw new IllegalArgumentException("returnType must be an enum");
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected E parse(Parameter<E, Void> parameter, CommandSender sender, String input) throws CommandException {
|
||||
for (E constant : universe) {
|
||||
if (constant.name().equalsIgnoreCase(input)) {
|
||||
return constant;
|
||||
}
|
||||
}
|
||||
|
||||
throw CommandException.invalidArgument(parameter.getName(), "the enum value does not exist");
|
||||
}
|
||||
|
||||
@Override public List<String> complete(Parameter<E, Void> parameter, CommandSender sender, Location location, ArgumentBuffer buffer) {
|
||||
String input = buffer.next().toUpperCase();
|
||||
List<String> result = new ArrayList<>();
|
||||
for (E constant : universe) {
|
||||
if (constant.name().toUpperCase().startsWith(input.toUpperCase())) {
|
||||
result.add(constant.name().toLowerCase());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,11 @@ public class MapBasedParameterTypeSelector implements IParameterTypeSelector {
|
||||
if (useDefault && out == null) {
|
||||
out = defaultSelector.selectExact(key);
|
||||
}
|
||||
if (out == null && key.getReturnType().isEnum()) {
|
||||
//noinspection unchecked
|
||||
out = new EnumParameterType(key.getReturnType());
|
||||
addType(false, out);
|
||||
}
|
||||
return cast(out);
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ public class ReflectiveRegistration {
|
||||
|
||||
String[] parameterNames = lookupParameterNames(method, parameters, start);
|
||||
for (int i = start, n = parameters.length; i < n; i++) {
|
||||
if (parameters[i].getType().getName().equals("kotlin.coroutines.experimental.Continuation")) {
|
||||
if (parameters[i].getType().getName().equals("kotlin.coroutines.Continuation")) {
|
||||
List<String> temp = new ArrayList<>(Arrays.asList(parameterNames));
|
||||
temp.remove(i - start);
|
||||
parameterNames = temp.toArray(new String[0]);
|
||||
|
||||
Reference in New Issue
Block a user