Skip to content
This repository was archived by the owner on Feb 27, 2025. It is now read-only.

Commit 6d29e3e

Browse files
committed
Add missing code references
And with that, the documentation has been moved to the docs repo!
1 parent 0c3cb09 commit 6d29e3e

File tree

8 files changed

+286
-30
lines changed

8 files changed

+286
-30
lines changed

commandapi-documentation-code/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies {
4141
api(libs.org.junit.jupiter.junit.jupiter.engine)
4242
api(libs.dev.jorel.commandapi.bukkit.core)
4343
api(libs.dev.jorel.commandapi.bukkit.kotlin)
44+
api(libs.dev.jorel.commandapi.annotations)
4445
api(libs.de.tr7zw.item.nbt.api)
4546
api(libs.org.jetbrains.kotlin.kotlin.stdlib)
4647
compileOnly(libs.com.mojang.brigadier)

commandapi-documentation-code/gradle/libs.versions.toml

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ com-mojang-brigadier = "1.0.17"
88
de-tr7zw-item-nbt-api = "2.11.1"
99
dev-jorel-commandapi-bukkit-core = "9.6.2-SNAPSHOT"
1010
dev-jorel-commandapi-bukkit-kotlin = "9.6.2-SNAPSHOT"
11+
dev-jorel-commandapi-annotations = "9.6.2-SNAPSHOT"
1112
dev-jorel-commandapi-bukkit-test-toolkit = "9.6.2-SNAPSHOT"
1213
io-papermc-paper-paper-api = "1.19.4-R0.1-SNAPSHOT"
1314
net-kyori-adventure-platform-bukkit = "4.2.0"
@@ -21,6 +22,7 @@ com-mojang-brigadier = { module = "com.mojang:brigadier", version.ref = "com-moj
2122
de-tr7zw-item-nbt-api = { module = "de.tr7zw:item-nbt-api", version.ref = "de-tr7zw-item-nbt-api" }
2223
dev-jorel-commandapi-bukkit-core = { module = "dev.jorel:commandapi-bukkit-core", version.ref = "dev-jorel-commandapi-bukkit-core" }
2324
dev-jorel-commandapi-bukkit-kotlin = { module = "dev.jorel:commandapi-bukkit-kotlin", version.ref = "dev-jorel-commandapi-bukkit-kotlin" }
25+
dev-jorel-commandapi-annotations = { module = "dev.jorel:commandapi-annotations", version.ref = "dev-jorel-commandapi-annotations" }
2426
dev-jorel-commandapi-bukkit-test-toolkit = { module = "dev.jorel:commandapi-bukkit-test-toolkit", version.ref = "dev-jorel-commandapi-bukkit-test-toolkit" }
2527
io-papermc-paper-paper-api = { module = "io.papermc.paper:paper-api", version.ref = "io-papermc-paper-paper-api" }
2628
net-kyori-adventure-platform-bukkit = { module = "net.kyori:adventure-platform-bukkit", version.ref = "net-kyori-adventure-platform-bukkit" }

commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java

+255-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,29 @@
2929
import com.mojang.brigadier.context.StringRange;
3030
import com.mojang.brigadier.exceptions.CommandSyntaxException;
3131
import com.mojang.brigadier.suggestion.Suggestions;
32+
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
3233
import com.mojang.brigadier.tree.LiteralCommandNode;
3334
import de.tr7zw.changeme.nbtapi.NBTContainer;
3435
import dev.jorel.commandapi.*;
36+
import dev.jorel.commandapi.annotations.Command;
37+
import dev.jorel.commandapi.annotations.Alias;
38+
import dev.jorel.commandapi.annotations.Default;
39+
import dev.jorel.commandapi.annotations.Help;
40+
import dev.jorel.commandapi.annotations.NeedsOp;
41+
import dev.jorel.commandapi.annotations.Permission;
42+
import dev.jorel.commandapi.annotations.Subcommand;
43+
import dev.jorel.commandapi.annotations.arguments.ADoubleArgument;
44+
import dev.jorel.commandapi.annotations.arguments.AEntitySelectorArgument;
45+
import dev.jorel.commandapi.annotations.arguments.AFloatArgument;
46+
import dev.jorel.commandapi.annotations.arguments.AIntegerArgument;
47+
import dev.jorel.commandapi.annotations.arguments.ALiteralArgument;
48+
import dev.jorel.commandapi.annotations.arguments.ALocation2DArgument;
49+
import dev.jorel.commandapi.annotations.arguments.ALocationArgument;
50+
import dev.jorel.commandapi.annotations.arguments.ALongArgument;
51+
import dev.jorel.commandapi.annotations.arguments.AMultiLiteralArgument;
52+
import dev.jorel.commandapi.annotations.arguments.APlayerArgument;
53+
import dev.jorel.commandapi.annotations.arguments.AScoreHolderArgument;
54+
import dev.jorel.commandapi.annotations.arguments.AStringArgument;
3555
import dev.jorel.commandapi.arguments.*;
3656
import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException;
3757
import dev.jorel.commandapi.arguments.CustomArgument.MessageBuilder;
@@ -151,6 +171,190 @@ void aliases() {
151171
/* ANCHOR_END: aliases1 */
152172
}
153173

174+
class annotations2 {
175+
/* ANCHOR: annotations2 */
176+
@Command("teleport")
177+
@Alias({"tp", "tele"})
178+
public class TeleportCommand {
179+
/* ANCHOR_END: annotations2 */
180+
}
181+
}
182+
class annotations3 {
183+
/* ANCHOR: annotations3 */
184+
@Command("teleport")
185+
@Permission("myplugin.tp")
186+
class TeleportCommand {
187+
/* ANCHOR_END: annotations3 */
188+
}
189+
}
190+
class annotations4 {
191+
/* ANCHOR: annotations4 */
192+
@Command("teleport")
193+
@NeedsOp
194+
class TeleportCommand {
195+
/* ANCHOR_END: annotations4 */
196+
}
197+
}
198+
class annotations5 {
199+
/* ANCHOR: annotations5 */
200+
@Command("teleport")
201+
@Help("Teleports yourself to another location")
202+
class TeleportCommand {
203+
/* ANCHOR_END: annotations5 */
204+
}
205+
}
206+
class annotations6 {
207+
/* ANCHOR: annotations6 */
208+
@Command("teleport")
209+
@Help(value = "Teleports yourself to another location", shortDescription = "TP to a location")
210+
class TeleportCommand {
211+
/* ANCHOR_END: annotations6 */
212+
213+
/* ANCHOR: annotations7 */
214+
@Subcommand({"teleport", "tp"})
215+
public static void teleport(Player player, @APlayerArgument OfflinePlayer target) {
216+
if(target.isOnline() && target instanceof Player onlineTarget) {
217+
player.teleport(onlineTarget);
218+
}
219+
}
220+
/* ANCHOR_END: annotations7 */
221+
}
222+
/* ANCHOR: annotations8 */
223+
@Default
224+
public static void command(CommandSender sender,
225+
@ADoubleArgument(min = 0.0, max = 10.0) double someDouble,
226+
@AFloatArgument(min = 5.0f, max = 10.0f) float someFloat,
227+
@AIntegerArgument(max = 100) int someInt,
228+
@ALongArgument(min = -10) long someLong
229+
) {
230+
// Command implementation here
231+
}
232+
/* ANCHOR_END: annotations8 */
233+
/* ANCHOR: annotations9 */
234+
@Default
235+
public static void command(CommandSender sender,
236+
@ALiteralArgument("myliteral") String literal,
237+
@AMultiLiteralArgument({"literal", "anotherliteral"}) String multipleLiterals
238+
) {
239+
// Command implementation here
240+
}
241+
/* ANCHOR_END: annotations9 */
242+
/* ANCHOR: annotations10 */
243+
@Default
244+
public static void command(CommandSender sender,
245+
@ALocationArgument(LocationType.BLOCK_POSITION) Location location,
246+
@ALocation2DArgument(LocationType.PRECISE_POSITION) Location location2d,
247+
@AEntitySelectorArgument.ManyEntities Collection<Entity> entities,
248+
@AScoreHolderArgument.Multiple Collection<String> scoreHolders
249+
) {
250+
// Command implementation here
251+
}
252+
/* ANCHOR_END: annotations10 */
253+
}
254+
255+
class annotationsintro {
256+
void annotationsintro1() {
257+
/* ANCHOR: annotationsintro1 */
258+
Map<String, Location> warps = new HashMap<>();
259+
260+
// /warp
261+
new CommandAPICommand("warp")
262+
.executes((sender, args) -> {
263+
sender.sendMessage("--- Warp help ---");
264+
sender.sendMessage("/warp - Show this help");
265+
sender.sendMessage("/warp <warp> - Teleport to <warp>");
266+
sender.sendMessage("/warp create <warpname> - Creates a warp at your current location");
267+
})
268+
.register();
269+
270+
// /warp <warp>
271+
new CommandAPICommand("warp")
272+
.withArguments(new StringArgument("warp").replaceSuggestions(ArgumentSuggestions.strings(info ->
273+
warps.keySet().toArray(new String[0])
274+
)))
275+
.executesPlayer((player, args) -> {
276+
player.teleport(warps.get((String) args.get(0)));
277+
})
278+
.register();
279+
280+
// /warp create <warpname>
281+
new CommandAPICommand("warp")
282+
.withSubcommand(
283+
new CommandAPICommand("create")
284+
.withPermission("warps.create")
285+
.withArguments(new StringArgument("warpname"))
286+
.executesPlayer((player, args) -> {
287+
warps.put((String) args.get(0), player.getLocation());
288+
})
289+
)
290+
.register();
291+
/* ANCHOR_END: annotationsintro1 */
292+
}
293+
294+
/* ANCHOR: annotationsintro2 */
295+
/* ANCHOR: annotationsintro4 */
296+
@Command("warp")
297+
public class WarpCommand {
298+
/* ANCHOR_END: annotationsintro4 */
299+
300+
// List of warp names and their locations
301+
static Map<String, Location> warps = new HashMap<>();
302+
303+
@Default
304+
public static void warp(CommandSender sender) {
305+
sender.sendMessage("--- Warp help ---");
306+
sender.sendMessage("/warp - Show this help");
307+
sender.sendMessage("/warp <warp> - Teleport to <warp>");
308+
sender.sendMessage("/warp create <warpname> - Creates a warp at your current location");
309+
}
310+
311+
@Default
312+
public static void warp(Player player, @AStringArgument String warpName) {
313+
player.teleport(warps.get(warpName));
314+
}
315+
316+
@Subcommand("create")
317+
@Permission("warps.create")
318+
public static void createWarp(Player player, @AStringArgument String warpName) {
319+
warps.put(warpName, player.getLocation());
320+
}
321+
322+
}
323+
324+
/* ANCHOR_END: annotationsintro2 */
325+
class annotationsintro3 {
326+
static Map<String, Location> warps = new HashMap<>();
327+
{
328+
/* ANCHOR: annotationsintro3 */
329+
CommandAPI.registerCommand(WarpCommand.class);
330+
/* ANCHOR_END: annotationsintro3 */
331+
}
332+
/* ANCHOR: annotationsintro5 */
333+
@Default
334+
public static void warp(CommandSender sender) {
335+
sender.sendMessage("--- Warp help ---");
336+
sender.sendMessage("/warp - Show this help");
337+
sender.sendMessage("/warp <warp> - Teleport to <warp>");
338+
sender.sendMessage("/warp create <warpname> - Creates a warp at your current location");
339+
}
340+
341+
/* ANCHOR_END: annotationsintro5 */
342+
/* ANCHOR: annotationsintro6 */
343+
@Default
344+
public static void warp(Player player, @AStringArgument String warpName) {
345+
player.teleport(warps.get(warpName));
346+
}
347+
/* ANCHOR_END: annotationsintro6 */
348+
/* ANCHOR: annotationsintro7 */
349+
@Subcommand("create")
350+
@Permission("warps.create")
351+
public static void createWarp(Player player, @AStringArgument String warpName) {
352+
warps.put(warpName, player.getLocation());
353+
}
354+
/* ANCHOR_END: annotationsintro7 */
355+
}
356+
}
357+
154358
void argument_angle() {
155359
// NOTE: This example isn't used!
156360
/* ANCHOR: argumentAngle1 */
@@ -661,8 +865,23 @@ void argument_lootTable() {
661865
}
662866

663867
@SuppressWarnings({ "unchecked", "null" })
664-
void argument_map() {
868+
class argument_map {
665869
/* ANCHOR: argumentMap1 */
870+
@FunctionalInterface
871+
public interface StringParser<T> {
872+
/**
873+
* A method that turns a String into an object of type T.
874+
*
875+
* @param s The String to parse
876+
* @return The resulting parsed object
877+
* @throws WrapperCommandSyntaxException If there is a problem with the syntax of the String that prevents it from being turned into an object of type T.
878+
*/
879+
T parse(String s) throws WrapperCommandSyntaxException;
880+
}
881+
882+
/* ANCHOR_END: argumentMap1 */
883+
void commandReg() {
884+
/* ANCHOR: argumentMap2 */
666885
new CommandAPICommand("sendmessage")
667886
// Parameter 'delimiter' is missing, delimiter will be a colon
668887
// Parameter 'separator' is missing, separator will be a space
@@ -694,7 +913,8 @@ void argument_map() {
694913
}
695914
})
696915
.register();
697-
/* ANCHOR_END: argumentMap1 */
916+
/* ANCHOR_END: argumentMap2 */
917+
}
698918
}
699919

700920
@SuppressWarnings("null")
@@ -1194,6 +1414,25 @@ void brigadier(){
11941414
/* ANCHOR_END: brigadier7 */
11951415
}
11961416

1417+
class brigadierSuggestions {
1418+
/* ANCHOR: brigadierSuggestions0 */
1419+
@FunctionalInterface
1420+
public interface ArgumentSuggestions<CommandSender> {
1421+
1422+
/**
1423+
* Create a {@link CompletableFuture} resolving onto a brigadier {@link Suggestions} object.
1424+
*
1425+
* @param info The suggestions info
1426+
* @param builder The Brigadier {@link SuggestionsBuilder} object
1427+
* @return a {@link CompletableFuture} resolving onto a brigadier {@link Suggestions} object.
1428+
* @throws CommandSyntaxException if there is an error making suggestions
1429+
*/
1430+
CompletableFuture<Suggestions> suggest(SuggestionInfo<CommandSender> info, SuggestionsBuilder builder)
1431+
throws CommandSyntaxException;
1432+
/* ANCHOR_END: brigadierSuggestions0 */
1433+
}
1434+
}
1435+
11971436
void brigadierSuggestions() {
11981437
/* ANCHOR: brigadierSuggestions1 */
11991438
Map<String, String> emojis = new HashMap<>();
@@ -2077,6 +2316,20 @@ void proxySender() {
20772316
/* ANCHOR_END: proxySender2 */
20782317
}
20792318

2319+
class registeringannotations {
2320+
class WarpCommand {}
2321+
/* ANCHOR: registeringannotations2 */
2322+
class MyPlugin extends JavaPlugin {
2323+
2324+
@Override
2325+
public void onLoad() {
2326+
CommandAPI.registerCommand(WarpCommand.class);
2327+
}
2328+
2329+
}
2330+
/* ANCHOR_END: registeringannotations2 */
2331+
}
2332+
20802333
void requirements() {
20812334
/* ANCHOR: requirements1 */
20822335
new CommandAPICommand("repair")

0 commit comments

Comments
 (0)