You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/create-commands/arguments/types/entities-arguments.md
+32-1Lines changed: 32 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -103,10 +103,41 @@ And there we have it! One thing to note is that entity selectors are still a val
103
103
104
104
## OfflinePlayer argument
105
105
106
-
The `OfflinePlayerArgument` class is identical to the `PlayerArgument` class, but instead of returning a `Player` object, it returns an `OfflinePlayer` object. Internally, this argument makes calls to Mojang servers (via Mojang's authlib), meaning it can be slightly slower than alternative methods (such as using a `StringArgument` and suggesting a list of existing offline players).
106
+
The `OfflinePlayerArgument` class is identical to the `PlayerArgument` class, but instead of returning a `Player` object, it returns an `OfflinePlayer` object. Internally, this argument makes calls to Mojang servers (via Mojang's authlib), meaning it can be slightly slower than alternative methods such as using a `AsyncOfflinePlayerArgument`, which runs the API call asynchronously, or using a `StringArgument` and suggesting a list of existing offline players.
107
107
108
108
The `OfflinePlayerArgument`_should_ be able to retrieve players that have never joined the server before.
109
109
110
+
## AsyncOfflinePlayer argument
111
+
112
+
The `AsyncOfflinePlayerArgument` class is identical to the `OfflinePlayerArgument` class, but instead of making the API call synchronously, it makes the API call asynchronously. This means that the command will not block the main thread while waiting for the API call to complete.
113
+
114
+
:::info
115
+
The `AsyncOfflinePlayerArgument` returns a `CompletableFuture<OfflinePlayer>` object, which can be used to retrieve the `OfflinePlayer` object when the API call is complete.
116
+
:::
117
+
118
+
::::tip Example - Checking if a player has joined before
119
+
120
+
Say we want to create a command that tells us if a player has joined the server before. We can use the `AsyncOfflinePlayerArgument` to fetch the `OfflinePlayer` object asynchronously. That way we simply wait for the request to complete, and once it does, we can check if the player has joined the server before. We want to create a command of the following form:
121
+
122
+
```mccmd
123
+
/playedbefore <player>
124
+
```
125
+
126
+
We now want to get the `CompletableFuture<OfflinePlayer>` object from the `AsyncOfflinePlayerArgument` and then use it to get the `OfflinePlayer` object. We can define it like this:
We now successfully ran a command that asynchronously checks if a player has joined the server before without blocking the main thread despite making an API call.
138
+
139
+
::::
140
+
110
141
## Entity type argument
111
142
112
143

0 commit comments