Dieser Commit ist enthalten in:
Ursprung
200a1a4718
Commit
58cc8eb2c6
@ -325,4 +325,10 @@ public abstract class SWCommand {
|
|||||||
|
|
||||||
boolean local() default false;
|
boolean local() default false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.PARAMETER})
|
||||||
|
protected @interface StaticValue {
|
||||||
|
String value();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,10 @@ public class SWCommandUtils {
|
|||||||
GUARD_FUNCTIONS.putIfAbsent(name, guardChecker);
|
GUARD_FUNCTIONS.putIfAbsent(name, guardChecker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TypeMapper<String> createMapper(String value) {
|
||||||
|
return createMapper((s) -> value.equals(s) ? value : null, s -> Collections.singletonList(value));
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> TypeMapper<T> createMapper(Function<String, T> mapper, Function<String, List<String>> tabCompleter) {
|
public static <T> TypeMapper<T> createMapper(Function<String, T> mapper, Function<String, List<String>> tabCompleter) {
|
||||||
return createMapper(mapper, (commandSender, s) -> tabCompleter.apply(s));
|
return createMapper(mapper, (commandSender, s) -> tabCompleter.apply(s));
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,13 @@ class SubCommand {
|
|||||||
String name = clazz.getTypeName();
|
String name = clazz.getTypeName();
|
||||||
if (mapper != null) {
|
if (mapper != null) {
|
||||||
name = mapper.value();
|
name = mapper.value();
|
||||||
|
} else {
|
||||||
|
SWCommand.StaticValue staticValue = parameter.getAnnotation(SWCommand.StaticValue.class);
|
||||||
|
if (parameter.getType() == String.class) {
|
||||||
|
arguments[i - 1] = SWCommandUtils.createMapper(staticValue.value());
|
||||||
|
guards[i - 1] = getGuardChecker(parameter, localGuardChecker);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
arguments[i - 1] = localTypeMapper.containsKey(name)
|
arguments[i - 1] = localTypeMapper.containsKey(name)
|
||||||
? localTypeMapper.get(name)
|
? localTypeMapper.get(name)
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren