Add SWCommand.StaticValue.allowISE
Dieser Commit ist enthalten in:
Ursprung
0a130fd7fc
Commit
8c1e4281ca
@ -355,6 +355,16 @@ public abstract class SWCommand {
|
|||||||
@Target({ElementType.PARAMETER})
|
@Target({ElementType.PARAMETER})
|
||||||
protected @interface StaticValue {
|
protected @interface StaticValue {
|
||||||
String[] value();
|
String[] value();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the short form for 'allowImplicitSwitchExpressions'
|
||||||
|
* and can be set to true if you want to allow int as well as boolean as annotated parameter types.
|
||||||
|
* The value array needs to be at least 2 long for this flag to be considered.
|
||||||
|
* While using an int, the value will represent the index into the value array.
|
||||||
|
* While using a boolean, the value array must only be 2 long and the value will be {@code false}
|
||||||
|
* for the first index and {@code true} for the second index.
|
||||||
|
*/
|
||||||
|
boolean allowISE() default false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@ -157,9 +157,49 @@ public class SWCommandUtils {
|
|||||||
name = mapper.value();
|
name = mapper.value();
|
||||||
} else {
|
} else {
|
||||||
SWCommand.StaticValue staticValue = parameter.getAnnotation(SWCommand.StaticValue.class);
|
SWCommand.StaticValue staticValue = parameter.getAnnotation(SWCommand.StaticValue.class);
|
||||||
if (staticValue != null && parameter.getType() == String.class) {
|
if (staticValue != null) {
|
||||||
|
if (parameter.getType() == String.class) {
|
||||||
return createMapper(staticValue.value());
|
return createMapper(staticValue.value());
|
||||||
}
|
}
|
||||||
|
if (staticValue.allowISE()) {
|
||||||
|
if (parameter.getType() == boolean.class && staticValue.value().length == 2) {
|
||||||
|
List<String> tabCompletes = new ArrayList<>(Arrays.asList(staticValue.value()));
|
||||||
|
return new TypeMapper<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
|
int index = tabCompletes.indexOf(s);
|
||||||
|
if (index == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return index != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> tabCompletes(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
|
return tabCompletes;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (parameter.getType() == int.class && staticValue.value().length >= 2) {
|
||||||
|
List<String> tabCompletes = new ArrayList<>(Arrays.asList(staticValue.value()));
|
||||||
|
return new TypeMapper<Integer>() {
|
||||||
|
@Override
|
||||||
|
public Integer map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
|
int index = tabCompletes.indexOf(s);
|
||||||
|
if (index == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> tabCompletes(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
|
return tabCompletes;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TypeMapper<?> typeMapper = localTypeMapper.getOrDefault(name, MAPPER_FUNCTIONS.getOrDefault(name, null));
|
TypeMapper<?> typeMapper = localTypeMapper.getOrDefault(name, MAPPER_FUNCTIONS.getOrDefault(name, null));
|
||||||
if (typeMapper == null) {
|
if (typeMapper == null) {
|
||||||
|
@ -119,7 +119,7 @@ public class SchematicSelector {
|
|||||||
inv.setItem(50, Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent));
|
inv.setItem(50, Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent));
|
||||||
}
|
}
|
||||||
inv.setItem(51, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter());
|
inv.setItem(51, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter());
|
||||||
inv.setItem(47, sorting.mat, Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING", player), List.of(
|
inv.setItem(47, sorting.mat, Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING", player), Arrays.asList(
|
||||||
Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_CURRENT", player, sorting.parseName(player)),
|
Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_CURRENT", player, sorting.parseName(player)),
|
||||||
Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_DIRECTION", player, Core.MESSAGE.parse(invertSorting?"SCHEM_SELECTOR_SORTING_DSC":"SCHEM_SELECTOR_SORTING_ASC", player))
|
Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_DIRECTION", player, Core.MESSAGE.parse(invertSorting?"SCHEM_SELECTOR_SORTING_DSC":"SCHEM_SELECTOR_SORTING_ASC", player))
|
||||||
), invertSorting, click -> {
|
), invertSorting, click -> {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren