diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 60a2c6b..e2a8f01 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -328,4 +328,10 @@ public abstract class SWCommand { boolean local() default false; } + + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.PARAMETER}) + protected @interface StaticValue { + String value(); + } } diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index 1d7110f..98ddcf6 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -163,6 +163,10 @@ public class SWCommandUtils { GUARD_FUNCTIONS.putIfAbsent(name, guardChecker); } + public static TypeMapper createMapper(String value) { + return createMapper((s) -> value.equals(s) ? value : null, s -> Collections.singletonList(value)); + } + public static TypeMapper createMapper(Function mapper, Function> tabCompleter) { return createMapper(mapper, (commandSender, s) -> tabCompleter.apply(s)); } diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index bd6c743..0c1adb0 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -84,6 +84,13 @@ class SubCommand { String name = clazz.getTypeName(); if (mapper != null) { 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) ? localTypeMapper.get(name)