Dieser Commit ist enthalten in:
Ursprung
39e4553f6e
Commit
d56150a8b1
@ -19,6 +19,10 @@
|
||||
|
||||
package de.steamwar.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PreviousArguments {
|
||||
|
||||
public final String[] userArgs;
|
||||
@ -36,4 +40,23 @@ public class PreviousArguments {
|
||||
public <T> T getMappedArg(int index) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.*;
|
||||
@ -42,12 +41,12 @@ public class SWCommandUtils {
|
||||
|
||||
private SWTypeMapperCreator swTypeMapperCreator = (mapper, tabCompleter) -> new AbstractTypeMapper<Object, Object>() {
|
||||
@Override
|
||||
public Object map(Object sender, String[] previousArguments, String s) {
|
||||
public Object map(Object sender, PreviousArguments previousArguments, String s) {
|
||||
return mapper.apply(s);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
};
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren