Fix one weird behaviour
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2023-01-15 20:45:29 +01:00
Ursprung 39e4553f6e
Commit d56150a8b1
2 geänderte Dateien mit 25 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,10 @@
package de.steamwar.command; package de.steamwar.command;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class PreviousArguments { public class PreviousArguments {
public final String[] userArgs; public final String[] userArgs;
@ -36,4 +40,23 @@ public class PreviousArguments {
public <T> T getMappedArg(int index) { public <T> T getMappedArg(int index) {
return (T) mappedArgs[mappedArgs.length - index - 1]; return (T) mappedArgs[mappedArgs.length - index - 1];
} }
public <T> Optional<T> getFirst(Class<T> clazz) {
for (Object o : mappedArgs) {
if (clazz.isInstance(o)) {
return Optional.of((T) o);
}
}
return Optional.empty();
}
public <T> List<T> getAll(Class<T> clazz) {
List<T> list = new ArrayList<>();
for (Object o : mappedArgs) {
if (clazz.isInstance(o)) {
list.add((T) o);
}
}
return list;
}
} }

Datei anzeigen

@ -23,7 +23,6 @@ import lombok.Getter;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Parameter; import java.lang.reflect.Parameter;
import java.util.*; import java.util.*;
@ -42,12 +41,12 @@ public class SWCommandUtils {
private SWTypeMapperCreator swTypeMapperCreator = (mapper, tabCompleter) -> new AbstractTypeMapper<Object, Object>() { private SWTypeMapperCreator swTypeMapperCreator = (mapper, tabCompleter) -> new AbstractTypeMapper<Object, Object>() {
@Override @Override
public Object map(Object sender, String[] previousArguments, String s) { public Object map(Object sender, PreviousArguments previousArguments, String s) {
return mapper.apply(s); return mapper.apply(s);
} }
@Override @Override
public Collection<String> tabCompletes(Object sender, String[] previousArguments, String s) { public Collection<String> tabCompletes(Object sender, PreviousArguments previousArguments, String s) {
return ((BiFunction<Object, Object, Collection<String>>) tabCompleter).apply(sender, s); return ((BiFunction<Object, Object, Collection<String>>) tabCompleter).apply(sender, s);
} }
}; };