Skip to content

Commit e3b40de

Browse files
committed
Document new NativeProxyCommandSender.from method
1 parent 4b74a3a commit e3b40de

File tree

5 files changed

+117
-0
lines changed

5 files changed

+117
-0
lines changed

commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,27 @@ void nativeSender() {
18211821
})
18221822
.register();
18231823
/* ANCHOR_END: native1 */
1824+
1825+
/* ANCHOR: native2 */
1826+
new CommandAPICommand("executeAs")
1827+
.withArguments(
1828+
new EntitySelectorArgument.OneEntity("target"),
1829+
new LocationArgument("location"),
1830+
new WorldArgument("world"),
1831+
new CommandArgument("command")
1832+
)
1833+
.executes((caller, args) -> {
1834+
CommandSender callee = args.getUnchecked("target");
1835+
Location location = args.getUnchecked("location");
1836+
World world = args.getUnchecked("world");
1837+
CommandResult command = args.getUnchecked("command");
1838+
1839+
assert callee != null && location != null && world != null && command != null;
1840+
1841+
command.execute(NativeProxyCommandSender.from(caller, callee, location, world));
1842+
})
1843+
.register();
1844+
/* ANCHOR_END: native2 */
18241845
}
18251846

18261847
void normalExecutors() {

commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,25 @@ CommandAPICommand("break")
17261726
})
17271727
.register()
17281728
/* ANCHOR_END: native1 */
1729+
1730+
/* ANCHOR: native2 */
1731+
CommandAPICommand("executeAs")
1732+
.withArguments(
1733+
EntitySelectorArgument.OneEntity("target"),
1734+
LocationArgument("location"),
1735+
WorldArgument("world"),
1736+
CommandArgument("command")
1737+
)
1738+
.executes(CommandExecutor { caller, args ->
1739+
val callee = args["target"] as CommandSender
1740+
val location = args["location"] as Location
1741+
val world = args["world"] as World
1742+
val command = args["command"] as CommandResult
1743+
1744+
command.execute(NativeProxyCommandSender.from(caller, callee, location, world))
1745+
})
1746+
.register();
1747+
/* ANCHOR_END: native2 */
17291748
}
17301749

17311750
fun normalExecutors() {

commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,23 @@ commandAPICommand("break") {
11091109
}
11101110
}
11111111
/* ANCHOR_END: native1 */
1112+
1113+
/* ANCHOR: native1 */
1114+
commandAPICommand("executeAs") {
1115+
entitySelectorArgumentOneEntity("target")
1116+
locationArgument("location")
1117+
worldArgument("world")
1118+
commandArgument("command")
1119+
anyExecutor { caller, args ->
1120+
val callee = args["target"] as CommandSender
1121+
val location = args["location"] as Location
1122+
val world = args["world"] as World
1123+
val command = args["command"] as CommandResult
1124+
1125+
command.execute(NativeProxyCommandSender.from(caller, callee, location, world))
1126+
}
1127+
}
1128+
/* ANCHOR_END: native1 */
11121129
}
11131130

11141131
fun optional_arguments() {

docssrc/src/native.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,29 @@ This can now be used via the following command examples:
8181
```
8282

8383
</div>
84+
85+
---
86+
87+
You may also create a `NativeProxyCommandSender` object yourself using the static `from` method:
88+
89+
```java
90+
public static NativeProxyCommandSender from(CommandSender caller, CommandSender callee, Location location, World world);
91+
```
92+
93+
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:
94+
95+
<div class="multi-pre">
96+
97+
```java,Java
98+
{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:native2}}
99+
```
100+
101+
```kotlin,Kotlin
102+
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:native2}}
103+
```
104+
105+
```kotlin,Kotlin_DSL
106+
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:native2}}
107+
```
108+
109+
</div>

docssrc/src/upgrading.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
# Upgrading guide
22

3+
[//]: # (TODO: Change 9.3.0 to the correct version)
4+
5+
## From 9.3.0 to 10.0.0
6+
7+
### NativeProxyCommandSender changes
8+
9+
`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:
10+
11+
```log
12+
java.lang.IncompatibleClassChangeError: Found interface dev.jorel.commandapi.wrappers.NativeProxyCommandSender, but class was expected
13+
```
14+
15+
If this happens, the original code simply needs to be recompiled using the new API version.
16+
17+
Additionally, the constructor of `NativeProxyCommandSender` is no longer available. Instead, the static `from` method should be used:
18+
19+
<div class="multi-pre">
20+
21+
```java,9.3.0
22+
new NativeProxyCommandSender(caller, callee, location, world)
23+
```
24+
25+
</div>
26+
27+
$$\downarrow$$
28+
29+
<div class="multi-pre">
30+
31+
```java,10.0.0
32+
NativeProxyCommandSender.from(caller, callee, location, world)
33+
```
34+
35+
</div>
36+
337
## From 9.2.0 to 9.3.0
438

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

0 commit comments

Comments
 (0)