|
2 | 2 |
|
3 | 3 | import org.bukkit.command.CommandSender; |
4 | 4 | import org.jetbrains.annotations.NotNull; |
| 5 | +import org.jetbrains.annotations.Nullable; |
5 | 6 |
|
6 | 7 | import java.util.List; |
| 8 | +import java.util.Set; |
| 9 | +import java.util.stream.Collectors; |
7 | 10 |
|
8 | | -/** |
9 | | - * Represents a command parameter with its properties. |
10 | | - */ |
11 | 11 | public interface Parameter { |
12 | 12 |
|
13 | | - /** |
14 | | - * The name of the parameter. |
15 | | - * |
16 | | - * @return The name of the parameter. |
17 | | - */ |
18 | 13 | @NotNull String name(); |
19 | 14 |
|
20 | | - /** |
21 | | - * The aliases of the parameter. |
22 | | - * |
23 | | - * @return The aliases of the parameter. |
24 | | - */ |
25 | 15 | default @NotNull List<String> aliases() { return List.of(); } |
26 | 16 |
|
27 | | - /** |
28 | | - * The permission required to use the parameter. |
29 | | - * |
30 | | - * @return The permission required to use the parameter. |
31 | | - */ |
32 | 17 | default String permission() { return null; } |
33 | 18 |
|
34 | | - /** |
35 | | - * Whether to stop processing sub-commands after this parameter is executed. |
36 | | - * |
37 | | - * @return true to stop processing sub-commands, false otherwise. |
38 | | - */ |
39 | 19 | default boolean stopSubCommands() { return false; } |
40 | 20 |
|
41 | | - /** |
42 | | - * The minimum number of arguments required for this parameter. |
43 | | - * |
44 | | - * @return The minimum number of arguments required for this parameter. |
45 | | - */ |
46 | 21 | default int minArgs() { return 0; } |
47 | 22 |
|
48 | | - /** |
49 | | - * The maximum number of arguments allowed for this parameter. |
50 | | - * |
51 | | - * @return The maximum number of arguments allowed for this parameter. |
52 | | - */ |
53 | 23 | default int maxArgs() { return Integer.MAX_VALUE; } |
54 | 24 |
|
55 | | - /** |
56 | | - * Called when the parameter is executed. |
57 | | - * @param sender The command sender |
58 | | - * @param fullArgs All args (same as Bukkit gives) |
59 | | - * @param parameterArgs The args already typed for THIS parameter (not including the "-name" token) |
60 | | - */ |
61 | | - default void execute(@NotNull CommandSender sender, @NotNull String[] fullArgs, @NotNull String[] parameterArgs) {}; |
62 | | - |
63 | | - /** |
64 | | - * Called for tab completion when the user is currently typing arguments for this parameter. |
65 | | - * @param sender The command sender |
66 | | - * @param fullArgs All args (same as Bukkit gives) |
67 | | - * @param parameterArgs The args already typed for THIS parameter (not including the "-name" token) |
68 | | - */ |
| 25 | + @Nullable |
| 26 | + default Set<String> whitelist() { return null; } |
| 27 | + |
| 28 | + @Nullable |
| 29 | + default String whitelistMessage() { return null; } |
| 30 | + |
| 31 | + default boolean isWhitelisted(@NotNull String value) { |
| 32 | + Set<String> whitelist = whitelist(); |
| 33 | + if (whitelist == null || whitelist.isEmpty()) return true; |
| 34 | + |
| 35 | + Set<String> lowercaseWhitelist = whitelist.stream() |
| 36 | + .map(String::toLowerCase) |
| 37 | + .collect(Collectors.toSet()); |
| 38 | + |
| 39 | + return lowercaseWhitelist.contains(value.toLowerCase()); |
| 40 | + } |
| 41 | + |
| 42 | + default void execute(@NotNull CommandSender sender, @NotNull String[] fullArgs, @NotNull String[] parameterArgs) {} |
| 43 | + |
69 | 44 | default @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String[] fullArgs, @NotNull String[] parameterArgs) { |
70 | 45 | return List.of(); |
71 | 46 | } |
|
0 commit comments