diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index a87dfd7..3dd6f8f 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -355,6 +355,16 @@ public abstract class SWCommand { @Target({ElementType.PARAMETER}) protected @interface StaticValue { 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) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index 265f874..3e18811 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -157,8 +157,48 @@ public class SWCommandUtils { name = mapper.value(); } else { SWCommand.StaticValue staticValue = parameter.getAnnotation(SWCommand.StaticValue.class); - if (staticValue != null && parameter.getType() == String.class) { - return createMapper(staticValue.value()); + if (staticValue != null) { + if (parameter.getType() == String.class) { + return createMapper(staticValue.value()); + } + if (staticValue.allowISE()) { + if (parameter.getType() == boolean.class && staticValue.value().length == 2) { + List tabCompletes = new ArrayList<>(Arrays.asList(staticValue.value())); + return new TypeMapper() { + @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 tabCompletes(CommandSender commandSender, String[] previousArguments, String s) { + return tabCompletes; + } + }; + } + if (parameter.getType() == int.class && staticValue.value().length >= 2) { + List tabCompletes = new ArrayList<>(Arrays.asList(staticValue.value())); + return new TypeMapper() { + @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 tabCompletes(CommandSender commandSender, String[] previousArguments, String s) { + return tabCompletes; + } + }; + } + } } } TypeMapper typeMapper = localTypeMapper.getOrDefault(name, MAPPER_FUNCTIONS.getOrDefault(name, null)); diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index ed4db5c..dc34232 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -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(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_DIRECTION", player, Core.MESSAGE.parse(invertSorting?"SCHEM_SELECTOR_SORTING_DSC":"SCHEM_SELECTOR_SORTING_ASC", player)) ), invertSorting, click -> {