|
6 | 6 |
|
7 | 7 | # ⚡ Command Framework |
8 | 8 |
|
9 | | -A modern, flexible command framework for Bukkit/Spigot and especially Paper Minecraft servers. |
| 9 | +A modern, flexible command framework for Bukkit/Spigot and especially Paper Minecraft servers. |
| 10 | +Easily create, register, and manage commands at runtime—even on Paper, where this is usually difficult. |
10 | 11 | Easily create, register, and manage commands at runtime—even on Paper, where this is usually difficult. |
11 | 12 |
|
12 | 13 | --- |
13 | | - |
14 | 14 | ## ✨ Features |
15 | | - |
| 15 | +--- |
16 | 16 | - 🔄 **Dynamic Command Registration:** Register/unregister commands at runtime, even on Paper. |
17 | 17 | - 🌳 **Sub-Commands:** Build command hierarchies with permissions and aliases. |
18 | 18 | - ✨ **Tab Completion:** Context-aware suggestions with `TabBuilder`. |
19 | 19 | - 🔐 **Permissions:** Wildcard and custom permission checks. |
20 | 20 | - 🧑💻 **Fluent API:** Quickly build commands with `CommandBuilder`. |
21 | | - |
22 | | ---- |
23 | | - |
24 | | -## 🛠️ Quick Example |
25 | | - |
26 | | -Create and register a simple command with a sub-command: |
27 | | - |
28 | | -```java |
29 | | -package com.example.myplugin.command; |
30 | | - |
31 | | -import me.croabeast.command.BukkitCommand; |
32 | | -import me.croabeast.command.SubCommand; |
33 | | -import me.croabeast.command.TabBuilder; |
34 | 21 | import me.croabeast.command.DefaultPermissible; |
35 | 22 | import org.bukkit.command.CommandSender; |
36 | 23 | import org.bukkit.plugin.Plugin; |
37 | | -import org.jetbrains.annotations.NotNull; |
38 | | - |
39 | | -public class GreetCommand extends BukkitCommand implements DefaultPermissible { |
40 | | - |
41 | | - /** |
42 | | - * Constructs the GreetCommand with a reference to the owning plugin. |
43 | | - * |
44 | | - * @param plugin the plugin instance. |
45 | | - */ |
46 | | - public GreetCommand(Plugin plugin) { |
47 | | - super(plugin, "greet"); |
48 | | - |
49 | | - // Set up the main command executable |
50 | | - setPredicate((CommandSender sender, String[] args) -> { |
51 | | - sender.sendMessage("Hello, " + sender.getName() + "!"); |
52 | | - return Executable.State.TRUE; |
53 | | - }); |
54 | | - |
55 | | - // Register a sub-command "reload" with an alias "r" |
56 | | - SubCommand reloadSub = new SubCommand(this, "reload;r"); |
57 | | - reloadSub.setPredicate((sender, args) -> { |
58 | | - // Reload logic here |
59 | | - sender.sendMessage("GreetCommand configuration reloaded."); |
60 | | - return true; |
61 | | - }); |
62 | | - addSubCommand(reloadSub); |
63 | | - } |
64 | | - |
65 | | - /** |
66 | | - * Provides custom tab completion for the command. |
67 | | - * |
68 | | - * @param sender the command sender. |
69 | | - * @param alias the command alias used. |
70 | | - * @param args the arguments passed to the command. |
71 | | - * @return a list of suggestions. |
72 | | - */ |
73 | | - @NotNull |
74 | | - @Override |
75 | | - public java.util.List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, String[] args) { |
76 | | - // Create a simple TabBuilder for suggestions |
77 | | - TabBuilder builder = new TabBuilder(); |
78 | | - if (args.length == 1) { |
79 | | - // Suggest "hello" and "hi" when no sub-command is specified |
80 | | - builder.addArgument(1, "hello"); |
81 | | - builder.addArgument(1, "hi"); |
82 | | - } else if (args.length > 1) { |
83 | | - // Optionally, provide additional suggestions for further arguments |
84 | | - builder.addArgument(args.length, "option1"); |
85 | | - builder.addArgument(args.length, "option2"); |
86 | | - } |
87 | | - return builder.build(sender, args); |
88 | | - } |
89 | | -} |
90 | | -``` |
| 24 | +## 🛠️ Quick Example |
91 | 25 |
|
92 | | -#### 📝 Registering the Command |
| 26 | +Create and register a simple command with a sub-command: |
93 | 27 |
|
94 | 28 | In your plugin’s main class (extending `JavaPlugin`), register the command: |
95 | 29 |
|
@@ -171,7 +105,7 @@ Replace `${version}` with the latest version. |
171 | 105 |
|
172 | 106 | ## 🎉 Happy Coding! |
173 | 107 |
|
174 | | -Build powerful, modern commands for your Minecraft plugin with ease! |
| 108 | +Build powerful, modern commands for your Minecraft plugin with ease! |
175 | 109 | Questions? Join our [Discord](https://discord.com/invite/gzzhVqgy3b) 💬 |
176 | 110 |
|
177 | 111 | — *CroaBeast* |
0 commit comments