Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8e2b800
Add documentation for https://github.com/CommandAPI/CommandAPI/pull/517
DerEchtePilz Feb 17, 2025
085078e
Add diff language support
DerEchtePilz Feb 17, 2025
2516a3a
Update mappings preference switch to say "Paper" and "Spigot" instead…
DerEchtePilz Aug 22, 2025
d81cac5
Document the updated config options
DerEchtePilz Aug 22, 2025
7408d7e
Update default configs
DerEchtePilz Aug 22, 2025
759a92c
Rename "mappings" preference to "paper-spigot" and use that on the co…
DerEchtePilz Aug 22, 2025
a3b2790
Finish config page
DerEchtePilz Aug 22, 2025
74134e4
Move documentation code to a new bukkit submodule in preparation for …
DerEchtePilz Sep 11, 2025
4e432e9
Setup buildSrc
DerEchtePilz Sep 11, 2025
e9dfa20
Add empty Paper/Spigot/Velocity modules
DerEchtePilz Sep 11, 2025
5dbe76f
Make Kotlin examples compile
DerEchtePilz Sep 12, 2025
d6abfcf
Make Java examples compile
DerEchtePilz Sep 13, 2025
eb7d287
Update code references
DerEchtePilz Sep 13, 2025
bc22213
Use more Paper/Spigot preference switches
DerEchtePilz Sep 13, 2025
b897923
Update ranged-arguments.md to correctly mention the DoubleRangeArgument
DerEchtePilz Sep 13, 2025
50b2d67
Update entities-arguments.md to now metion PlayerProfileArgument inst…
DerEchtePilz Sep 13, 2025
8476ecf
Update adventure chat arguments page
DerEchtePilz Sep 13, 2025
8390216
Update BlockStateArgument page
DerEchtePilz Sep 13, 2025
a6ce6ad
Replace PlayerArgument with EntitySelectorArgument.OnePlayer where ap…
DerEchtePilz Sep 13, 2025
b1f3688
Update cast table and safe suggestion table
DerEchtePilz Sep 13, 2025
446df85
Update unregistration page
DerEchtePilz Sep 14, 2025
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ reference-code.iml
reference-code/reference-code.iml
reference-code/target
reference-code/build
reference-code/.kotlin
reference-code/.gradle
reference-code/**/build
**/.kotlin
**/.gradle

package-lock.json
.vscode
7 changes: 6 additions & 1 deletion docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ const vitepressOptions: UserConfig = {
}]
}).then(_ => {
})
shiki.loadLanguage({
name: 'diff',
scopeName: 'source.diff'
}).then(_ => {
})
},
config: (md) => {
config: ( md) => {
tabsPlugin(md);
injectUpgradingPartsPlugin(md);
mermaidSpaceConverter(md);
Expand Down
20 changes: 10 additions & 10 deletions docs/.vitepress/theme/preference/PreferenceSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ onMounted(() => {
/>
<label class="groovy-label prefer-label-right" @click="toggleGradleDsl(true)">.gradle</label>
</div>
<div v-if="preferencesToDisplay.includes('mapping')" class="switch-container">
<label class="mojmap-label prefer-label-left" @click="toggleMapping(false)">Mojmap</label>
<div v-if="preferencesToDisplay.includes('paper-spigot')" class="switch-container">
<label class="mojmap-label prefer-label-left" @click="toggleMapping(false)">Paper</label>
<VTSwitch
class="mapping-switch"
aria-label="prefer reobf"
:aria-checked="preferReobf"
@click="toggleMapping()"
/>
<label class="reobf-label prefer-label-right" @click="toggleMapping(true)">Reobf</label>
<label class="reobf-label prefer-label-right" @click="toggleMapping(true)">Spigot</label>
</div>
</div>
</div>
Expand Down Expand Up @@ -272,19 +272,19 @@ onMounted(() => {
<style>
.maven,
.groovy,
.reobf {
.spigot {
display: none;
}

.prefer-maven .gradle,
.prefer-groovy .kts,
.prefer-reobf .mojmap {
.prefer-reobf .paper {
display: none;
}

.prefer-maven .maven,
.prefer-groovy .groovy,
.prefer-reobf .reobf {
.prefer-reobf .spigot {
display: initial;
}

Expand Down Expand Up @@ -319,10 +319,10 @@ onMounted(() => {
.tip .groovy,
.tip .kts,
.tip .maven,
.tip .mojmap,
.tip .reobf {
color: var(--vt-c-text-code);
.tip .paper,
.tip .spigot {
//color: var(--vt-c-text-code);
/* transition: color 0.5s; */
font-weight: 600;
//font-weight: 600;
}
</style>
1 change: 1 addition & 0 deletions docs/.vitepress/theme/upgrading/upgrading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const upgradingInfos: UpgradingInfo[] = [
{from: '9.0.3', to: '9.1.0'},
{from: '9.2.0', to: '9.3.0'},
{from: '9.7.0', to: '10.0.0'},
{from: '10.1.2', to: '11.0.0'}
]

export const keyVersions = Array.from(new Set(upgradingInfos.map(info => [info.from, info.to]).flat()));
Expand Down
32 changes: 16 additions & 16 deletions docs/en/annotations/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ This page outlines in detail the list of all annotations that the CommandAPI's a

The `@Command` annotation is used to declare a command. The parameter is the name of the command that will be registered.

<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#declareCommand
<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#declareCommand

### `@Alias({...})`

The `@Alias` annotation is used to declare a list of aliases for a command. The parameter is a list of aliases which can be used for the command.

<<< @/../reference-code/src/main/java/annotations/aliasClassExample/TeleportCommand.java#aliasClassExample
<<< @/../reference-code/bukkit/src/main/java/annotations/aliasClassExample/TeleportCommand.java#aliasClassExample

### `@Permission("permissionNode")`

The `@Permission` annotation is used to add a permission node to a command. Users that want to run this command must have this permission. The parameter is the permission node required to run the command.

<<< @/../reference-code/src/main/java/annotations/permissionClassExample/TeleportCommand.java#permissionClassExample
<<< @/../reference-code/bukkit/src/main/java/annotations/permissionClassExample/TeleportCommand.java#permissionClassExample

### `@NeedsOp`

The `@NeedsOp` annotation is used to indicate that a command needs to have operator privileges to run it. This annotation has no parameters.

<<< @/../reference-code/src/main/java/annotations/needsOpClassExample/TeleportCommand.java#needsOpClassExample
<<< @/../reference-code/bukkit/src/main/java/annotations/needsOpClassExample/TeleportCommand.java#needsOpClassExample

### `@Help("Full description")`

The `@Help` annotation is used to add a help topic to a command. This annotation can take two forms:

A simple form which just uses a string which is used as the full description for a command:

<<< @/../reference-code/src/main/java/annotations/helpClassExample/TeleportCommand.java#helpClassExample
<<< @/../reference-code/bukkit/src/main/java/annotations/helpClassExample/TeleportCommand.java#helpClassExample

A form with two parameters `value` and `shortDescription`, to provide the full description (`value`) and short description (`shortDescription`) content for a command:

<<< @/../reference-code/src/main/java/annotations/shortHelpClassExample/TeleportCommand.java#shortHelpClassExample
<<< @/../reference-code/bukkit/src/main/java/annotations/shortHelpClassExample/TeleportCommand.java#shortHelpClassExample

## Annotations that go on methods

Expand All @@ -54,27 +54,27 @@ To use annotations on methods, **methods must be static**.

The `@Default` annotation indicates that the method is _not_ a subcommand. This acts in a similar way to regular Bukkit commands. Commands with the `@Default` annotation can be used to run the main code when the command named with the `@Command` annotation is stated, such as the following:

<<< @/../reference-code/src/main/java/annotations/DefaultMethodExample.java#defaultMethodExample
<<< @/../reference-code/bukkit/src/main/java/annotations/DefaultMethodExample.java#defaultMethodExample

The `@Default` annotation does not mean that the command can't have arguments! Arguments can still be used and declared as shown:

<<< @/../reference-code/src/main/java/annotations/DefaultMethodExample.java#defaultWithArgsMethodExample
<<< @/../reference-code/bukkit/src/main/java/annotations/DefaultMethodExample.java#defaultWithArgsMethodExample

### `@Subcommand`

The `@Subcommand` simply tells the CommandAPI that the declared method is a subcommand. This acts in a similar way to the regular CommandAPI's `.withSubcommand()` method. The subcommand annotation can take in a single string which is the name of the subcommand:

<<< @/../reference-code/src/main/java/annotations/SubcommandMethodExample.java#subcommandMethodExample
<<< @/../reference-code/bukkit/src/main/java/annotations/SubcommandMethodExample.java#subcommandMethodExample

Or, it can take in a list of strings which represent the _aliases_ that can also be used for the declared subcommand:

<<< @/../reference-code/src/main/java/annotations/SubcommandMethodExample.java#subcommandAliasesMethodExample
<<< @/../reference-code/bukkit/src/main/java/annotations/SubcommandMethodExample.java#subcommandAliasesMethodExample

### `@Permission`

The `@Permission` annotation can also be used on methods to indicate that a permission is required to execute a command.

<<< @/../reference-code/src/main/java/annotations/PermissionMethodExample.java#permissionMethodExample
<<< @/../reference-code/bukkit/src/main/java/annotations/PermissionMethodExample.java#permissionMethodExample

### `@NeedsOp`

Expand All @@ -88,14 +88,14 @@ The annotations for arguments are really simple, there are just two things you n

$$\begin{align}
\texttt{StringArgument}&\xrightarrow{A}\texttt{@AStringArgument}\\\\
\texttt{PlayerArgument}&\xrightarrow{A}\texttt{@APlayerArgument}\\\\
\texttt{IntegerArgument}&\xrightarrow{A}\texttt{@AIntegerArgument}\\\\
\texttt{AdvancementArgument}&\xrightarrow{A}\texttt{@AAdvancementArgument}\\\\
&\hspace{0.75em}\vdots
\end{align}$$

For example, we use `@AStringArgument` to indicate that this command takes a `StringArgument` as its first parameter:

<<< @/../reference-code/src/main/java/annotations/ParameterExample.java#simpleParameterExample
<<< @/../reference-code/bukkit/src/main/java/annotations/ParameterExample.java#simpleParameterExample

- **The name of the argument (referred to as "nodeName" in the normal CommandAPI system) is the name of the variable assigned to the parameter.** In the above code, this means that the name of the argument is `warpName`.

Expand All @@ -107,18 +107,18 @@ Certain argument annotations have extra parameters that can be supplied to provi

The following numerical arguments can take both a `min` and `max` value. Both of these are completely optional. This indicates the range of values (inclusive) that is valid for this argument. For example:

<<< @/../reference-code/src/main/java/annotations/ParameterExample.java#numericalParameterExample
<<< @/../reference-code/bukkit/src/main/java/annotations/ParameterExample.java#numericalParameterExample

#### Literal arguments

Both the `LiteralArgument` and `MultiLiteralArgument` can be used. When these are used, the name of the variable assigned to the parameter is _ignored_ and not used as the argument's name.

For the `@ALiteralArgument` annotation, the parameter is the literal to be used for the command. For the `@AMultiLiteralArgument`, the parameter can be an array of multiple literals to use:

<<< @/../reference-code/src/main/java/annotations/ParameterExample.java#literalParameterExample
<<< @/../reference-code/bukkit/src/main/java/annotations/ParameterExample.java#literalParameterExample

#### Other arguments

The `LocationArgument`, `Location2DArgument`, `EntitySelectorArgument` and `ScoreHolderArgument` can all take an extra parameter in their constructors. As a result, the annotation-equivalent of these arguments also allow you to provide the parameter in the annotation:

<<< @/../reference-code/src/main/java/annotations/ParameterExample.java#otherParameterExample
<<< @/../reference-code/bukkit/src/main/java/annotations/ParameterExample.java#otherParameterExample
16 changes: 8 additions & 8 deletions docs/en/annotations/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,38 @@ Let's say we're writing a plugin with the capability to create warps to places o

Using the regular CommandAPI, this is one way we can create this command. In the code below, we use StringArguments to represent the warp names. To teleport to a warp, we also populate it with suggestions (deferred so it updates), and also use a subcommand to represent `/warp create`:

<<< @/../reference-code/src/main/java/annotations/Intro.java#legacyExample
<<< @/../reference-code/bukkit/src/main/java/annotations/Intro.java#legacyExample

Seems fairly straightforward, given everything else covered in this documentation. Now let's compare it to using annotations!

### Warp command (with annotations)

I think it's best to show the example and explain it afterwards:

<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#annotationsExample
<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#annotationsExample

<<< @/../reference-code/src/main/java/annotations/Intro.java#annotationsRegisterExample
<<< @/../reference-code/bukkit/src/main/java/annotations/Intro.java#annotationsRegisterExample

As we can see, the code certainly _looks_ very different to the normal registration method. Let's take it apart piece by piece to see what exactly is going on here.

#### Command declaration

<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#declareCommand
<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#declareCommand

Firstly, we declare our command `warp`. To do this, we use the `@Command` annotation and simply state the name of the command in the annotation. This annotation is attached to the class `WarpCommand`, which indicates that the whole class `WarpCommand` will be housing our command.

The annotation framework is designed in such a way that an entire command is represented by a single class. This provides a more modular approach to command declaration that allows you to easily contain the methods of a command in one location.

#### Default command
<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#defaultExample
<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#defaultExample

Here, declare the main command implementation using the `@Default` annotation. The `@Default` annotation informs the CommandAPI that the method it is attached to does not have any subcommands. This is effectively the same as registering a regular command without using `.withSubcommand()`.

Here, we simply write what happens when no arguments are run (i.e. the user just runs `/warp` on its own). As such, we don't include any parameters to our method.

#### Default command (again!)

<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#anotherDefaultExample
<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#anotherDefaultExample

We also have a second `@Default` annotated method, which handles our `/warp <warp>` command. Because this isn't a subcommand (the warp to teleport to is not a subcommand, it's an argument), we're still using the `@Default` annotation. In this method, we include an argument with this command by using the `@AStringArgument` annotation. This argument uses the `StringArgument` class, and the name of this argument is "warpName", which is extracted from the name of the variable. Simply put, **the Annotation for an argument is A** followed by the name of the argument. This is synonymous with using the following:

Expand All @@ -88,14 +88,14 @@ The second argument is a `String` object, which represents the result of our arg

#### Subcommand

<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#subcommandExample
<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#subcommandExample

Lastly, we declare a subcommand to allow us to run `/warp create <name>`. To do this, we simply use the `@Subcommand` annotation. In this example, we also apply a permission node that is required to run the command by using the `@Permission` annotation. The rest is fairly straight forward - we declare an argument, in this case it's another `StringArgument` , so we use `@AStringArgument` and then declare everything else in a similar fashion to the default command executor.

#### Registering the command

Registering the command is fairly simple and is a one-liner:

<<< @/../reference-code/src/main/java/annotations/Intro.java#annotationsRegisterExample
<<< @/../reference-code/bukkit/src/main/java/annotations/Intro.java#annotationsRegisterExample

This line can be placed in your `onEnable()` or `onLoad()` method like you were registering a normal command.
4 changes: 2 additions & 2 deletions docs/en/annotations/registration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ CommandAPI.registerCommand(className)

Say we have a simple command `/warp` that is defined as follows:

<<< @/../reference-code/src/main/java/annotations/WarpCommand.java#annotationsExample
<<< @/../reference-code/bukkit/src/main/java/annotations/WarpCommand.java#annotationsExample

We can register this in our `onLoad()` method so we can use this command from within Minecraft functions:

<<< @/../reference-code/src/main/java/annotations/Registration.java#registerCommand
<<< @/../reference-code/bukkit/src/main/java/annotations/Registration.java#registerCommand

::::
6 changes: 3 additions & 3 deletions docs/en/create-commands/aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ In this example, we register the command `/getpos` that returns the command send

:::tabs
===Java
<<< @/../reference-code/src/main/java/createcommands/Aliases.java#aliasesExample
<<< @/../reference-code/bukkit/src/main/java/createcommands/Aliases.java#aliasesExample
===Kotlin
<<< @/../reference-code/src/main/kotlin/createcommands/Aliases.kt#aliasesExample
<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Aliases.kt#aliasesExample
===Kotlin DSL
<<< @/../reference-code/src/main/kotlin/createcommands/Aliases.kt#aliasesExampleDSL
<<< @/../reference-code/bukkit/src/main/kotlin/createcommands/Aliases.kt#aliasesExampleDSL
:::

::::
Loading