Skip to content

Commit

Permalink
Update documentation references and some other minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DerEchtePilz committed Jul 24, 2024
1 parent b0b9e1c commit 4625a32
Show file tree
Hide file tree
Showing 20 changed files with 385 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import de.tr7zw.changeme.nbtapi.NBTContainer;
import dev.jorel.commandapi.Brigadier;
import dev.jorel.commandapi.BukkitTooltip;
import dev.jorel.commandapi.CommandAPI;
Expand Down Expand Up @@ -68,6 +69,7 @@
import dev.jorel.commandapi.arguments.MapArgumentBuilder;
import dev.jorel.commandapi.arguments.MathOperationArgument;
import dev.jorel.commandapi.arguments.MultiLiteralArgument;
import dev.jorel.commandapi.arguments.NBTCompoundArgument;
import dev.jorel.commandapi.arguments.ObjectiveArgument;
import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument;
import dev.jorel.commandapi.arguments.ParticleArgument;
Expand Down Expand Up @@ -731,6 +733,19 @@ void argument_multiLiteral() {
/* ANCHOR_END: argumentMultiLiteral1 */
}

void argument_nbt2() {
/* ANCHOR: argumentNBT2 */
new CommandAPICommand("award")
.withArguments(new NBTCompoundArgument<NBTContainer>("nbt"))
.executes((sender, args) -> {
NBTContainer nbt = (NBTContainer) args.get("nbt");

// Do something with "nbt" here...
})
.register();
/* ANCHOR_END: argumentNBT2 */
}

void argument_objectives() {
/* ANCHOR: argumentObjectives1 */
new CommandAPICommand("sidebar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,19 @@ CommandAPICommand("gamemode")
/* ANCHOR_END: argumentMultiLiteral1 */
}

fun argument_nbt2() {
/* ANCHOR: argumentNBT2 */
CommandAPICommand("award")
.withArguments(NBTCompoundArgument<NBTContainer>("nbt"))
.executes(CommandExecutor { _, args ->
val nbt = args["nbt"] as NBTContainer

// Do something with "nbt" here...
})
.register()
/* ANCHOR_END: argumentNBT2 */
}

fun argument_objectives() {
/* ANCHOR: argumentObjectives1 */
CommandAPICommand("sidebar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public abstract class CommandAPIBukkitConfig<T extends CommandAPIBukkitConfig<T>
JavaPlugin plugin;

// Default configuration
boolean shouldHookPaperReload = true;
boolean skipReloadDatapacks = false;

/**
Expand Down Expand Up @@ -70,6 +69,11 @@ public T setNamespace(String namespace) {
return super.setNamespace(namespace);
}

public T skipReloadDatapacks(boolean skip) {
this.skipReloadDatapacks = skip;
return instance();
}

@Override
public abstract T instance();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public CommandAPIPaperConfig shouldHookPaperReload(boolean hooked) {
* @return this CommandAPIBukkitConfig
*/
public CommandAPIPaperConfig skipReloadDatapacks(boolean skip) {
this.skipReloadDatapacks = skip;
return this;
return super.skipReloadDatapacks(skip);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,6 @@ public void onLoad() {
);
}
/* ANCHOR_END: argumentNBT1 */

void argument_nbt2() {
/* ANCHOR: argumentNBT2 */
new CommandAPICommand("award")
.withArguments(new NBTCompoundArgument<NBTContainer>("nbt"))
.executes((sender, args) -> {
NBTContainer nbt = (NBTContainer) args.get("nbt");

// Do something with "nbt" here...
})
.register();
/* ANCHOR_END: argumentNBT2 */
}
}

void chatPreview() {
Expand Down Expand Up @@ -158,8 +145,8 @@ public void onEnable() {

@Override
public void onDisable() {
CommandAPI.onDisable();
}
CommandAPI.onDisable();
}

}
/* ANCHOR_END: setupShading2 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,6 @@ override fun onLoad() {
}
/* ANCHOR_END: argumentNBT1 */

fun argument_nbt2() {
/* ANCHOR: argumentNBT2 */
CommandAPICommand("award")
.withArguments(NBTCompoundArgument<NBTContainer>("nbt"))
.executes(CommandExecutor { _, args ->
val nbt = args["nbt"] as NBTContainer

// Do something with "nbt" here...
})
.register()
/* ANCHOR_END: argumentNBT2 */
}

}

fun chatPreview() {
Expand Down Expand Up @@ -127,9 +114,9 @@ class setupShading {
val plugin: JavaPlugin = object : JavaPlugin() {}

fun setupShading1() {
/* ANCHOR: setupShading1 */
CommandAPI.onLoad(CommandAPIPaperConfig(plugin).silentLogs(true))
/* ANCHOR_END: setupShading1 */
/* ANCHOR: setupShading1 */
CommandAPI.onLoad(CommandAPIPaperConfig(plugin).silentLogs(true))
/* ANCHOR_END: setupShading1 */
}

/* ANCHOR: setupShading2 */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dev.jorel.commandapi.examples.kotlin

import de.tr7zw.changeme.nbtapi.NBTContainer
import dev.jorel.commandapi.kotlindsl.anyExecutor
import dev.jorel.commandapi.kotlindsl.chatArgument
import dev.jorel.commandapi.kotlindsl.chatColorArgument
import dev.jorel.commandapi.kotlindsl.chatComponentArgument
import dev.jorel.commandapi.kotlindsl.commandAPICommand
import dev.jorel.commandapi.kotlindsl.nbtCompoundArgument
import dev.jorel.commandapi.kotlindsl.playerArgument
import dev.jorel.commandapi.kotlindsl.playerExecutor
import dev.jorel.commandapi.kotlindsl.stringArgument
Expand Down Expand Up @@ -62,4 +64,17 @@ commandAPICommand("pbroadcast") {
/* ANCHOR_END: argumentChatAdventure3 */
}

fun argument_nbt() {
/* ANCHOR: argumentNBT1 */
commandAPICommand("award") {
nbtCompoundArgument<NBTContainer>("nbt")
anyExecutor { _, args ->
val nbt = args["nbt"] as NBTContainer

// Do something with "nbt" here...
}
}
/* ANCHOR_END: argumentNBT1 */
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public CommandAPISpigotConfig(JavaPlugin plugin) {
* @return this CommandAPIBukkitConfig
*/
public CommandAPISpigotConfig skipReloadDatapacks(boolean skip) {
this.skipReloadDatapacks = skip;
return this;
return super.skipReloadDatapacks(skip);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,6 @@ public void onLoad() {
);
}
/* ANCHOR_END: argumentNBT1 */

void argument_nbt2() {
/* ANCHOR: argumentNBT2 */
new CommandAPICommand("award")
.withArguments(new NBTCompoundArgument<NBTContainer>("nbt"))
.executes((sender, args) -> {
NBTContainer nbt = (NBTContainer) args.get("nbt");

// Do something with "nbt" here...
})
.register();
/* ANCHOR_END: argumentNBT2 */
}
}

void chatPreview() {
Expand All @@ -110,7 +97,7 @@ void chatPreview() {
.register();
/* ANCHOR_END: chatPreview1 */

/* ANCHOR: chatPreview3 */
/* ANCHOR: chatPreview2 */
new CommandAPICommand("broadcast")
.withArguments(new ChatArgument("message").usePreview(true).withPreview(info -> {
// Convert parsed BaseComponent[] to plain text
Expand All @@ -123,17 +110,17 @@ void chatPreview() {
Bukkit.spigot().broadcast((BaseComponent[]) args.get("message"));
})
.register();
/* ANCHOR_END: chatPreview3 */
/* ANCHOR_END: chatPreview2 */
}

class setupShading {
JavaPlugin plugin = new JavaPlugin() {
};

{
/* ANCHOR: setupShading1 */
CommandAPI.onLoad(new CommandAPISpigotConfig(plugin).silentLogs(true));
/* ANCHOR_END: setupShading1 */
/* ANCHOR: setupShading1 */
CommandAPI.onLoad(new CommandAPISpigotConfig(plugin).silentLogs(true));
/* ANCHOR_END: setupShading1 */
}

/* ANCHOR: setupShading2 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,6 @@ override fun onLoad() {
)
}
/* ANCHOR_END: argumentNBT1 */

fun argument_nbt2() {
/* ANCHOR: argumentNBT2 */
CommandAPICommand("award")
.withArguments(NBTCompoundArgument<NBTContainer>("nbt"))
.executes(CommandExecutor { _, args ->
val nbt = args["nbt"] as NBTContainer

// Do something with "nbt" here...
})
.register()
/* ANCHOR_END: argumentNBT2 */
}

}

fun chatPreview() {
Expand Down Expand Up @@ -132,9 +118,9 @@ class setupShading {
val plugin: JavaPlugin = object : JavaPlugin() {}

fun setupShading1() {
/* ANCHOR: setupShading1 */
CommandAPI.onLoad(CommandAPISpigotConfig(plugin).silentLogs(true))
/* ANCHOR_END: setupShading1 */
/* ANCHOR: setupShading1 */
CommandAPI.onLoad(CommandAPISpigotConfig(plugin).silentLogs(true))
/* ANCHOR_END: setupShading1 */
}

/* ANCHOR: setupShading2 */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.jorel.commandapi.examples.kotlin

import de.tr7zw.changeme.nbtapi.NBTContainer
import dev.jorel.commandapi.executors.CommandArguments
import dev.jorel.commandapi.kotlindsl.*
import net.md_5.bungee.api.chat.BaseComponent
Expand Down
36 changes: 19 additions & 17 deletions docssrc/src/argument_chat_adventure.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Adventure chat arguments

> **Developer's Note:**
>
> The two following classes, `AdventureChatComponentArgument` and `AdventureChatArgument` depend on a Paper based server which has the Adventure library. If you use this class on a server without the Adventure library, it will throw a `PaperAdventureNotFoundException`
From Paper 1.16.5 build #473 onwards, Paper now includes [Kyori's Adventure API](https://github.com/KyoriPowered/adventure-platform). This library is a replacement of the BungeeCord chat API and has all of the same functionality as the BungeeCord chat API (and more!). The documentation for this API can be found [here](https://docs.adventure.kyori.net/index.html).

Since this functions very similar to the Spigot chat arguments, this page won't reiterate everything about how it works, we'll just outline some examples of how to use these arguments instead.
Additionally, the names used here may be confusing as they are the same names as on the [Spigot chat arguments](./argument_chat_spigot.md) page but have different return types. This is because the classes on this page are only accessible using `commandapi-paper-core` or `commandapi-paper-shade`
while the arguments on the Spigot chat arguments page are only available when using `commandapi-spigot-core` or `commandapi-spigot-shade`.

> **Developer's Note:**
>
> The three following classes, `ChatColorArgument`, `ChatComponentArgument` and `ChatArgument` depend on a Paper based server which has the Adventure library. If you use this class on a server without the Adventure library, it will throw a `PaperAdventureNotFoundException`
-----

## Adventure chat color argument

![Chatcolor argument in-game, displaying a list of Minecraft chat colors](./images/arguments/chatcolor.png)

The `AdventureChatColorArgument` class is used to represent a given chat color (e.g. red or green). This argument returns the `NamedTextColor` object. If `reset` is passed to this argument, this will return `NamedTextColor.WHITE`.
The `ChatColorArgument` class is used to represent a given chat color (e.g. red or green). This argument returns the `NamedTextColor` object. If `reset` is passed to this argument, this will return `NamedTextColor.WHITE`.

<div class="example">

Expand All @@ -31,15 +33,15 @@ We then use the `ChatColorArgument` to change the player's name color:
<div class="multi-pre">

```java,Java
{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure1}}
{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure1}}
```

```kotlin,Kotlin
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure1}}
{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure1}}
```

```kotlin,Kotlin_DSL
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure1}}
{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure1}}
```

</div>
Expand All @@ -50,7 +52,7 @@ We then use the `ChatColorArgument` to change the player's name color:

## Adventure chat component argument

The `AdventureChatComponentArgument` class accepts raw chat-based JSON as valid input, as declared [here](https://minecraft.wiki/w/Raw_JSON_text_format). This is converted into Adventure's `Component` class.
The `ChatComponentArgument` class accepts raw chat-based JSON as valid input, as declared [here](https://minecraft.wiki/w/Raw_JSON_text_format). This is converted into Adventure's `Component` class.

<div class="example">

Expand All @@ -67,15 +69,15 @@ We can construct a book using the Adventure API's `Book.book(Component, Componen
<div class="multi-pre">

```java,Java
{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure2}}
{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure2}}
```

```kotlin,Kotlin
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure2}}
{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure2}}
```

```kotlin,Kotlin_DSL
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure2}}
{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure2}}
```

</div>
Expand All @@ -86,13 +88,13 @@ We can construct a book using the Adventure API's `Book.book(Component, Componen

## Adventure chat argument

The `AdventureChatArgument` class is the equivalent Adventure API class for the `ChatArgument` - it represents infinitely long strings similar to the `GreedyStringArgument` and allows entity selectors such as `@e`, `@p` and so on. The `AdventureChatArgument` returns a `Component`, similar to the `AdventureChatComponentArgument`.
The `ChatArgument` represents infinitely long strings similar to the `GreedyStringArgument` and allows entity selectors such as `@e`, `@p` and so on. The `ChatArgument` returns a `Component`, similar to the `ChatComponentArgument`.

<div class="example">

### Example - Sending personalized messages to players

We'll take the same example from the `ChatArgument` class, but using the `AdventureChatArgument` instead - We want to create a personalized message broadcasted to all users using a chat component that allows entity selectors. For this command, we want the following syntax:
We want to create a personalized message broadcasted to all users using a chat component that allows entity selectors. For this command, we want the following syntax:

```mccmd
/pbroadcast <message>
Expand All @@ -103,15 +105,15 @@ In order to broadcast an Adventure `Component` to all players on the server, we
<div class="multi-pre">

```java,Java
{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure3}}
{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure3}}
```

```kotlin,Kotlin
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure3}}
{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure3}}
```

```kotlin,Kotlin_DSL
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure3}}
{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure3}}
```

</div>
Expand Down
Loading

0 comments on commit 4625a32

Please sign in to comment.