Skip to content

Commit

Permalink
feat: add method for getting OnlineUser in common module
Browse files Browse the repository at this point in the history
(cherry picked from commit 1820a81)
  • Loading branch information
WiIIiam278 committed Dec 7, 2024
1 parent 548f9cc commit b9864e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions common/src/main/java/net/william278/husksync/api/HuskSyncAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ public CompletableFuture<Optional<User>> getUser(@NotNull UUID uuid) {
return plugin.supplyAsync(() -> plugin.getDatabase().getUser(uuid));
}

/**
* Get an {@link OnlineUser} by their UUID
*
* @param uuid the UUID of the user to get
* @return The {@link OnlineUser} wrapped in an optional, if they are online on <i>this</i> server.
* @since 3.7.2
*/
@NotNull
public Optional<OnlineUser> getOnlineUser(@NotNull UUID uuid) {
return plugin.getOnlineUser(uuid);
}

/**
* Get a {@link User} by their username
*
Expand Down
1 change: 0 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ The HuskSync API is available for the following platforms:
* `fabric` - Fabric API for Minecraft. Provides Fabric API event listeners and adapters to `net.minecraft` objects.
* `common` - Common API for all platforms.


<details>
<summary>Targeting older versions</summary>

Expand Down
1 change: 1 addition & 0 deletions docs/Data-Snapshot-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ huskSyncAPI.getUser(uuid).thenAccept(optionalUser -> {
</details>

* If you have an online `org.bukkit.Player` object, you can use `BukkitPlayer#adapt(player)` to get an `OnlineUser` (extends `User`), representing a logged-in user.
* You can also use `#getOnlineUser(UUID)` to get an OnlineUser by their UUID - note this only works for players online on the server the logic is called from, however.

<details>
<summary>Code Example &mdash; Getting an online user</summary>
Expand Down

0 comments on commit b9864e6

Please sign in to comment.