@ -31,11 +31,12 @@ The HuskSync API is available for the following platforms:
1. [API Introduction](#api-introduction)
1. [Setup with Maven](#11-setup-with-maven)
2. [Setup with Gradle](#12-setup-with-gradle)
2. [Creating a class to interface with the API](#3-creating-a-class-to-interface-with-the-api)
3. [Checking if HuskSync is present and creating the hook](#4-checking-if-husksync-is-present-and-creating-the-hook)
4. [Getting an instance of the API](#5-getting-an-instance-of-the-api)
5. [CompletableFuture and Optional basics](#6-completablefuture-and-optional-basics)
6. [Next steps](#7-next-steps)
2. [Adding HuskSync as a dependency](#2-adding-husksync-as-a-dependency)
3. [Creating a class to interface with the API](#3-creating-a-class-to-interface-with-the-api)
4. [Checking if HuskSync is present and creating the hook](#4-checking-if-husksync-is-present-and-creating-the-hook)
5. [Getting an instance of the API](#5-getting-an-instance-of-the-api)
6. [CompletableFuture and Optional basics](#6-completablefuture-and-optional-basics)
7. [Next steps](#7-next-steps)
## API Introduction
### 1.1 Setup with Maven
@ -83,7 +84,7 @@ dependencies {
```
</details>
### 2. Adding HuskSync as a dependency
## 2. Adding HuskSync as a dependency
- Add HuskSync to your `softdepend` (if you want to optionally use HuskSync) or `depend` (if your plugin relies on HuskSync) section in `plugin.yml` of your project.
```yaml
@ -146,7 +147,7 @@ public class HuskSyncAPIHook {
## 6. CompletableFuture and Optional basics
- HuskSync's API methods often deal with `CompletableFuture`s and `Optional`s.
- A `CompletableFuture` is an asynchronous callback mechanism. The method will be processed asynchronously and the data returned when it has been retrieved. Then, use `CompletableFuture#thenAccept(data -> {})` to do what you want to do with the `data` you requested after it has asynchronously been retrieved, to prevent lag.
- An `Optional` is a null-safe representation of data, or no data. You can check if the Optional is empty via `Optional#isEmpty()` (which will be returned by the API if no data could be found for the call you made). If the optional does contain data, you can get it via `Optional#get().
- An `Optional` is a null-safe representation of data, or no data. You can check if the Optional is empty via `Optional#isEmpty()` (which will be returned by the API if no data could be found for the call you made). If the optional does contain data, you can get it via `Optional#get()`.
> **Warning:** You should never call `#join()` on futures returned from the HuskSyncAPI as futures are processed on server asynchronous tasks, which could lead to thread deadlock and crash your server if you attempt to lock the main thread to process them.