|
1 | 1 | package dev.manere.commands; |
2 | 2 |
|
3 | | -import com.google.common.collect.ImmutableList; |
4 | | -import dev.manere.commands.api.APIHolder; |
5 | | -import dev.manere.commands.api.CommandManager; |
6 | | -import dev.manere.commands.api.CommandsAPI; |
7 | 3 | import dev.manere.commands.argument.CommandArgument; |
8 | | -import dev.manere.commands.ctx.CommandContext; |
9 | | -import dev.manere.commands.handler.CommandRequirement; |
10 | | -import dev.manere.commands.handler.ExecutionHandler; |
11 | | -import dev.manere.commands.handler.RequirementResult; |
12 | | -import dev.manere.commands.info.CommandInfo; |
13 | | -import org.bukkit.plugin.java.JavaPlugin; |
| 4 | +import org.bukkit.command.CommandSender; |
14 | 5 | import org.jetbrains.annotations.NotNull; |
15 | | -import org.jetbrains.annotations.Nullable; |
16 | 6 | import org.jetbrains.annotations.Unmodifiable; |
17 | 7 |
|
18 | | -import java.lang.reflect.InvocationTargetException; |
| 8 | +import java.util.Collection; |
19 | 9 | import java.util.List; |
| 10 | +import java.util.Optional; |
20 | 11 |
|
21 | | -/** |
22 | | - * Represents a command node in a command tree structure. |
23 | | - * A basic command node may contain information about the command, its children, |
24 | | - * and the command's literal and arguments. |
25 | | - * This interface also extends {@link ExecutionHandler}, allowing for command execution handling. |
26 | | - * |
27 | | - * @see CommandManager |
28 | | - * @see CommandsAPI |
29 | | - * @see CommandNode |
30 | | - */ |
31 | | -public interface BasicCommandNode extends ExecutionHandler, CommandRequirement { |
32 | | - /** |
33 | | - * Registers a command node with the provided {@link CommandsAPI}. |
34 | | - * |
35 | | - * @param api The CommandsAPI instance used to manage command nodes. |
36 | | - * @param root The root command node to register. |
37 | | - */ |
38 | | - static void register(final @NotNull CommandsAPI api, final @NotNull BasicCommandNode root) { |
39 | | - api.manager().register(root); |
40 | | - } |
41 | | - |
42 | | - /** |
43 | | - * Registers a command node by its class type with the provided {@link CommandsAPI}. |
44 | | - * <p> |
45 | | - * If the root class does not have an empty constructor, this method attempts to find |
46 | | - * a constructor that accepts a {@link JavaPlugin} instance and registers using it. |
47 | | - * </p> |
48 | | - * |
49 | | - * @param api The CommandsAPI instance used to manage command nodes. |
50 | | - * @param root The class type of the root command node to register. |
51 | | - * @throws RuntimeException If no suitable constructor is found. |
52 | | - */ |
53 | | - static void register(final @NotNull CommandsAPI api, final @NotNull Class<? extends BasicCommandNode> root) { |
54 | | - try { |
55 | | - register(api, root.getDeclaredConstructor().newInstance()); |
56 | | - } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { |
57 | | - api.plugin().getLogger().severe("Attempted to register a basic command node. Couldn't find a empty constructor, attempting to provide a plugin inside the parameters."); |
58 | | - |
59 | | - try { |
60 | | - register(api, root.getDeclaredConstructor(api.plugin().getClass()).newInstance(api.plugin())); |
61 | | - } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { |
62 | | - api.plugin().getLogger().severe("Attempted to register a basic command node. Couldn't find a empty constructor, attempting to provide a plugin inside the parameters."); |
63 | | - throw new RuntimeException("Attempted to register a basic command node, couldn't find empty constructor and constructor of parameters JavaPlugin/Plugin/" + api.plugin().getClass().getSimpleName()); |
64 | | - } |
65 | | - |
66 | | - throw new RuntimeException(e); |
67 | | - } |
68 | | - } |
69 | | - |
70 | | - /** |
71 | | - * Registers a command node using the default {@link CommandsAPI} instance. |
72 | | - * |
73 | | - * @param root The root command node to register. |
74 | | - */ |
75 | | - static void register(final @NotNull BasicCommandNode root) { |
76 | | - register(APIHolder.api(), root); |
77 | | - } |
78 | | - |
79 | | - /** |
80 | | - * Registers a command node by its class type using the default {@link CommandsAPI} instance. |
81 | | - * |
82 | | - * @param root The class type of the root command node to register. |
83 | | - */ |
84 | | - static void register(final @NotNull Class<? extends BasicCommandNode> root) { |
85 | | - register(APIHolder.api(), root); |
86 | | - } |
87 | | - |
88 | | - /** |
89 | | - * Registers this command node using the default {@link CommandsAPI} instance. |
90 | | - */ |
91 | | - default void register() { |
92 | | - register(this); |
93 | | - } |
| 12 | +public interface BasicCommandNode { |
| 13 | + @NotNull |
| 14 | + String getLiteral(); |
94 | 15 |
|
95 | | - /** |
96 | | - * Registers this command node with the provided {@link CommandsAPI} instance. |
97 | | - * |
98 | | - * @param api The CommandsAPI instance used to manage command nodes. |
99 | | - */ |
100 | | - default void register(final @NotNull CommandsAPI api) { |
101 | | - register(api, this); |
| 16 | + @NotNull |
| 17 | + default Optional<String> getPermission() { |
| 18 | + return Optional.empty(); |
102 | 19 | } |
103 | 20 |
|
104 | | - /** |
105 | | - * Gets the command information associated with this command node. |
106 | | - * |
107 | | - * @return the {@link CommandInfo} object containing the command's metadata, |
108 | | - * or {@code null} if no information is associated with this command node. |
109 | | - */ |
110 | | - @Nullable |
111 | | - CommandInfo info(); |
112 | | - |
113 | | - /** |
114 | | - * Gets the literal string representing this command node. |
115 | | - * The literal is typically the name or identifier of the command. |
116 | | - * |
117 | | - * @return a non-null string representing the literal of this command node. |
118 | | - */ |
119 | 21 | @NotNull |
120 | | - String literal(); |
| 22 | + default Collection<String> getAliases() { |
| 23 | + return List.of(); |
| 24 | + } |
121 | 25 |
|
122 | | - /** |
123 | | - * Gets an unmodifiable list of arguments that this command node accepts. |
124 | | - * This method returns an empty list by default, which can be overridden by implementing classes. |
125 | | - * |
126 | | - * @return a non-null unmodifiable list of {@link CommandArgument} objects. |
127 | | - */ |
128 | 26 | @NotNull |
129 | 27 | @Unmodifiable |
130 | | - default List<CommandArgument<?>> arguments() { |
131 | | - return ImmutableList.of(); |
| 28 | + default Collection<? extends CommandArgument> getArguments() { |
| 29 | + return List.of(); |
132 | 30 | } |
133 | 31 |
|
134 | | - /** |
135 | | - * Gets an unmodifiable list of child command nodes for this command node. |
136 | | - * Child nodes represent sub-commands or additional layers in the command hierarchy. |
137 | | - * This method returns an empty list by default, which can be overridden by implementing classes. |
138 | | - * |
139 | | - * @return a non-null unmodifiable list of {@link BasicCommandNode} objects representing the child nodes. |
140 | | - */ |
141 | 32 | @NotNull |
142 | 33 | @Unmodifiable |
143 | | - default List<BasicCommandNode> children() { |
144 | | - return ImmutableList.of(); |
| 34 | + default Collection<?> getChildren() { |
| 35 | + return List.of(); |
145 | 36 | } |
146 | 37 |
|
147 | | - @NotNull |
148 | | - @Override |
149 | | - default RequirementResult require(final @NotNull CommandContext context) { |
150 | | - return RequirementResult.passed(); |
151 | | - } |
| 38 | + void execute(final @NotNull CommandContext<? extends CommandSender> context); |
152 | 39 | } |
0 commit comments