Skip to content

Commit f556d57

Browse files
committed
Add documentation for CommandAPI/CommandAPI#478
1 parent c43a1cf commit f556d57

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

docs/.vitepress/theme/upgrading/upgrading.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const upgradingInfos: UpgradingInfo[] = [
1818
{from: '9.0.1', to: '9.0.2'},
1919
{from: '9.0.3', to: '9.1.0'},
2020
{from: '9.2.0', to: '9.3.0'},
21+
{from: `9.7.0`, to: '10.0.0'},
2122
]
2223

2324
export const keyVersions = Array.from(new Set(upgradingInfos.map(info => [info.from, info.to]).flat()));

docs/en/create-commands/executors/native-sender.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,23 @@ This can now be used via the following command examples:
6767
/execute in minecraft:overworld positioned 20 60 -20 run break
6868
```
6969

70-
::::
70+
::::
71+
72+
## Constructing a `NativeProxyCommandSender`
73+
74+
You can create a `NativeProxyCommandSender` object yourself using the static `from` method:
75+
76+
```java
77+
NativeProxyCommandSender from(CommandSender caller, CommandSender callee, Location location, World world);
78+
```
79+
80+
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:
81+
82+
:::tabs
83+
===Java
84+
<<< @/../reference-code/src/main/java/createcommands/executors/NativeSender.java#constructorExample
85+
===Kotlin
86+
<<< @/../reference-code/src/main/kotlin/createcommands/executors/NativeSender.kt#constructorExample
87+
===Kotlin DSL
88+
<<< @/../reference-code/src/main/kotlin/createcommands/executors/NativeSender.kt#constructorExampleDSL
89+
:::
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
`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:
2+
3+
```
4+
java.lang.IncompatibleClassChangeError: Found interface dev.jorel.commandapi.wrappers.NativeProxyCommandSender, but class was expected
5+
```
6+
7+
If this happens, the original code simply needs to be recompiled using the new API version.
8+
9+
Additionally, the constructor of `NativeProxyCommandSender` is no longer available. Instead, the static `from` method should be used:
10+
11+
```java
12+
new NativeProxyCommandSender(caller, callee, location, world); // [!code --]
13+
14+
NativeProxyCommandSender.from(caller, callee, location, world); // [!code ++]
15+
```

reference-code/src/main/java/createcommands/executors/NativeSender.java

+29
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package createcommands.executors;
22

33
import dev.jorel.commandapi.CommandAPICommand;
4+
import dev.jorel.commandapi.arguments.CommandArgument;
5+
import dev.jorel.commandapi.arguments.EntitySelectorArgument;
6+
import dev.jorel.commandapi.arguments.LocationArgument;
7+
import dev.jorel.commandapi.arguments.WorldArgument;
8+
import dev.jorel.commandapi.wrappers.CommandResult;
9+
import dev.jorel.commandapi.wrappers.NativeProxyCommandSender;
410
import org.bukkit.Location;
11+
import org.bukkit.World;
12+
import org.bukkit.command.CommandSender;
513

614
class NativeSender {
715
static {
@@ -15,5 +23,26 @@ class NativeSender {
1523
})
1624
.register();
1725
// #endregion breakCommandExample
26+
27+
// #region constructorExample
28+
new CommandAPICommand("executeAs")
29+
.withArguments(
30+
new EntitySelectorArgument.OneEntity("target"),
31+
new LocationArgument("location"),
32+
new WorldArgument("world"),
33+
new CommandArgument("command")
34+
)
35+
.executes((caller, args) -> {
36+
CommandSender callee = args.getUnchecked("target");
37+
Location location = args.getUnchecked("location");
38+
World world = args.getUnchecked("world");
39+
CommandResult command = args.getUnchecked("command");
40+
41+
assert callee != null && location != null && world != null && command != null;
42+
43+
command.execute(NativeProxyCommandSender.from(caller, callee, location, world));
44+
})
45+
.register();
46+
// #endregion constructorExample
1847
}
1948
}

reference-code/src/main/kotlin/createcommands/executors/NativeSender.kt

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
package createcommands.executors
22

33
import dev.jorel.commandapi.CommandAPICommand
4+
import dev.jorel.commandapi.arguments.CommandArgument
5+
import dev.jorel.commandapi.arguments.EntitySelectorArgument
6+
import dev.jorel.commandapi.arguments.LocationArgument
7+
import dev.jorel.commandapi.arguments.WorldArgument
8+
import dev.jorel.commandapi.executors.CommandExecutor
49
import dev.jorel.commandapi.executors.NativeCommandExecutor
5-
import dev.jorel.commandapi.kotlindsl.commandAPICommand
6-
import dev.jorel.commandapi.kotlindsl.nativeExecutor
10+
import dev.jorel.commandapi.kotlindsl.*
11+
import dev.jorel.commandapi.wrappers.CommandResult
12+
import dev.jorel.commandapi.wrappers.NativeProxyCommandSender
13+
import org.bukkit.Location
14+
import org.bukkit.World
15+
import org.bukkit.command.CommandSender
716

817
fun nativeSender() {
918
// #region breakCommandExample
@@ -14,6 +23,25 @@ fun nativeSender() {
1423
})
1524
.register()
1625
// #endregion breakCommandExample
26+
27+
// #region constructorExample
28+
CommandAPICommand("executeAs")
29+
.withArguments(
30+
EntitySelectorArgument.OneEntity("target"),
31+
LocationArgument("location"),
32+
WorldArgument("world"),
33+
CommandArgument("command")
34+
)
35+
.executes(CommandExecutor { caller, args ->
36+
val callee = args["target"] as CommandSender
37+
val location = args["location"] as Location
38+
val world = args["world"] as World
39+
val command = args["command"] as CommandResult
40+
41+
command.execute(NativeProxyCommandSender.from(caller, callee, location, world))
42+
})
43+
.register()
44+
// #endregion constructorExample
1745
}
1846

1947
fun nativeSenderDSL() {
@@ -25,4 +53,21 @@ fun nativeSenderDSL() {
2553
}
2654
}
2755
// #endregion breakCommandExampleDSL
56+
57+
// #region constructorExampleDSL
58+
commandAPICommand("executeAs") {
59+
entitySelectorArgumentOneEntity("target")
60+
locationArgument("location")
61+
worldArgument("world")
62+
commandArgument("command")
63+
anyExecutor { caller, args ->
64+
val callee = args["target"] as CommandSender
65+
val location = args["location"] as Location
66+
val world = args["world"] as World
67+
val command = args["command"] as CommandResult
68+
69+
command.execute(NativeProxyCommandSender.from(caller, callee, location, world))
70+
}
71+
}
72+
// #endregion constructorExampleDSL
2873
}

0 commit comments

Comments
 (0)