From 57ab89e058b2feda1445981c3b48dbe356c9294f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 30 May 2022 14:59:00 +0200 Subject: [PATCH] Fix SWCommandUtils --- src/de/steamwar/command/SWCommandUtils.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/command/SWCommandUtils.java b/src/de/steamwar/command/SWCommandUtils.java index 331b9f9..6e486b1 100644 --- a/src/de/steamwar/command/SWCommandUtils.java +++ b/src/de/steamwar/command/SWCommandUtils.java @@ -38,11 +38,19 @@ public class SWCommandUtils { @Getter private final Map> GUARD_FUNCTIONS = new HashMap<>(); - private SWTypeMapperCreator swTypeMapperCreator; + private SWTypeMapperCreator swTypeMapperCreator = (mapper, tabCompleter) -> new AbstractTypeMapper() { + @Override + public Object map(Object sender, String[] previousArguments, String s) { + return mapper.apply(s); + } - public static , K, V> void init(SWTypeMapperCreator swTypeMapperCreator) { - SWCommandUtils.swTypeMapperCreator = swTypeMapperCreator; + @Override + public Collection tabCompletes(Object sender, String[] previousArguments, String s) { + return tabCompleter.apply(sender, s); + } + }; + static { addMapper(boolean.class, Boolean.class, createMapper(s -> { if (s.equalsIgnoreCase("true")) return true; if (s.equalsIgnoreCase("false")) return false; @@ -55,6 +63,10 @@ public class SWCommandUtils { MAPPER_FUNCTIONS.put(String.class.getTypeName(), createMapper(s -> s, Collections::singletonList)); } + public static , K, V> void init(SWTypeMapperCreator swTypeMapperCreator) { + SWCommandUtils.swTypeMapperCreator = swTypeMapperCreator; + } + private static void addMapper(Class clazz, Class alternativeClazz, AbstractTypeMapper mapper) { MAPPER_FUNCTIONS.put(clazz.getTypeName(), mapper); MAPPER_FUNCTIONS.put(alternativeClazz.getTypeName(), mapper);