From 8f13a3955c45280df741c6cf31b15ee7f776da7f Mon Sep 17 00:00:00 2001 From: SnowCutieOwO <89032291+SnowCutieOwO@users.noreply.github.com> Date: Sun, 7 Apr 2024 19:33:10 +0800 Subject: [PATCH] docs: fix errors in API (#268) * Update API.md There's a little mistake and I found it and fixed. :) * Update API.md Fixed the wrong index --- docs/API.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/API.md b/docs/API.md index 6439e427..b5642ad6 100644 --- a/docs/API.md +++ b/docs/API.md @@ -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 { ``` -### 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. @@ -154,4 +155,4 @@ public class HuskSyncAPIHook { Now that you've got everything ready, you can start doing stuff with the HuskSync API! - [[Data Snapshot API]] — Get, edit, create & delete data snapshots and update players - [[Custom Data API]] — Register custom data types to sync your plugin's data with HuskSync -- [[API Events]] — Listen to, cancel and modify the result of data synchronization events \ No newline at end of file +- [[API Events]] — Listen to, cancel and modify the result of data synchronization events