From c33bc728ecbdc692bcfa6e058c42f17ce66e6bc6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 1 Feb 2022 11:16:33 +0100 Subject: [PATCH] Update SWCommandUtils and shorten the methods --- .../de/steamwar/command/SWCommandUtils.java | 49 +++++++------------ 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index 3e18811..3af5b37 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -162,41 +162,26 @@ public class SWCommandUtils { return createMapper(staticValue.value()); } if (staticValue.allowISE()) { - if (parameter.getType() == boolean.class && staticValue.value().length == 2) { + if ((parameter.getType() == boolean.class || 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; - } - }; + return createMapper(s -> { + int index = tabCompletes.indexOf(s); + return index == -1 ? null : index != 0; + }, (commandSender, s) -> tabCompletes); } - if (parameter.getType() == int.class && staticValue.value().length >= 2) { + if ((parameter.getType() == int.class || parameter.getType() == Integer.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; - } - }; + return createMapper(s -> { + int index = tabCompletes.indexOf(s); + return index == -1 ? null : index; + }, (commandSender, s) -> tabCompletes); + } + if ((parameter.getType() == long.class || parameter.getType() == Long.class) && staticValue.value().length >= 2) { + List tabCompletes = new ArrayList<>(Arrays.asList(staticValue.value())); + return createMapper(s -> { + long index = tabCompletes.indexOf(s); + return index == -1 ? null : index; + }, (commandSender, s) -> tabCompletes); } } } -- 2.39.5