Add SWCommand.Register.Registeres #104
@ -50,10 +50,7 @@ public class SWCommandUtils {
|
||||
|
||||
static final BiFunction<Class<Enum<?>>, String, Enum<?>> ENUM_MAPPER = (enumClass, s) -> {
|
||||
Enum<?>[] enums = enumClass.getEnumConstants();
|
||||
for (Enum<?> e : enums) {
|
||||
if (e.name().equalsIgnoreCase(s)) return e;
|
||||
}
|
||||
return null;
|
||||
return Arrays.stream(enums).filter(e -> e.name().equalsIgnoreCase(s)).findFirst().orElse(null);
|
||||
};
|
||||
|
||||
static {
|
||||
@ -105,9 +102,7 @@ public class SWCommandUtils {
|
||||
Object[] arguments = new Object[parameters.length + 1];
|
||||
int index = 0;
|
||||
while (index < subCommand.length) {
|
||||
if (!args[index].equalsIgnoreCase(subCommand[index])) {
|
||||
throw new CommandParseException();
|
||||
}
|
||||
if (!args[index].equalsIgnoreCase(subCommand[index])) throw new CommandParseException();
|
||||
index++;
|
||||
}
|
||||
|
||||
@ -116,17 +111,13 @@ public class SWCommandUtils {
|
||||
length = args.length - parameters.length - subCommand.length + 1;
|
||||
arguments[arguments.length - 1] = Array.newInstance(varArgType, length);
|
||||
|
||||
if (index > args.length - 1) {
|
||||
return arguments;
|
||||
}
|
||||
if (index > args.length - 1) return arguments;
|
||||
}
|
||||
|
||||
for (int i = 0; i < parameters.length - (varArgType != null ? 1 : 0); i++) {
|
||||
arguments[i + 1] = parameters[i].map(commandSender, Arrays.copyOf(args, index), args[index]);
|
||||
index++;
|
||||
if (arguments[i + 1] == null) {
|
||||
throw new CommandParseException();
|
||||
}
|
||||
if (arguments[i + 1] == null) throw new CommandParseException();
|
||||
}
|
||||
|
||||
if (varArgType != null) {
|
||||
@ -134,9 +125,7 @@ public class SWCommandUtils {
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
Object value = parameters[parameters.length - 1].map(commandSender, Arrays.copyOf(args, index), args[index]);
|
||||
if (value == null) {
|
||||
throw new CommandParseException();
|
||||
}
|
||||
if (value == null) throw new CommandParseException();
|
||||
Array.set(varArgument, i, value);
|
||||
index++;
|
||||
}
|
||||
@ -149,8 +138,7 @@ public class SWCommandUtils {
|
||||
}
|
||||
|
||||
public static void addMapper(String name, TypeMapper<?> mapper) {
|
||||
if (MAPPER_FUNCTIONS.containsKey(name)) return;
|
||||
MAPPER_FUNCTIONS.put(name, mapper);
|
||||
MAPPER_FUNCTIONS.putIfAbsent(name, mapper);
|
||||
}
|
||||
|
||||
public static <T> TypeMapper<T> createMapper(Function<String, T> mapper, Function<String, List<String>> tabCompleter) {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren