Skip to content

Command build rewrite #2

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docs/en/create-commands/command-trees.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ So far in this documentation, we've described many different ways to register co
The Command Tree represents command structures in a tree-like fashion, in a very similar way that Brigadier's API lets you declare commands. Command tree commands effectively revolve around two methods:

```java
public T executes(CommandExecutor executor);
public T executes(NormalExecutor<CommandSender, ?> executor);

public CommandTree then(ArgumentTree branch);
public ArgumentTree then(ArgumentTree branch);
Expand Down
33 changes: 0 additions & 33 deletions docs/en/create-commands/registration.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,39 +142,6 @@ CommandAPICommand executesNative(info -> {})

Executes a command regardless of what the command sender is, using the `NativeProxyCommandSender`. Read more about native proxied command senders [here](./executors/native-sender).

:::info

Sometimes, the Java compiler throws an error saying that a method is ambiguous for the type CommandAPICommand. This is due to a limitation in Java's type inference system and is not a fault of the CommandAPI. If we take the following code, used to spawn a pig:

```java
new CommandAPICommand("spawnpigs")
.executesPlayer((player, args) -> {
for(int i = 0; i < 10; i++) {
player.getWorld().spawnEntity(player.getLocation(), (EntityType) args.get(0));
}
})
.register();
```

The Java type inference system can’t determine what the type of the lambda `(player, args) -> ()` is, therefore, it produces the following compilation error:

```log
The method executesPlayer(PlayerCommandExecutor) is ambiguous for the type CommandAPICommand
```

This can easily be resolved by declaring the specific type of the command sender and the arguments. For example:

```java
new CommandAPICommand("spawnpigs")
.executesPlayer((Player player, CommandArguments args) -> {
for(int i = 0; i < 10; i++) {
player.getWorld().spawnEntity(player.getLocation(), (EntityType) args.get(0));
}
})
.register();
```
:::

#### Registering the command

```java
Expand Down
12 changes: 6 additions & 6 deletions docs/en/dev-setup/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The annotation system effectively needs to be added twice: Once for compilation
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-annotations</artifactId>
<version>9.7.0</version>
<version>9.7.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -42,7 +42,7 @@ The annotation system effectively needs to be added twice: Once for compilation
<path>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-annotations</artifactId>
<version>9.7.0</version>
<version>9.7.1-SNAPSHOT</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down Expand Up @@ -81,17 +81,17 @@ The annotation system effectively needs to be added twice: Once for compilation

```groovy
dependencies {
compileOnly "dev.jorel:commandapi-annotations:9.7.0"
annotationProcessor "dev.jorel:commandapi-annotations:9.7.0"
compileOnly "dev.jorel:commandapi-annotations:9.7.1-SNAPSHOT"
annotationProcessor "dev.jorel:commandapi-annotations:9.7.1-SNAPSHOT"
}
```
</div>
<div class="kts">

```kotlin
dependencies {
compileOnly("dev.jorel:commandapi-annotations:9.7.0")
annotationProcessor("dev.jorel:commandapi-annotations:9.7.0")
compileOnly("dev.jorel:commandapi-annotations:9.7.1-SNAPSHOT")
annotationProcessor("dev.jorel:commandapi-annotations:9.7.1-SNAPSHOT")
}
```
</div>
Expand Down
6 changes: 3 additions & 3 deletions docs/en/dev-setup/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ If you've never used a build system before, I highly recommend it! It makes it e
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-core</artifactId>
<version>9.7.0</version>
<version>9.7.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -90,7 +90,7 @@ If you've never used a build system before, I highly recommend it! It makes it e

```groovy
dependencies {
compileOnly "dev.jorel:commandapi-bukkit-core:9.7.0"
compileOnly "dev.jorel:commandapi-bukkit-core:9.7.1-SNAPSHOT"
}
```

Expand All @@ -99,7 +99,7 @@ If you've never used a build system before, I highly recommend it! It makes it e

```kotlin
dependencies {
compileOnly("dev.jorel:commandapi-bukkit-core:9.7.0")
compileOnly("dev.jorel:commandapi-bukkit-core:9.7.1-SNAPSHOT")
}
```

Expand Down
12 changes: 6 additions & 6 deletions docs/en/dev-setup/shading.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Add the CommandAPI shade dependency:
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-shade</artifactId>
<version>9.7.0</version>
<version>9.7.1-SNAPSHOT</version>
</dependency>
</dependencies>
```
Expand All @@ -126,7 +126,7 @@ Add the CommandAPI shade dependency:
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-shade-mojang-mapped</artifactId>
<version>9.7.0</version>
<version>9.7.1-SNAPSHOT</version>
</dependency>
</dependencies>
```
Expand Down Expand Up @@ -222,15 +222,15 @@ Next, we declare our dependencies:

```groovy
dependencies {
implementation "dev.jorel:commandapi-bukkit-shade:9.7.0"
implementation "dev.jorel:commandapi-bukkit-shade:9.7.1-SNAPSHOT"
}
```
</div>
<div class="mojmap">

```groovy
dependencies {
implementation "dev.jorel:commandapi-bukkit-shade-mojang-mapped:9.7.0"
implementation "dev.jorel:commandapi-bukkit-shade-mojang-mapped:9.7.1-SNAPSHOT"
}
```
</div>
Expand All @@ -240,15 +240,15 @@ dependencies {

```kotlin
dependencies {
implementation("dev.jorel:commandapi-bukkit-shade:9.7.0")
implementation("dev.jorel:commandapi-bukkit-shade:9.7.1-SNAPSHOT")
}
```
</div>
<div class="mojmap">

```kotlin
dependencies {
implementation("dev.jorel:commandapi-bukkit-shade-mojang-mapped:9.7.0")
implementation("dev.jorel:commandapi-bukkit-shade-mojang-mapped:9.7.1-SNAPSHOT")
}
```
</div>
Expand Down
6 changes: 3 additions & 3 deletions docs/en/kotlin-dsl/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To install the DSL, you need to add the `commandapi-bukkit-kotlin` dependency in
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-kotlin</artifactId>
<version>9.7.0</version>
<version>9.7.1-SNAPSHOT</version>
</dependency>
</dependencies>
```
Expand Down Expand Up @@ -106,7 +106,7 @@ Next, you need to add the dependency:

```groovy
dependencies {
implementation "dev.jorel:commandapi-bukkit-kotlin:9.7.0"
implementation "dev.jorel:commandapi-bukkit-kotlin:9.7.1-SNAPSHOT"
}
```

Expand All @@ -115,7 +115,7 @@ dependencies {

```kotlin
dependencies {
implementation("dev.jorel:commandapi-bukkit-kotlin:9.7.0")
implementation("dev.jorel:commandapi-bukkit-kotlin:9.7.1-SNAPSHOT")
}
```

Expand Down
4 changes: 3 additions & 1 deletion docs/en/kotlin-dsl/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ We want to create a `/give` command with the following syntax:
/optionalArgument give <item> <amount>
```

To declare an argument as optional you need to set the `optional` value to `true`:
When using a CommandTree, you can do this by using the same executor in two places.

When using a CommandAPICommand, you can create an optional Argument by setting the `optional` value to `true`:

:::tabs key:dsl-usage-page
===CommandTree
Expand Down
12 changes: 6 additions & 6 deletions docs/en/test/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ When you add the dependencies for MockBukkit and `commandapi-bukkit-test-toolkit
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-test-toolkit</artifactId>
<version>9.7.0</version>
<version>9.7.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<!-- May be the shade dependency and/or mojang-mapped -->
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-core</artifactId>
<version>9.7.0</version>
<version>9.7.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -70,10 +70,10 @@ dependencies {
// See https://github.com/MockBukkit/MockBukkit?tab=readme-ov-file#mag-usage for latest version
testImplementation 'com.github.seeseemelk:MockBukkit-v1.21:3.128.0'

testImplementation 'dev.jorel:commandapi-bukkit-test-toolkit:9.7.0'
testImplementation 'dev.jorel:commandapi-bukkit-test-toolkit:9.7.1-SNAPSHOT'

// May be the shade dependency and/or mojang-mapped
compileOnly 'dev.jorel:commandapi-bukkit-core:9.7.0'
compileOnly 'dev.jorel:commandapi-bukkit-core:9.7.1-SNAPSHOT'

// Can also be paper-api
compileOnly 'org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT'
Expand All @@ -91,10 +91,10 @@ dependencies {
// See https://github.com/MockBukkit/MockBukkit?tab=readme-ov-file#mag-usage for latest version
testImplementation("com.github.seeseemelk:MockBukkit-v1.21:3.128.0")

testImplementation("dev.jorel:commandapi-bukkit-test-toolkit:9.7.0")
testImplementation("dev.jorel:commandapi-bukkit-test-toolkit:9.7.1-SNAPSHOT")

// May be the shade dependency and/or mojang-mapped
compileOnly("dev.jorel:commandapi-bukkit-core:9.7.0")
compileOnly("dev.jorel:commandapi-bukkit-core:9.7.1-SNAPSHOT")

// Can also be paper-api
compileOnly("org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT")
Expand Down
10 changes: 5 additions & 5 deletions reference-code/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ 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"
dev-jorel-commandapi-annotations = "9.7.0"
dev-jorel-commandapi-bukkit-core = "9.7.0"
dev-jorel-commandapi-bukkit-kotlin = "9.7.0"
dev-jorel-commandapi-bukkit-test-toolkit = "9.7.0"
dev-jorel-commandapi-velocity-shade = "9.6.2-SNAPSHOT"
dev-jorel-commandapi-annotations = "9.7.1-SNAPSHOT"
dev-jorel-commandapi-bukkit-core = "9.7.1-SNAPSHOT"
dev-jorel-commandapi-bukkit-kotlin = "9.7.1-SNAPSHOT"
dev-jorel-commandapi-bukkit-test-toolkit = "9.7.1-SNAPSHOT"
dev-jorel-commandapi-velocity-shade = "9.7.1-SNAPSHOT"
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"
Expand Down
9 changes: 5 additions & 4 deletions reference-code/src/main/kotlin/createcommands/Aliases.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package createcommands

import dev.jorel.commandapi.CommandAPICommand
import dev.jorel.commandapi.executors.CommandBlockCommandExecutor
import dev.jorel.commandapi.executors.EntityCommandExecutor
import dev.jorel.commandapi.executors.NormalExecutor
import dev.jorel.commandapi.kotlindsl.commandAPICommand
import dev.jorel.commandapi.kotlindsl.commandBlockExecutor
import dev.jorel.commandapi.kotlindsl.entityExecutor
import org.bukkit.command.BlockCommandSender
import org.bukkit.entity.Entity

fun aliases() {
// #region aliasesExample
Expand All @@ -14,11 +15,11 @@ fun aliases() {
.withAliases("getposition", "getloc", "getlocation", "whereami")

// Declare your implementation
.executesEntity(EntityCommandExecutor { entity, _ ->
.executesEntity(NormalExecutor<Entity, Any> { entity, _ ->
val loc = entity.location
entity.sendMessage("You are at ${loc.blockX}, ${loc.blockY}, ${loc.blockZ}")
})
.executesCommandBlock(CommandBlockCommandExecutor { block, _ ->
.executesCommandBlock(NormalExecutor<BlockCommandSender, Any> { block, _ ->
val loc = block.block.location
block.sendMessage("You are at ${loc.blockX}, ${loc.blockY}, ${loc.blockZ}")
})
Expand Down
20 changes: 10 additions & 10 deletions reference-code/src/main/kotlin/createcommands/CommandTrees.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ package createcommands
import dev.jorel.commandapi.CommandAPI
import dev.jorel.commandapi.CommandTree
import dev.jorel.commandapi.arguments.*
import dev.jorel.commandapi.executors.CommandExecutor
import dev.jorel.commandapi.executors.PlayerCommandExecutor
import dev.jorel.commandapi.executors.NormalExecutor
import dev.jorel.commandapi.kotlindsl.*
import org.bukkit.block.Sign
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.metadata.FixedMetadataValue
import org.bukkit.plugin.java.JavaPlugin

fun commandTrees() {
// #region commandTreesExample
CommandTree("sayhi")
.executes(CommandExecutor { sender, _ ->
.executes(NormalExecutor<CommandSender, Any> { sender, _ ->
sender.sendMessage("Hi!")
})
.then(
PlayerArgument("target")
.executes(CommandExecutor { _, args ->
.executes(NormalExecutor<CommandSender, Any> { _, args ->
val target = args["target"] as Player
target.sendMessage("Hi")
})
Expand All @@ -35,7 +35,7 @@ fun commandTrees() {
.then(StringArgument("arg3")
.then(DoubleArgument("arg4", 0.0)
.then(StringArgument("arg5")
.executes(CommandExecutor { sender, _ ->
.executes(NormalExecutor<CommandSender, Any> { sender, _ ->
// your code here
}))))))
.register()
Expand All @@ -50,7 +50,7 @@ fun commandTrees() {
StringArgument("arg3"),
DoubleArgument("arg4", 0.0),
StringArgument("arg5")
.executes(CommandExecutor { sender, _ ->
.executes(NormalExecutor<CommandSender, Any> { sender, _ ->
// your code here
})
).register()
Expand All @@ -64,7 +64,7 @@ fun commandTrees() {
.then(LiteralArgument("set")
.then(IntegerArgument("line_number", 1, 4)
.then(GreedyStringArgument("text")
.executesPlayer(PlayerCommandExecutor { player, args ->
.executesPlayer(NormalExecutor<Player, Any> { player, args ->
// /signedit set <line_number> <text>
val sign: Sign = getTargetSign(player)
val line_number = args["line_number"] as Int
Expand All @@ -74,7 +74,7 @@ fun commandTrees() {
}))))
.then(LiteralArgument("clear")
.then(IntegerArgument("line_number", 1, 4)
.executesPlayer(PlayerCommandExecutor { player, args ->
.executesPlayer(NormalExecutor<Player, Any> { player, args ->
// /signedit clear <line_number>
val sign: Sign = getTargetSign(player)
val line_number = args["line_number"] as Int
Expand All @@ -83,15 +83,15 @@ fun commandTrees() {
})))
.then(LiteralArgument("copy")
.then(IntegerArgument("line_number", 1, 4)
.executesPlayer(PlayerCommandExecutor { player, args ->
.executesPlayer(NormalExecutor<Player, Any> { player, args ->
// /signedit copy <line_number>
val sign: Sign = getTargetSign(player)
val line_number = args["line_number"] as Int
player.setMetadata("copied_sign_text", FixedMetadataValue(this, sign.getLine(line_number - 1)))
})))
.then(LiteralArgument("paste")
.then(IntegerArgument("line_number", 1, 4)
.executesPlayer(PlayerCommandExecutor { player, args ->
.executesPlayer(NormalExecutor<Player, Any> { player, args ->
// /signedit copy <line_number>
val sign: Sign = getTargetSign(player)
val line_number = args["line_number"] as Int
Expand Down
Loading