|
31 | 31 | import java.lang.reflect.InvocationTargetException; |
32 | 32 | import java.lang.reflect.Method; |
33 | 33 | import java.util.*; |
34 | | -import java.util.function.Consumer; |
| 34 | +import java.util.function.Function; |
35 | 35 | import java.util.logging.Level; |
36 | 36 | import java.util.stream.Collectors; |
37 | 37 | import java.util.stream.Stream; |
@@ -77,10 +77,15 @@ public class CommandFramework implements CommandExecutor, TabCompleter { |
77 | 77 | @NotNull |
78 | 78 | private final Map<CommandSender, Map<Command, Long>> cooldowns = new HashMap<>(); |
79 | 79 | /** |
80 | | - * Consumer to accept if there is no matched commands related framework. |
| 80 | + * Function to apply if there is no matched commands related framework. |
| 81 | + * |
| 82 | + * <pre> |
| 83 | + * // To disable sending usage to command sender return true |
| 84 | + * CommandFramework#setMatchFunction(arguments -> true); |
| 85 | + * </pre> |
81 | 86 | */ |
82 | 87 | @Nullable |
83 | | - private Consumer<CommandArguments> anyMatchConsumer; |
| 88 | + private Function<CommandArguments, Boolean> matchFunction = (arguments) -> false; |
84 | 89 | /** |
85 | 90 | * Default command map of Bukkit. |
86 | 91 | */ |
@@ -112,12 +117,12 @@ public CommandFramework(@NotNull Plugin plugin) { |
112 | 117 | } |
113 | 118 |
|
114 | 119 | /** |
115 | | - * Consumer to accept if there is no matched commands related framework. |
| 120 | + * Function to apply if there is no matched commands related framework. |
116 | 121 | * |
117 | | - * @param anyMatchConsumer to be accepted if there is no matched commands |
| 122 | + * @param matchFunction to be applied if there is no matched commands |
118 | 123 | */ |
119 | | - public void setAnyMatch(@NotNull Consumer<CommandArguments> anyMatchConsumer) { |
120 | | - this.anyMatchConsumer = anyMatchConsumer; |
| 124 | + public void setMatchFunction(@NotNull Function<CommandArguments, Boolean> matchFunction) { |
| 125 | + this.matchFunction = matchFunction; |
121 | 126 | } |
122 | 127 |
|
123 | 128 | /** |
@@ -320,7 +325,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.comm |
320 | 325 | final Map.Entry<Command, Map.Entry<Method, Object>> entry = this.getAssociatedCommand(cmd.getName(), args); |
321 | 326 |
|
322 | 327 | if (entry == null) { |
323 | | - if (anyMatchConsumer != null) anyMatchConsumer.accept(new CommandArguments(sender, cmd, label, args)); |
| 328 | + if (matchFunction != null) return matchFunction.apply(new CommandArguments(sender, cmd, label, args)); |
324 | 329 |
|
325 | 330 | return true; |
326 | 331 | } |
|
0 commit comments