From ee85ec6696e2c14546858e98bd4117d43f530d0f Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 29 Dec 2020 16:42:47 +0100 Subject: [PATCH] Simplify Argument.tabCompleteSupplier --- SpigotCore_Main/src/de/steamwar/command/Argument.java | 4 +--- SpigotCore_Main/src/de/steamwar/command/SWCommandBundle.java | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/Argument.java b/SpigotCore_Main/src/de/steamwar/command/Argument.java index 4f80c92..652c684 100644 --- a/SpigotCore_Main/src/de/steamwar/command/Argument.java +++ b/SpigotCore_Main/src/de/steamwar/command/Argument.java @@ -117,9 +117,7 @@ public class Argument { // Check number constraints if needed if (argumentType.number && !constraint.test(argumentMapped)) return Optional.empty(); } - List strings = Arrays.stream(tabCompletes.apply(s)).filter(t -> t.startsWith(s)).collect(Collectors.toList()); - if (strings.isEmpty()) strings.add(s); - return Optional.of(strings); + return Optional.of(Arrays.stream(tabCompletes.apply(s)).filter(t -> t.startsWith(s)).collect(Collectors.toList())); } catch (NumberFormatException e) { return Optional.empty(); } catch (Exception e) { diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandBundle.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandBundle.java index c5dcde0..24f24c7 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandBundle.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandBundle.java @@ -59,8 +59,7 @@ public class SWCommandBundle { public List tabComplete(String[] args) { List strings = new ArrayList<>(); for (SWCommand swCommand : swCommandList) { - Optional> tabCompletes = swCommand.tabComplete(args); - if (tabCompletes.isPresent()) strings.addAll(tabCompletes.get()); + swCommand.tabComplete(args).ifPresent(strings::addAll); } return strings; }