diff --git a/SpigotCore_Main/src/de/steamwar/command/Argument.java b/SpigotCore_Main/src/de/steamwar/command/Argument.java index 591cc38..b7ec53b 100644 --- a/SpigotCore_Main/src/de/steamwar/command/Argument.java +++ b/SpigotCore_Main/src/de/steamwar/command/Argument.java @@ -71,8 +71,12 @@ public class Argument { public Optional> tabCompleteSupplier(String s) { try { - // Check if mappable - if (!s.isEmpty()) argumentType.mapper.apply(s); + if (!s.isEmpty()) { + // Check if mappable + T argumentMapped = argumentType.mapper.apply(s); + // Check number constraints if needed + if (argumentType.number && !constraint.test(argumentMapped)) return Optional.empty(); + } List strings = Arrays.stream(tabCompletes).filter(t -> t.startsWith(s)).collect(Collectors.toList()); if (strings.isEmpty()) strings.add(s); return Optional.of(strings); diff --git a/SpigotCore_Main/src/de/steamwar/command/ArgumentType.java b/SpigotCore_Main/src/de/steamwar/command/ArgumentType.java index f24cc1c..80f5531 100644 --- a/SpigotCore_Main/src/de/steamwar/command/ArgumentType.java +++ b/SpigotCore_Main/src/de/steamwar/command/ArgumentType.java @@ -25,16 +25,18 @@ import java.util.function.Function; public class ArgumentType { - public static final ArgumentType INT = new ArgumentType<>(Integer::parseInt); - public static final ArgumentType LONG = new ArgumentType<>(Long::parseLong); - public static final ArgumentType FLOAT = new ArgumentType<>(Float::parseFloat); - public static final ArgumentType DOUBLE = new ArgumentType<>(Double::parseDouble); - public static final ArgumentType STRING = new ArgumentType<>((s) -> s); + public static final ArgumentType INT = new ArgumentType<>(Integer::parseInt, true); + public static final ArgumentType LONG = new ArgumentType<>(Long::parseLong, true); + public static final ArgumentType FLOAT = new ArgumentType<>(Float::parseFloat, true); + public static final ArgumentType DOUBLE = new ArgumentType<>(Double::parseDouble, true); + public static final ArgumentType STRING = new ArgumentType<>((s) -> s, false); Function mapper; + boolean number; - private ArgumentType(Function mapper) { + private ArgumentType(Function mapper, boolean number) { this.mapper = mapper; + this.number = number; } } diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandBundle.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandBundle.java index e3954ca..44f9bdf 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandBundle.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandBundle.java @@ -37,7 +37,7 @@ public class SWCommandBundle { return this; } - public SWCommandBundle add(SWCommandBundle swCommandBundle) { + public SWCommandBundle addAll(SWCommandBundle swCommandBundle) { if (swCommandBundle == null) return this; swCommandList.addAll(swCommandBundle.swCommandList); return this; @@ -51,4 +51,13 @@ public class SWCommandBundle { return Optional.empty(); } + 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()); + } + return strings; + } + }