Skip to content

Commit

Permalink
Document new NativeProxyCommandSender.from method
Browse files Browse the repository at this point in the history
  • Loading branch information
willkroboth committed Jul 4, 2024
1 parent 6744bdf commit cd81410
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,27 @@ void nativeSender() {
})
.register();
/* ANCHOR_END: native1 */

/* ANCHOR: native2 */
new CommandAPICommand("executeAs")
.withArguments(
new EntitySelectorArgument.OneEntity("target"),
new LocationArgument("location"),
new WorldArgument("world"),
new CommandArgument("command")
)
.executes((caller, args) -> {
CommandSender callee = args.getUnchecked("target");
Location location = args.getUnchecked("location");
World world = args.getUnchecked("world");
CommandResult command = args.getUnchecked("command");

assert callee != null && location != null && world != null && command != null;

command.execute(NativeProxyCommandSender.from(caller, callee, location, world));
})
.register();
/* ANCHOR_END: native2 */
}

void normalExecutors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,25 @@ CommandAPICommand("break")
})
.register()
/* ANCHOR_END: native1 */

/* ANCHOR: native2 */
CommandAPICommand("executeAs")
.withArguments(
EntitySelectorArgument.OneEntity("target"),
LocationArgument("location"),
WorldArgument("world"),
CommandArgument("command")
)
.executes(CommandExecutor { caller, args ->
val callee = args["target"] as CommandSender
val location = args["location"] as Location
val world = args["world"] as World
val command = args["command"] as CommandResult

command.execute(NativeProxyCommandSender.from(caller, callee, location, world))
})
.register();
/* ANCHOR_END: native2 */
}

fun normalExecutors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,23 @@ commandAPICommand("break") {
}
}
/* ANCHOR_END: native1 */

/* ANCHOR: native1 */
commandAPICommand("executeAs") {
entitySelectorArgumentOneEntity("target")
locationArgument("location")
worldArgument("world")
commandArgument("command")
anyExecutor { caller, args ->
val callee = args["target"] as CommandSender
val location = args["location"] as Location
val world = args["world"] as World
val command = args["command"] as CommandResult

command.execute(NativeProxyCommandSender.from(caller, callee, location, world))
}
}
/* ANCHOR_END: native1 */
}

fun optional_arguments() {
Expand Down
26 changes: 26 additions & 0 deletions docssrc/src/native.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,29 @@ This can now be used via the following command examples:
```

</div>

---

You may also create a `NativeProxyCommandSender` object yourself using the static `from` method:

```java
public static NativeProxyCommandSender from(CommandSender caller, CommandSender callee, Location location, World world);
```

This `CommandSender` will work the same as any other `NativeProxyCommandSender` you would get while using `executesNative`. For example, you could use it to make a simple version of `/execute`, like so:

<div class="multi-pre">

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

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

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

</div>
34 changes: 34 additions & 0 deletions docssrc/src/upgrading.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# Upgrading guide

[//]: # (TODO: Change 9.3.0 to the correct version)

## From 9.3.0 to 10.0.0

### NativeProxyCommandSender changes

`NativeProxyCommandSender` used to be a class, but this version changed it to an interface. Any code compiled against an earlier version that references any method of `NativeProxyCommandSender` may throw the following `IncompatibleClassChangeError` when run using the new version of the API:

```log
java.lang.IncompatibleClassChangeError: Found interface dev.jorel.commandapi.wrappers.NativeProxyCommandSender, but class was expected
```

If this happens, the original code simply needs to be recompiled using the new API version.

Additionally, the constructor of `NativeProxyCommandSender` is no longer available. Instead, the static `from` method should be used:

<div class="multi-pre">

```java,9.3.0
new NativeProxyCommandSender(caller, callee, location, world)
```

</div>

$$\downarrow$$

<div class="multi-pre">

```java,10.0.0
NativeProxyCommandSender.from(caller, callee, location, world)
```

</div>

## From 9.2.0 to 9.3.0

The `BukkitTooltip.generateAdvenureComponents` methods have now been deprecated in favour of the correctly named `BukkitTooltip.generateAdventureComponents` methods:
Expand Down

0 comments on commit cd81410

Please sign in to comment.