Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Improve Brigadier Documentation #507

Draft
wants to merge 55 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
159f2d4
Add introduction page
Strokkur424 Dec 14, 2024
86fbcbd
Move comparison to seperate file
Strokkur424 Dec 14, 2024
b541bf5
Add missing files!
Strokkur424 Dec 14, 2024
aedbde5
Improve introduction page
Strokkur424 Dec 14, 2024
5a67905
Update docs/paper/dev/api/command-api/introduction.mdx
Strokkur424 Dec 14, 2024
e65c570
Update docs/paper/dev/api/command-api/introduction.mdx
Strokkur424 Dec 14, 2024
a63eec3
Create command tree site
Strokkur424 Dec 14, 2024
473c518
Merge branch 'improve-brigadier-docs' of https://github.com/Strokkur4…
Strokkur424 Dec 14, 2024
96c0352
Remove titles from code blocks
Strokkur424 Dec 14, 2024
efb22e3
Revisit comparison page
Strokkur424 Dec 14, 2024
ac4ef8b
Improvements to the command tree site
Strokkur424 Dec 15, 2024
548eae0
Create command execution page
Strokkur424 Dec 15, 2024
9c8f087
Commit unsaved changes
Strokkur424 Dec 15, 2024
c165ade
Decrease tree art size
Strokkur424 Dec 15, 2024
57cbd19
Move newlines
Strokkur424 Dec 15, 2024
0d0f9f2
Add arguments-and-literals site
Strokkur424 Dec 15, 2024
d1d6355
Fix spelling mistake
Strokkur424 Dec 15, 2024
c3a721f
Reverse gamemode tree
Strokkur424 Dec 15, 2024
d0dbb30
Slight improvements to the arguments page
Strokkur424 Dec 15, 2024
4b0ed02
Add command executor site
Strokkur424 Dec 15, 2024
1147109
Slight modifications
Strokkur424 Dec 15, 2024
f55c87b
Fix incorrect link
Strokkur424 Dec 15, 2024
834c010
Add command registration site
Strokkur424 Dec 17, 2024
a6ec90d
Fix broken link
Strokkur424 Dec 17, 2024
c7a3e70
Change titles
Strokkur424 Dec 17, 2024
f9122d1
Move previous documentation to seperate category for better organization
Strokkur424 Dec 17, 2024
e6e4074
...forgor to git add the new files
Strokkur424 Dec 17, 2024
968b639
blockPosition, blockState, and component arguments
Strokkur424 Dec 17, 2024
f6a7605
doubleRange, entity, entities arguments
Strokkur424 Dec 17, 2024
f786b2c
Hopefully fix all issues
Strokkur424 Dec 17, 2024
1aa2359
Convert gifs to mp4s
Strokkur424 Dec 18, 2024
b3f1561
Add entity anchor, fine position, gamemode, heightmap, integerrange, …
Strokkur424 Dec 18, 2024
14d2f89
Format
Strokkur424 Dec 18, 2024
797cf99
Add namespaced and objective criteria arguments
Strokkur424 Dec 18, 2024
e356556
Fix casing for argument titles
Strokkur424 Dec 18, 2024
221361d
Fixup
Strokkur424 Dec 18, 2024
81a974f
Add player, players, playerprofiles, scoreboarddisplayslot, signedmes…
Strokkur424 Dec 18, 2024
dc67f62
Rebase main branch
Strokkur424 Dec 19, 2024
51411ae
Basic restructure
Strokkur424 Dec 19, 2024
d5e7233
Finish migrating arguments to seperate pages
Strokkur424 Dec 21, 2024
95cd544
Revert "Finish migrating arguments to seperate pages"
Strokkur424 Dec 21, 2024
f9c122b
Migrate arguments to seperate pages
Strokkur424 Dec 21, 2024
7fde946
Fix spelling mistakes
Strokkur424 Dec 21, 2024
aa67a4b
Final fixup
Strokkur424 Dec 21, 2024
bbbd32d
Update docs/paper/dev/api/command-api/arguments/adventure-arguments.mdx
Strokkur424 Dec 21, 2024
0edb936
Add showcase videos and basic registry argument file structure
Strokkur424 Dec 25, 2024
e93ac96
Fix assets
Strokkur424 Dec 25, 2024
47a52c7
Rename Brigadier and Bukkit comparison page title
Strokkur424 Dec 28, 2024
7063436
Merge branch 'improve-brigadier-docs' of github.com:Strokkur424/paper…
Strokkur424 Dec 28, 2024
72f01f2
Add registry preview videos
Strokkur424 Dec 29, 2024
e383051
Registry arguments
Strokkur424 Dec 29, 2024
9dc9d4b
Fix spelling
Strokkur424 Dec 29, 2024
55997df
Fix broken anchors
Strokkur424 Dec 29, 2024
686529e
Add BasicCommand documentation
Strokkur424 Dec 29, 2024
d5441c7
Fix spelling and wording
Strokkur424 Dec 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion config/sidebar.paper.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,46 @@ const paper: SidebarsConfig = {
type: "category",
label: "Brigadier Command API",
collapsed: true,
items: ["dev/api/command-api/commands", "dev/api/command-api/arguments"],
items: [
{
type: "category",
label: "Basics",
collapsed: true,
items: [
"dev/api/command-api/basics/introduction",
"dev/api/command-api/basics/command-tree",
"dev/api/command-api/basics/arguments-and-literals",
"dev/api/command-api/basics/command-executors",
"dev/api/command-api/basics/command-registration",
],
},
{
type: "category",
label: "Arguments",
collapsed: true,
items: [
"dev/api/command-api/arguments/minecraft-arguments",
"dev/api/command-api/arguments/location-arguments",
"dev/api/command-api/arguments/entity-player-arguments",
"dev/api/command-api/arguments/registry-arguments",
"dev/api/command-api/arguments/enum-value-arguments",
"dev/api/command-api/arguments/predicate-arguments",
"dev/api/command-api/arguments/adventure-arguments",
],
},
{
type: "category",
label: "Misc",
collapsed: true,
items: ["dev/api/command-api/misc/comparison-bukkit-brigadier"],
},
],
},
{
type: "category",
label: "Old Brigadier Command API",
collapsed: true,
items: ["dev/api/command-api-old/commands", "dev/api/command-api-old/arguments"],
},
{
type: "category",
Expand Down
186 changes: 186 additions & 0 deletions docs/paper/dev/api/command-api/arguments/adventure-arguments.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
---
slug: /dev/command-api/arguments/adventure-arguments
description: Documentation for all arguments returning Adventure API objects
---

import ComponentMp4 from "./assets/vanilla-arguments/component.mp4"
import KeyMp4 from "./assets/vanilla-arguments/key.mp4"
import NamedColorMp4 from "./assets/vanilla-arguments/namedcolor.mp4"
import StyleMp4 from "./assets/vanilla-arguments/style.mp4"
import SignedMessageMp4 from "./assets/vanilla-arguments/signedmessage.mp4"

# Adventure Library Arguments
These arguments return a class from the `net.kyori` package. They are *technically* not native to Minecraft or Bukkit, but as Paper includes the Adventure library, they are
usually widely used in the Paper ecosystem.


## Component Argument
The component argument is a very complicated command for the user, which is why it should not be used for usual user input. It follows the same format as the `/tellraw <player> <msg>`
command for its second argument. It accepts a text component as its json representation, returning it as an Adventure component to work with.

### Example usage
```java
public static LiteralCommandNode<CommandSourceStack> componentArgument() {
return Commands.literal("componentargument")
.then(Commands.argument("arg", ArgumentTypes.component())
.executes(ctx -> {
final Component component = ctx.getArgument("arg", Component.class);

ctx.getSource().getSender().sendRichMessage(
"Your message: <input>",
Placeholder.component("input", component)
);
return Command.SINGLE_SUCCESS;
}))
.build();
}
```

### In-game preview
<FullWidthVideo src={ComponentMp4}/>



## Key Argument
The key argument allows a user to put in any artificial (namespaced) key, ensuring its validity. This returns a `net.kyori.adventure.key.Key` from the adventure library,
which can be used at various other places in the Bukkit/Paper API.

### Example usage
```java
public static LiteralCommandNode<CommandSourceStack> keyArgument() {
return Commands.literal("key")
.then(Commands.argument("key_input", ArgumentTypes.key())
.executes(ctx -> {
final Key key = ctx.getArgument("key_input", Key.class);

ctx.getSource().getSender().sendRichMessage("You put in <aqua><key></aqua>!",
Placeholder.unparsed("key", key.asString())
);

return Command.SINGLE_SUCCESS;
}))
.build();
}
```

### In-game preview
<FullWidthVideo src={KeyMp4}/>



## Named Color Argument
This argument provides the user with the ability to select between the 16 build-in "named" text colors. This argument returns a `net.kyori.adventure.text.format.NamedtextColor` that
Strokkur424 marked this conversation as resolved.
Show resolved Hide resolved
you can use for styling components.

### Example usage
```java
public static LiteralCommandNode<CommandSourceStack> namedColorArgument() {
return Commands.literal("namedcolor")
.then(Commands.argument("color", ArgumentTypes.namedColor())
.then(Commands.argument("message", StringArgumentType.greedyString())
.executes(ctx -> {
final NamedTextColor color = ctx.getArgument("color", NamedTextColor.class);
final String msg = ctx.getArgument("message", String.class);

ctx.getSource().getSender().sendMessage(
Component.text(msg).color(color)
);
return Command.SINGLE_SUCCESS;
})))
.build();
}
```

### In-game preview
<FullWidthVideo src={NamedColorMp4}/>



## Adventure Style Argument
:::note

Similar to the component argument, this argument is not really appropriate for general user input, as it also follows the json format for displaying components. Most users
do not know how to use that format and thus its public usage is not advised.

:::

The style argument returns its value in form of an `net.kyori.adventure.text.format.Style` object. This can be applied to any component using `Component#style(Style)`.

Whilst the json input allows for the `text` field, it does not actually do anything.

### Example usage
```java
public static LiteralCommandNode<CommandSourceStack> styleArgument() {
return Commands.literal("style")
.then(Commands.argument("style", ArgumentTypes.style())
.then(Commands.argument("message", StringArgumentType.greedyString())
.executes(ctx -> {
final Style style = ctx.getArgument("style", Style.class);
final String message = ctx.getArgument("message", String.class);

ctx.getSource().getSender().sendRichMessage("Your input: <input>",
Placeholder.component("input", Component.text(message).style(style))
);
return Command.SINGLE_SUCCESS;
})))
.build();
}
```

### In-game preview
<FullWidthVideo src={StyleMp4}/>



## Signed Message Argument
The signed message argument allows a player (not a console!!) to send an argument in form of a **signed message** to the server. This signed message is a special type - it
allows the server to send that message, without the ability to directly modify it, to any player. The visible difference is that unsigned messages have a white bar at the left,
whilst signed messages don't.

A signed message argument returns a `SignedMessageResolver`. In order to call its `#resolve` method, you have to pass in two parameters:
* The argument name
* The `CommandContext<CommandSourceStack>` object

You then get returned with a `CompletableFuture<SignedMessage>`. In order to work with the resulting `SignedMessage`, you can call `CompletableFuture<T>#thenAccept(Consumer<T>)`
on that resulting completable future. Inside of that, you can send the signed message to players or work with it in other ways.

:::warning

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.
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).

:::

:::note

A non-player sender is not capable of sending a signed message, which means that the method block inside the `#thenAccept` method of the `SignedMessageResolver#resolve` method
will never be called. You should make sure to put a `.requires(ctx -> ctx.getSender() instanceof Player)` on your SignedArgument to only allow Players to run it. You may
add a fallback greedy string argument for non-player senders if you want the argument to execute regardless of signing or not.

:::

### Example usage
```java title="MinecraftArguments.java"
public static LiteralCommandNode<CommandSourceStack> signedMessageArgument() {
return Commands.literal("signedmessage")
.then(Commands.argument("target", ArgumentTypes.player())
.then(Commands.argument("message", ArgumentTypes.signedMessage())
.executes(MinecraftArguments::executeSignedMessageCommand)))
.build();
}

private static int executeSignedMessageCommand(final CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
final Player target = ctx.getArgument("target", PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()).getFirst();
final SignedMessageResolver messageResolver = ctx.getArgument("message", SignedMessageResolver.class);

messageResolver.resolveSignedMessage("message", ctx).thenAccept(msg -> {
target.sendMessage(msg, ChatType.CHAT.bind(ctx.getSource().getSender().name()));
});


return Command.SINGLE_SUCCESS;
}
```

### In-game preview
<FullWidthVideo src={SignedMessageMp4}/>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading