Skip to content

Commit 900a9e3

Browse files
committed
Add hyperlinks
1 parent c50ce1d commit 900a9e3

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

docs/paper/dev/api/command-api/arguments/adventure-arguments.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ on that resulting completable future. Inside of that, you can send the signed me
148148
:::warning
149149

150150
The use of thread unsafe Bukkit API inside the `.thenAccept` method is not supported, as this is an asynchronous method, which does not run on the main thread.
151-
If you need to use Bukkit API, you can schedule a task to be run on the next available tick. You can read up on that **here** (WIP).
151+
If you need to use Bukkit API, you can schedule a task to be run on the next available tick. You can read up on that [here](../../scheduler.mdx).
152152

153153
:::
154154

docs/paper/dev/api/command-api/arguments/bukkit-arguments.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static LiteralCommandNode<CommandSourceStack> blockStateArgument() {
3939

4040
## ItemStack Argument
4141
The item stack argument is a way to retrieve an `ItemStack` following the same argument format as the vanilla `/give <player> <item> [<amount>]` command as its second argument.
42-
The user may also define components to further customize the `ItemStack`. If you only require a material, you should instead check out the **Registry Arguments** (WIP).
42+
The user may also define components to further customize the `ItemStack`. If you only require a material, you should instead check out the [registry arguments](./registry-arguments.mdx).
4343

4444
### Example usage
4545
```java
@@ -139,7 +139,7 @@ public static LiteralCommandNode<CommandSourceStack> timeArgument() {
139139
## UUID Argument
140140
The uuid argument allows the user to input a valid uuid. You can retrieve that value as a `UUID` object, which is used in various places, like `Bukkit.getOfflinePlayer(UUID)`.
141141
This argument is not very user-friendly, which is why it is suggested to only use this as a moderation or debug argument. For user input regarding offline player
142-
retrieval, the **player profiles argument** (WIP) is preferred, as it allows by-name lookup.
142+
retrieval, the [player profiles argument](./entity-player-arguments#player-profiles-argument) is preferred, as it allows by-name lookup.
143143

144144
### Example usage - Lookup command
145145
```java

docs/paper/dev/api/command-api/basics/command-registration.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, comman
117117

118118
### Registering a BasicCommand
119119
A `BasicCommand` is a bukkit-like way of defining commands. Instead of building up a command tree, we allow all user input and retrieve the arguments as a simple array of Strings.
120-
This type of commands is particularly useful for very simple, text based commands, like a `/broadcast` command. You can read up on more details **here** (WIP).
120+
This type of commands is particularly useful for very simple, text based commands, like a `/broadcast` command. You can read up on more details about basic commands
121+
[here](../misc/basic-command.mdx).
121122

122123
Assuming you already have your `BasicCommand` object, we can register it like this:
123124

docs/paper/dev/api/command-api/misc/basic-command.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ With the permission method you can, similar to the `canUse` method, set the perm
6161

6262
## Example: Broadcast command
6363
As an example, we can create a simple broadcast command. We start by declaring creating a class which implements BasicCommand and overrides `execute` and `permission`:
64+
6465
```java
6566
package your.package.name;
6667

@@ -86,6 +87,7 @@ Our permission is set to `example.broadcast.use`. In order to give yourself that
8687
operator permissions. You can also set this permission to be `true` by default. For this, please check out the [plugin.yml documentation](../../../getting-started/plugin-yml.mdx).
8788

8889
Now, in our `execute` method, we can retrieve the name of the executor of that command. If we do not find one, we can just get the name of the command sender, like this:
90+
8991
```java
9092
final Component name;
9193
if (commandSourceStack.getExecutor() != null) {
@@ -99,6 +101,7 @@ else {
99101
This makes sure that we cover all cases and even allow the command to work correctly with `/execute as`.
100102

101103
Next, we retrieve all arguments and join them to a String or tell the sender that at least one argument is required in order to send a broadcast
104+
102105
if they defined no arguments (meaning that `args` has a length of 0):
103106
```java
104107
if (args.length == 0) {
@@ -110,6 +113,7 @@ final String message = String.join(" ", args);
110113
```
111114

112115
Finally, we can build our broadcast message and send it via `Bukkit.broadcast(Component)`:
116+
113117
```java
114118
final Component broadcastMessage = MiniMessage.miniMessage().deserialize(
115119
"<red><bold>BROADCAST</red> <name> <dark_gray>»</dark_gray> <message>",
@@ -121,6 +125,7 @@ Bukkit.broadcast(broadcastMessage);
121125
```
122126

123127
And we are done! As you can see, this is a very simple way to define commands. Here is the final result of our class:
128+
124129
```java title="BroadcastCommand.java"
125130
package your.package.name;
126131

@@ -167,6 +172,7 @@ public class BroadcastCommand implements BasicCommand {
167172
```
168173

169174
Registering our command looks like this:
175+
170176
```java title="PluginMainClass.java"
171177
@Override
172178
public void onEnable() {
@@ -183,6 +189,7 @@ And this is how it looks like in-game:
183189
## Example: Adding suggestions
184190
Our broadcast command works pretty well, but it is lacking on suggestions. A very common kind of suggestion for text based commands are player names.
185191
In order to suggest player names, we can just map all online players to their name, like this:
192+
186193
```java
187194
@Override
188195
public Collection<String> suggest(CommandSourceStack commandSourceStack, String[] args) {
@@ -196,13 +203,15 @@ This works great, but as you can see here, it will always suggest all players, r
196203
In order to fix this, we have to do some changes:
197204

198205
First, we early return what we already have in case there is no arguments, as we cannot filter by input then:
206+
199207
```java
200208
if (args.length == 0) {
201209
return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
202210
}
203211
```
204212

205213
After this, we can add a `filter` clause to our stream, where we filter all names by whether they start with our current input, which is `args[args.length - 1]`:
214+
206215
```java
207216
return Bukkit.getOnlinePlayers().stream()
208217
.map(Player::getName)
@@ -218,6 +227,7 @@ But when there is no player who starts with an input, it just suggests nothing:
218227

219228
### Final code
220229
Here is the final code for our whole `BroadcastCommand` class, including the suggestions:
230+
221231
```java
222232
package your.package.name;
223233

docs/paper/dev/api/command-api/misc/comparison-bukkit-brigadier.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public class BukkitPartyCommand extends BukkitCommand {
4747
}
4848
}
4949
```
50+
5051
After that, you can define your command like this:
52+
5153
```java title="PluginClass.java"
5254
this.getServer().getCommandMap().register(
5355
this.getName().toLowerCase(),
@@ -64,6 +66,7 @@ In our case, it is the root of our command. We can do that by running `Commands.
6466
`LiteralArgumentBuilder<CommandSourceStack>`, where we can define some arguments and executors. Once we are done, we can call
6567
`LiteralArgumentBuilder#build()` to retrieve our build `LiteralCommandNode`, which we can then register. That sounds complicated at first,
6668
but once you see it in action, it looks less terrifying:
69+
6770
```java title="PaperPartyCommand.java"
6871
public static LiteralCommandNode<CommandSourceStack> createCommand(final String commandName) {
6972
return Commands.literal(commandName)

0 commit comments

Comments
 (0)