From 7d664b63ba535f982935e6efcc0f1e699bb0117b Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Wed, 26 Mar 2025 00:26:38 +0000 Subject: [PATCH] Rework NBT argument documentation to include Mojang-mapped examples and include Rtag examples --- .../arguments/types/nbt-arguments.md | 71 -------------- .../arguments/types/nbt/index.md | 4 + .../arguments/types/nbt/nbt-arguments.md | 64 +++++++++++++ .../arguments/types/nbt/nbt-nbtapi.md | 40 ++++++++ .../arguments/types/nbt/nbt-rtag.md | 87 +++++++++++++++++ .../arguments/types/predicate/index.md | 2 +- reference-code/build.gradle.kts | 13 +++ reference-code/gradle/libs.versions.toml | 4 +- .../arguments/types/NBTArguments.java | 70 +++++++++++++- .../arguments/types/NBTArguments.kt | 93 +++++++++++++++++-- 10 files changed, 361 insertions(+), 87 deletions(-) delete mode 100644 docs/en/create-commands/arguments/types/nbt-arguments.md create mode 100644 docs/en/create-commands/arguments/types/nbt/index.md create mode 100644 docs/en/create-commands/arguments/types/nbt/nbt-arguments.md create mode 100644 docs/en/create-commands/arguments/types/nbt/nbt-nbtapi.md create mode 100644 docs/en/create-commands/arguments/types/nbt/nbt-rtag.md diff --git a/docs/en/create-commands/arguments/types/nbt-arguments.md b/docs/en/create-commands/arguments/types/nbt-arguments.md deleted file mode 100644 index 42276d962..000000000 --- a/docs/en/create-commands/arguments/types/nbt-arguments.md +++ /dev/null @@ -1,71 +0,0 @@ ---- -order: 11 -authors: - - JorelAli - - willkroboth - - DerEchtePilz ---- - -# NBT arguments - -The CommandAPI includes support for NBT compound arguments using an NBT API. The usage for the `NBTCompoundArgument` depends on whether you are using the CommandAPI plugin (using a `CommandAPI.jar` file in your `plugins/` folder), or are shading the CommandAPI (including the compiled CommandAPI code in your own plugin). - -## Shading usage setup - -In order to use the `NBTCompoundArgument`, you will have to use an NBT API that can create an NBT Compound object from an `Object` (ideally a `net.minecraft.nbt.NBTTagCompound` object). Examples of NBT APIs that can do this are _(these are not sponsored in any way)_: - -- [NBT API](https://www.spigotmc.org/resources/nbt-api.7939/), via the [`new NBTContainer(Object)`](https://tr7zw.github.io/Item-NBT-API/v2-api/de/tr7zw/changeme/nbtapi/NBTContainer.html#NBTContainer-java.lang.Object-) constructor - -### Hooking into an NBT API - -Before the `NBTCompoundArgument` can be used, the CommandAPI needs to know what implementation of an NBT Compound object you're going to use. This is specified in the `onLoad()` sequence, where your CommandAPI's config is set up, by using the following method: - -```java - CommandAPIConfig initializeNBTAPI(Class nbtContainerClass, Function nbtContainerConstructor); -``` - -The `initializeNBTAPI(Class, Function)` takes in two arguments: - -- `Class` - The class that will be your NBT Compound implementation. This is also the type that the CommandAPI will return when the `NBTCompoundArgument` is used. - -- `Function` - A function that takes in an object and returns the specified NBT Compound implementation. This could be a constructor or a static method, for example. - -::::tip Example – Hooking into the NBT API - -Say we want to use the [NBT API](https://www.spigotmc.org/resources/nbt-api.7939/) as our implementation of NBT compounds. First, we have to shade the NBT API into our project (view the official documentation for how to do this for [Maven](https://github.com/tr7zw/Item-NBT-API/wiki/Using-Maven#option-2-shading-the-nbt-api-into-your-plugin) or [Gradle](https://github.com/tr7zw/Item-NBT-API/wiki/Using-Gradle#option-2-shading-the-nbt-api-into-your-plugin)). - -Now, we can configure the CommandAPI using the `CommandAPI.onLoad()` method to use the `NBTContainer` class, and the [`NBTContainer` constructor that takes in an `Object`](https://tr7zw.github.io/Item-NBT-API/v2-api/de/tr7zw/changeme/nbtapi/NBTContainer.html#NBTContainer-java.lang.Object-): - -:::tabs -===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java#hookNbtAPIExample -===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#hookNbtAPIExample -::: - -> _Confused with the `::new` syntax? Read more about method references to a constructor [here](https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html)._ - -We're now able to use the `NBTContainer` as our implemented type for the `NBTCompoundArgument`! - -:::: - -::::tip Example – ??? - -Since the underlying implementation of the `NBTCompoundArgument` can change (e.g. `NBTContainer` if you're using the NBT API), the type of your NBT compound implementation has to be declared in angle brackets. - -:::tabs -===Java -<<< @/../reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java#nbtCompoundArgumentsExample -===Kotlin -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExample -===Kotlin DSL -<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExampleDSL -::: - -:::: - -:::info - -If you believe you can supply a suitable example for this page, feel free to send an example [on the CommandAPI issues page!](https://github.com/CommandAPI/CommandAPI/issues/new/choose) - -::: \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/nbt/index.md b/docs/en/create-commands/arguments/types/nbt/index.md new file mode 100644 index 000000000..02341db71 --- /dev/null +++ b/docs/en/create-commands/arguments/types/nbt/index.md @@ -0,0 +1,4 @@ +--- +order: 10 +title: NBT arguments +--- \ No newline at end of file diff --git a/docs/en/create-commands/arguments/types/nbt/nbt-arguments.md b/docs/en/create-commands/arguments/types/nbt/nbt-arguments.md new file mode 100644 index 000000000..e2bd275cb --- /dev/null +++ b/docs/en/create-commands/arguments/types/nbt/nbt-arguments.md @@ -0,0 +1,64 @@ +--- +order: 1 +authors: + - JorelAli + - willkroboth + - DerEchtePilz +--- + +# NBT arguments + +The CommandAPI has support for arguments that interact with Minecraft's [NBT format](https://minecraft.wiki/w/NBT_format). Since Minecraft's NBT format is not directly accessible via Spigot (it is instead implemented via Spigot's APIs when necessary), using NBT-based arguments requires an implementation of an NBT API that is capable of interpreting NMS NBT objects. + +## Shading usage setup + +In order to use the `NBTCompoundArgument`, you can an NBT API that can create an NBT Compound object from an `Object` (ideally a `net.minecraft.nbt.NBTTagCompound` object). Examples of NBT APIs that can do this are _(these are not sponsored in any way)_: + +- Mojang-mapped plugins, via `net.minecraft.nbt.CompoundTag` +- [NBT API](https://www.spigotmc.org/resources/nbt-api.7939/) +- [Rtag](https://www.spigotmc.org/resources/100694/) + +## Hooking into an NBT API + +Before the `NBTCompoundArgument` can be used, the CommandAPI needs to know what implementation of an NBT Compound object you're going to use. This is specified in the `onLoad()` sequence, where your CommandAPI's config is set up, by using the following method: + +```java + CommandAPIConfig initializeNBTAPI(Class nbtContainerClass, Function nbtContainerConstructor); +``` + +The `initializeNBTAPI(Class, Function)` takes in two arguments: + +- `Class` - The class that will be your NBT Compound implementation. This is also the type that the CommandAPI will return when the `NBTCompoundArgument` is used. + +- `Function` - A function that takes in an object and returns the specified NBT Compound implementation. This could be a constructor or a static method, for example. + +## Using Minecraft's NBT objects + +The CommandAPI allows you to access the NMS `NBTTagCompound` class via `net.minecraft.nbt.NBTTagCompound` directly without requiring any additional APIs to access NBT. This is especially useful for Mojang-mapped servers. + +| Spigot-mapped name | Mojang-mapped name | +|--------------------|--------------------| +| `NBTTagCompound` | `CompoundTag` | +| `NBTBase` | `Tag` | + +:::tabs +===Java +<<< @/../reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java#hookNbtAPIExampleMojang +===Kotlin +<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#hookNbtAPIExampleMojang +::: + +::::tip Example – Using a Mojang-mapped `CompoundTag` + +Since the underlying implementation of the `NBTCompoundArgument` can change (for example, `CompoundTag` if you're using Mojang-mapped names), the type of your NBT compound implementation has to be declared in angle brackets. + +:::tabs +===Java +<<< @/../reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java#nbtCompoundArgumentsExampleMojang +===Kotlin +<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExampleMojang +===Kotlin DSL +<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExampleMojangDSL +::: + +:::: diff --git a/docs/en/create-commands/arguments/types/nbt/nbt-nbtapi.md b/docs/en/create-commands/arguments/types/nbt/nbt-nbtapi.md new file mode 100644 index 000000000..a3ae7ae20 --- /dev/null +++ b/docs/en/create-commands/arguments/types/nbt/nbt-nbtapi.md @@ -0,0 +1,40 @@ +--- +order: 2 +authors: + - JorelAli +--- + +# NBT API + +[NBT API](https://www.spigotmc.org/resources/nbt-api.7939/) is an API that can be run as a standalone plugin on a server, or shaded into your own plugin to allow you to easily interact with NBT. + +## Setup + +The NBT API can be shaded into your project as stated in its official documentation: + +- Shading using [Maven](https://github.com/tr7zw/Item-NBT-API/wiki/Using-Maven#option-2-shading-the-nbt-api-into-your-plugin) +- Shading using [Gradle](https://github.com/tr7zw/Item-NBT-API/wiki/Using-Gradle#option-2-shading-the-nbt-api-into-your-plugin) + +You can configure the CommandAPI using the `CommandAPI.onLoad()` method to use the `ReadWriteNBT` class using the [`NBT#wrapNMSTag`](https://tr7zw.github.io/Item-NBT-API/v2-api/de/tr7zw/changeme/nbtapi/NBT.html#wrapNMSTag-java.lang.Object-) method that wraps `net.minecraft.nbt.CompoundTag` objects into NBTAPI `ReadWriteNBT` objects: + +:::tabs +===Java +<<< @/../reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java#hookNbtAPIExample +===Kotlin +<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#hookNbtAPIExample +::: + +## Using `ReadWriteNBT` to handle NBT + +::::tip Example – Reading NBT Compounds using `ReadWriteNBT` + +:::tabs +===Java +<<< @/../reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java#nbtCompoundArgumentsExampleNBTAPI +===Kotlin +<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExampleNBTAPI +===Kotlin DSL +<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExampleNBTAPIDSL +::: + +:::: diff --git a/docs/en/create-commands/arguments/types/nbt/nbt-rtag.md b/docs/en/create-commands/arguments/types/nbt/nbt-rtag.md new file mode 100644 index 000000000..493fe1f4b --- /dev/null +++ b/docs/en/create-commands/arguments/types/nbt/nbt-rtag.md @@ -0,0 +1,87 @@ +--- +order: 3 +authors: + - JorelAli +--- + +# RTag + +[Rtag](https://www.spigotmc.org/resources/100694/) is a shadeable API that allows you to easily interact with NBT. There are multiple ways to deconstruct NBT arguments using Rtag. + +## Accessing individual paths using `Rtag.INSTANCE.get()` + +The [`Rtag#get`](https://javadoc.saicone.com/rtag/com/saicone/rtag/Rtag.html#get(java.lang.Object,java.lang.Object...)) method allows you to retrieve objects directly from an NMS `NBTTagCompound` object without requiring you to import `net.minecraft.net.NBTTagCompound`. We can initialize an NBTAPI by using an `Object` class, and using the identity function (to take the NMS object from the CommandAPI and keep it as an NMS object): + +:::tabs +===Java +<<< @/../reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java#hookNbtAPIExampleRtag +===Kotlin +<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#hookNbtAPIExampleRtag +::: + +::::tip Example - Accessing NBT compound tags directly with `Rtag#get` + +For example, if you have an NBT compound tag with this data: + +```js +{ + some: { + path: { + here: "hello" + } + } +} +``` + +You can access the string value `hello` using `Rtag.INSTANCE.get()`: + +:::tabs +===Java +<<< @/../reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java#nbtCompoundArgumentsExampleRtagPath +===Kotlin +<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExampleRtagPath +===Kotlin DSL +<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#nbtCompoundArgumentsExampleRtagPathDSL +::: + +:::: + +## Converting a compound tag into standard Java objects + +The easiest way to interact with Rtag is to deconstruct a compound tag into a `Map` of Java objects. Rtag is able to do this easily using `TagCompound#getValue`, with the `Rtag.INSTANCE` field, allowing you to initialize an NBT API as follows: + + +:::tabs +===Java +<<< @/../reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java#hookNbtAPIExampleRtagObjects +===Kotlin +<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt#hookNbtAPIExampleRtagObjects +::: + +Say you have an NBT compound tag that looks like this: + +```js +{ + name: "Notch", + exp: 20s, + armor: ["diamond_helmet", "elytra", "diamond_leggings", "leather_boots"], + hand_item: { + type: "diamond_pickaxe", + durability: 123 + } +} +``` + +Using Rtag's representation of an NBT compound tag using standard Java objects would convert the above NBT compound tag into the following object: + +```java +Map { + "name": String "Notch", + "exp": Short 20, + "armor": List ["diamond_helmet", "elytra", "diamond_leggings", "leather_boots"], + "hand_item": Map { + "type": String "diamond_pickaxe", + "durability": Integer 123 + } +} +``` diff --git a/docs/en/create-commands/arguments/types/predicate/index.md b/docs/en/create-commands/arguments/types/predicate/index.md index 4196d4684..022c293ff 100644 --- a/docs/en/create-commands/arguments/types/predicate/index.md +++ b/docs/en/create-commands/arguments/types/predicate/index.md @@ -1,4 +1,4 @@ --- -order: 10 +order: 11 title: Predicate arguments --- \ No newline at end of file diff --git a/reference-code/build.gradle.kts b/reference-code/build.gradle.kts index 46d21eebc..4e1501c34 100644 --- a/reference-code/build.gradle.kts +++ b/reference-code/build.gradle.kts @@ -24,6 +24,10 @@ repositories { url = uri("https://repo.codemc.org/repository/maven-public/") } + maven { + url = uri("https://repo.codemc.io/repository/nms/") + } + maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") } @@ -31,6 +35,11 @@ repositories { maven { url = uri("https://repo.maven.apache.org/maven2/") } + + maven { + url = uri("https://jitpack.io") + } + } dependencies { @@ -40,6 +49,7 @@ dependencies { api(libs.dev.jorel.commandapi.annotations) compileOnly(libs.dev.jorel.commandapi.velocity.shade) api(libs.de.tr7zw.item.nbt.api) + api(libs.com.saicone.rtag) api(libs.org.jetbrains.kotlin.kotlin.stdlib) testImplementation(libs.org.junit.jupiter.junit.jupiter) testImplementation(libs.dev.jorel.commandapi.bukkit.test.toolkit) @@ -48,6 +58,9 @@ dependencies { compileOnly(libs.com.mojang.authlib) compileOnly(libs.io.papermc.paper.paper.api) compileOnly(libs.com.velocitypowered.velocity.api) + + // Apologies to whoever discovers I added this heinous dependency here + api("org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:remapped-mojang") } group = "dev.jorel.commandapi" diff --git a/reference-code/gradle/libs.versions.toml b/reference-code/gradle/libs.versions.toml index aed5bdd10..3811f26f8 100644 --- a/reference-code/gradle/libs.versions.toml +++ b/reference-code/gradle/libs.versions.toml @@ -6,7 +6,7 @@ com-github-seeseemelk-mockbukkit-v1-v21 = "3.133.2" com-mojang-authlib = "3.3.39" com-mojang-brigadier = "1.0.17" com-velocitypowered-velocity-api = "3.4.0-SNAPSHOT" -de-tr7zw-item-nbt-api = "2.11.1" +de-tr7zw-item-nbt-api = "2.14.1" dev-jorel-commandapi-annotations = "10.0.0" dev-jorel-commandapi-bukkit-core = "10.0.0" dev-jorel-commandapi-bukkit-kotlin = "10.0.0" @@ -16,6 +16,7 @@ io-papermc-paper-paper-api = "1.21-R0.1-SNAPSHOT" net-kyori-adventure-platform-bukkit = "4.2.0" org-jetbrains-kotlin-kotlin-stdlib = "2.0.0" org-junit-jupiter-junit-jupiter = "5.11.0" +com-saicone-rtag = "1.5.9" [libraries] com-github-seeseemelk-mockbukkit-v1-v21 = { module = "com.github.seeseemelk:MockBukkit-v1.21", version.ref = "com-github-seeseemelk-mockbukkit-v1-v21" } @@ -32,3 +33,4 @@ io-papermc-paper-paper-api = { module = "io.papermc.paper:paper-api", version.re net-kyori-adventure-platform-bukkit = { module = "net.kyori:adventure-platform-bukkit", version.ref = "net-kyori-adventure-platform-bukkit" } org-jetbrains-kotlin-kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "org-jetbrains-kotlin-kotlin-stdlib" } org-junit-jupiter-junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "org-junit-jupiter-junit-jupiter" } +com-saicone-rtag = { module = "com.saicone.rtag:rtag", version.ref="com-saicone-rtag" } \ No newline at end of file diff --git a/reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java b/reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java index b93dd082b..662e52e69 100644 --- a/reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java +++ b/reference-code/src/main/java/createcommands/arguments/types/NBTArguments.java @@ -1,11 +1,19 @@ package createcommands.arguments.types; import de.tr7zw.changeme.nbtapi.NBTContainer; +import de.tr7zw.changeme.nbtapi.NBT; +import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT; import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPIBukkitConfig; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.arguments.NBTCompoundArgument; + +import java.util.Map; + import org.bukkit.plugin.java.JavaPlugin; +import net.minecraft.nbt.CompoundTag; +import com.saicone.rtag.Rtag; +import com.saicone.rtag.tag.TagCompound; class NBTArguments { { @@ -14,20 +22,72 @@ class NBTArguments { @Override public void onLoad() { CommandAPI.onLoad(new CommandAPIBukkitConfig(this) - .initializeNBTAPI(NBTContainer.class, NBTContainer::new) + .initializeNBTAPI(ReadWriteNBT.class, NBT::wrapNMSTag) ); } // #endregion hookNbtAPIExample }; - // #region nbtCompoundArgumentsExample + new JavaPlugin() { + // #region hookNbtAPIExampleMojang + @Override + public void onLoad() { + CommandAPI.onLoad(new CommandAPIBukkitConfig(this) + .initializeNBTAPI(CompoundTag.class, o -> o) + ); + } + // #endregion hookNbtAPIExampleMojang + }; + + new JavaPlugin() { + // #region hookNbtAPIExampleRtag + @Override + public void onLoad() { + CommandAPI.onLoad(new CommandAPIBukkitConfig(this) + .initializeNBTAPI(Object.class, o -> o) + ); + } + // #endregion hookNbtAPIExampleRtag + }; + + new JavaPlugin() { + // #region hookNbtAPIExampleRtagObjects + @Override + public void onLoad() { + CommandAPI.onLoad(new CommandAPIBukkitConfig(this) + .initializeNBTAPI(Map.class, o -> TagCompound.getValue(Rtag.INSTANCE, o)) + ); + } + // #endregion hookNbtAPIExampleRtagObjects + }; + + // #region nbtCompoundArgumentsExampleMojang + new CommandAPICommand("award") + .withArguments(new NBTCompoundArgument("nbt")) + .executes((sender, args) -> { + CompoundTag nbt = (CompoundTag) args.get("nbt"); + // Do something with "nbt" here... + }) + .register(); + // #endregion nbtCompoundArgumentsExampleMojang + + // #region nbtCompoundArgumentsExampleNBTAPI new CommandAPICommand("award") - .withArguments(new NBTCompoundArgument("nbt")) + .withArguments(new NBTCompoundArgument("nbt")) .executes((sender, args) -> { - NBTContainer nbt = (NBTContainer) args.get("nbt"); + ReadWriteNBT nbt = (ReadWriteNBT) args.get("nbt"); // Do something with "nbt" here... }) .register(); - // #endregion nbtCompoundArgumentsExample + // #endregion nbtCompoundArgumentsExampleNBTAPI + + // #region nbtCompoundArgumentsExampleRtagPath + new CommandAPICommand("test") + .withArguments(new NBTCompoundArgument("nbt")) + .executes((sender, args) -> { + String result = Rtag.INSTANCE.get(args.get("nbt"), "some", "path", "here"); + }) + .register(); + // #endregion nbtCompoundArgumentsExampleRtagPath } } diff --git a/reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt b/reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt index 5a5758f85..e8243c1d2 100644 --- a/reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt +++ b/reference-code/src/main/kotlin/createcommands/arguments/types/NBTArguments.kt @@ -1,6 +1,8 @@ package createcommands.arguments.types import de.tr7zw.changeme.nbtapi.NBTContainer +import de.tr7zw.changeme.nbtapi.NBT +import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT import dev.jorel.commandapi.CommandAPI import dev.jorel.commandapi.CommandAPIBukkitConfig import dev.jorel.commandapi.CommandAPICommand @@ -10,37 +12,110 @@ import dev.jorel.commandapi.kotlindsl.anyExecutor import dev.jorel.commandapi.kotlindsl.commandAPICommand import dev.jorel.commandapi.kotlindsl.nbtCompoundArgument import org.bukkit.plugin.java.JavaPlugin +import net.minecraft.nbt.CompoundTag +import com.saicone.rtag.Rtag +import com.saicone.rtag.tag.TagCompound val nbtArguments = object : JavaPlugin() { // #region hookNbtAPIExample override fun onLoad() { CommandAPI.onLoad(CommandAPIBukkitConfig(this) - .initializeNBTAPI(NBTContainer::class.java, ::NBTContainer) + .initializeNBTAPI(ReadWriteNBT::class.java, NBT::wrapNMSTag) ) } // #endregion hookNbtAPIExample } +val nbtArgumentsMojang = object : JavaPlugin() { + // #region hookNbtAPIExampleMojang + override fun onLoad() { + CommandAPI.onLoad(CommandAPIBukkitConfig(this) + .initializeNBTAPI(CompoundTag::class.java, { it as CompoundTag }) + ) + } + // #endregion hookNbtAPIExampleMojang +} + +val nbtArgumentsRtag = object : JavaPlugin() { + // #region hookNbtAPIExampleRtag + override fun onLoad() { + CommandAPI.onLoad(CommandAPIBukkitConfig(this) + .initializeNBTAPI(Object::class.java, { it as Object }) + ) + } + // #endregion hookNbtAPIExampleRtag +} + +val nbtArgumentsRtagObjects = object : JavaPlugin() { + // #region hookNbtAPIExampleRtagObjects + override fun onLoad() { + CommandAPI.onLoad(CommandAPIBukkitConfig(this) + .initializeNBTAPI(Map::class.java) { o -> TagCompound.getValue(Rtag.INSTANCE, o) } + ) + } + // #endregion hookNbtAPIExampleRtagObjects +} + + + fun nbtArguments() { - // #region nbtCompoundArgumentsExample + // #region nbtCompoundArgumentsExampleMojang CommandAPICommand("award") - .withArguments(NBTCompoundArgument("nbt")) + .withArguments(NBTCompoundArgument("nbt")) .executes(CommandExecutor { _, args -> - val nbt = args["nbt"] as NBTContainer + val nbt = args["nbt"] as CompoundTag // Do something with "nbt" here... }) .register() - // #endregion nbtCompoundArgumentsExample + // #endregion nbtCompoundArgumentsExampleMojang + + // #region nbtCompoundArgumentsExampleNBTAPI + CommandAPICommand("award") + .withArguments(NBTCompoundArgument("nbt")) + .executes(CommandExecutor { _, args -> + val nbt = args["nbt"] as ReadWriteNBT + // Do something with "nbt" here... + }) + .register() + // #endregion nbtCompoundArgumentsExampleNBTAPI + + // #region nbtCompoundArgumentsExampleRtagPath + CommandAPICommand("test") + .withArguments(NBTCompoundArgument("nbt")) + .executes(CommandExecutor { _, args -> + val result = Rtag.INSTANCE.get(args["nbt"], "some", "path", "here") as String + }) + .register() + // #endregion nbtCompoundArgumentsExampleRtagPath } fun nbtArgumentsDSL() { - // #region nbtCompoundArgumentsExampleDSL + // #region nbtCompoundArgumentsExampleMojangDSL + commandAPICommand("award") { + nbtCompoundArgument("nbt") + anyExecutor { _, args -> + val nbt = args["nbt"] as CompoundTag + // Do something with "nbt" here... + } + } + // #endregion nbtCompoundArgumentsExampleMojangDSL + + // #region nbtCompoundArgumentsExampleNBTAPIDSL commandAPICommand("award") { - nbtCompoundArgument("nbt") + nbtCompoundArgument("nbt") anyExecutor { _, args -> - val nbt = args["nbt"] as NBTContainer + val nbt = args["nbt"] as ReadWriteNBT // Do something with "nbt" here... } } - // #endregion nbtCompoundArgumentsExampleDSL + // #endregion nbtCompoundArgumentsExampleNBTAPIDSL + + // #region nbtCompoundArgumentsExampleRtagPathDSL + commandAPICommand("award") { + nbtCompoundArgument("nbt") + anyExecutor { _, args -> + val result = Rtag.INSTANCE.get(args["nbt"], "some", "path", "here") as String + } + } + // #endregion nbtCompoundArgumentsExampleRtagPathDSL } \ No newline at end of file