Skip to content

Commit a93557f

Browse files
committed
fix: fix some typo, add missing page
1 parent 062603a commit a93557f

File tree

6 files changed

+114
-7
lines changed

6 files changed

+114
-7
lines changed

docs/en/create-commands/arguments/types/map-arguments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ To implement that, we create a command that uses a `MapArgument` and use `Player
154154
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/MapArguments.kt#mapArgumentsExampleDSL
155155
:::
156156

157-
:::warning Developer's Note:
157+
:::danger Developer's Note:
158158

159159
The `MapArgument` is very strict and doesn't have room for any errors. A key must always be followed by the delimiter, then a value. One value and the next key must always be separated by the separator. Both keys and values also have the option to be surrounded by quotes.
160160

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
order: 3
3+
authors:
4+
- JorelAli
5+
- DerEchtePilz
6+
- willkroboth
7+
---
8+
9+
# The FunctionWrapper
10+
11+
The CommandAPI includes the `FunctionWrapper` class which is a wrapper for Minecraft's functions. It allows you to execute the commands that are represented by the respective `.mcfunction` file.
12+
13+
The `FunctionWrapper` class is an extension of the `SimpleFunctionWrapper` class. It is a `SimpleFunctionWrapper` which has been constructed from an existing command sender when a command is used. This means that the command sender has already been "baked into" the `FunctionWrapper` object, allowing you to run it without having to provide a command sender.
14+
15+
## FunctionWrapper methods
16+
17+
The `FunctionWrapper` class has the following methods:
18+
19+
```java
20+
class FunctionWrapper extends SimpleFunctionWrapper {
21+
22+
// Methods specific to this class
23+
int run();
24+
int runAs(Entity e);
25+
26+
// Methods inherited from SimpleFunctionWrapper
27+
static SimpleFunctionWrapper getFunction(NamespacedKey key);
28+
static SimpleFunctionWrapper[] getTag(NamespacedKey key);
29+
static Set<NamespacedKey> getFunctions();
30+
static Set<NamespacedKey> getTags();
31+
int run(CommandSender sender);
32+
String[] getCommands();
33+
NamespacedKey getKey();
34+
}
35+
```
36+
37+
These methods allow you to interact with the Minecraft function that this class wraps.
38+
39+
### `run()`
40+
41+
:::warning run() support in 1.20.3+
42+
43+
As of CommandAPI 9.3.0 (compatible with Minecraft versions 1.20.3 and 1.20.4), calling `run()` will always return a value of `1`, regardless of whether the command succeeds, fails, or returns a result.
44+
45+
:::
46+
47+
The `run()` method runs the function. The command executor that runs this function is the command executor that was used to retrieve it. For example, if a player in-game populated this argument, then the player will be filled in for `@p` and the player's location would be used for things such as `~ ~ ~`:
48+
49+
:::tabs
50+
===Java
51+
<<< @/../reference-code/src/main/java/createcommands/functionsandtags/FunctionWrapperRef.java#runExample
52+
===Kotlin
53+
<<< @/../reference-code/src/main/kotlin/createcommands/functionsandtags/FunctionWrapperRef.kt#runExample
54+
:::
55+
56+
### `runAs(Entity)`
57+
58+
:::warning runAs(Entity) support in 1.20.3+
59+
60+
As of CommandAPI 9.3.0 (compatible with Minecraft versions 1.20.3 and 1.20.4), calling `runAs(Entity)` will always return a value of `1`, regardless of whether the command succeeds, fails, or returns a result.
61+
62+
:::
63+
64+
The `runAs(Entity)` is the same as the `run()` method, but it allows you to change the command executor to another entity.

docs/en/create-commands/functions-and-tags/simple-function-wrapper.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
order: 3
2+
order: 2
33
authors:
44
- JorelAli
55
title: SimpleFunctionWrapper class
@@ -50,7 +50,7 @@ The methods `getFunctions()` and `getTags()` simply return a set of `NamespacedK
5050

5151
### `run(CommandSender)`
5252

53-
:::warning `run(CommandSender)` support in 1.20.3+
53+
:::danger `run(CommandSender)` support in 1.20.3+
5454

5555
As of CommandAPI 9.3.0 (compatible with Minecraft versions 1.20.3 and 1.20.4), calling `run(CommandSender)` will always return a value of `1`, regardless of whether the command succeeds, fails, or returns a result.
5656

@@ -60,7 +60,7 @@ This method simply runs the current `SimpleFunctionWrapper` as the provided comm
6060

6161
### `getCommands()`
6262

63-
:::warning `getCommands()` support in 1.20.3+
63+
:::danger `getCommands()` support in 1.20.3+
6464

6565
As of CommandAPI 9.3.0 (compatible with Minecraft versions 1.20.3 and 1.20.4), calling `getCommands()` will always return an empty `String[]`. At the time of writing, it is not possible to extract the function command list in 1.20.3+.
6666

docs/en/internal/brigadier-plus-commandapi.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ authors:
1010

1111
So far, we've been using only the CommandAPI to register commands. As a result, this makes the CommandAPI's features limited by whatever the CommandAPI has implemented. To push past these limits, the CommandAPI includes some extra methods to help with invoking brigadier methods. Of course, to use these methods, brigadier is required. The brigadier dependency's installation instructions can be found [here](https://github.com/Mojang/brigadier#installation).
1212

13-
> **Developer's Note:**
14-
>
15-
> For those that are unaware, [brigadier](https://github.com/Mojang/brigadier) is Mojang's command parser and dispatching framework. This is what the CommandAPI wraps around and is the main underlying source of its functionality.
13+
:::info
14+
15+
For those that are unaware, [brigadier](https://github.com/Mojang/brigadier) is Mojang's command parser and dispatching framework. This is what the CommandAPI wraps around and is the main underlying source of its functionality.
16+
17+
:::
1618

1719
The CommandAPI has been designed in such a way that you shouldn't have to access NMS in order to make use of the more "advanced" arguments and features - if you find that NMS is required to do something, [please make a new issue](https://github.com/CommandAPI/CommandAPI/issues/new/choose)!
1820

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package createcommands.functionsandtags;
2+
3+
import dev.jorel.commandapi.CommandAPICommand;
4+
import dev.jorel.commandapi.arguments.FunctionArgument;
5+
import dev.jorel.commandapi.wrappers.FunctionWrapper;
6+
7+
class FunctionWrapperRef {
8+
{
9+
// #region runExample
10+
new CommandAPICommand("runfunc")
11+
.withArguments(new FunctionArgument("function"))
12+
.executes((sender, args) -> {
13+
FunctionWrapper[] functions = (FunctionWrapper[]) args.get("function");
14+
for (FunctionWrapper function : functions) {
15+
function.run(); // The command executor in this case is 'sender'
16+
}
17+
})
18+
.register();
19+
// #endregion runExample
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package createcommands.functionsandtags
2+
3+
import dev.jorel.commandapi.CommandAPICommand
4+
import dev.jorel.commandapi.arguments.FunctionArgument
5+
import dev.jorel.commandapi.executors.CommandExecutor
6+
import dev.jorel.commandapi.wrappers.FunctionWrapper
7+
8+
fun functionWrapper() {
9+
// #region runExample
10+
CommandAPICommand("runfunc")
11+
.withArguments(FunctionArgument("function"))
12+
.executes(CommandExecutor { _, args ->
13+
val functions = args["function"] as Array<FunctionWrapper>
14+
for (function in functions) {
15+
function.run() // The command executor in this case is 'sender'
16+
}
17+
})
18+
.register()
19+
// #endregion runExample
20+
}

0 commit comments

Comments
 (0)