* Upgrade the Fabric version and rewrite the code. * Migrate the completed code of version 1.19.2. * fabric: some events. * Updated open source license to Apache 2.0. * Add Plan analyzer support. * Fix build. * `UnsupportedOperationException` * More fabric implementation work, update to v3's structure * Suppress compiler warnings * Add commands, adjust registration order * Inventory and ender chest data/serializers * Update license headers * Fixup shaded library relocations * Fix build * Potion effects & location serializers * Catch `Files.createDirectory(path);` in `#getDataFolder` * Update fabric.mod.json metadata, correct icon * Events for Fabric (#218) * Added apache commons pool2 dependency A NoClassDefFoundError would get thrown without this dependency. Relocation appears to not work very well either, so it has been excluded for now * Added in Item Pickup and Drop events and mixins * Update husksync.mixins.json * Switch drop item event to using Network Handler mixin * Implemented even more events - Interact block (place too) - Interact Entity - Use Item - Block Break - Player damage - Inventory Click (handles drops) - Player Commands * Re-implement the dropItem mixin * Set dropItem mixin as cancellable * deps: Include all bukkit runtime deps * fix/fabric: Supply AudienceProvider to `ConsoleUser` constructor * docs: credit Fabric porters :) * fix: Item deserialization now working * refactor: Remove inventory debug log * docs: Update `fabric.mod.json` * refactor: update with upstream changes * fix: dangling JD comment * fix: config file reference fixes * refactor: optimize imports, fix relocation * refactor: move tag references to common * refactor: use lombok for data / serializer methods * fix: bad annotating * refactor: adjust callback formatting * fabric: bump deps, refactor to match main branch * fabric: more serializer type work * feat: register more fabric data serializers also fixes a compile issue on bukkit, and refactors the JSON serializer to be in the common module * feat: implement remaining Fabric serializers * feat: add on-the-fly DFU for Fabric Now auto-upgrades item data to support version bumps. Also improved the schema a lil' bit. * feat: add missing mixins * feat: implement toKeep/toDrop option on Fabric * feat: apply stats on sync * build: append fabric MC version to file name * feat: add HuskSync API support for Fabric Also updates the docs * refactor: fixup a deprecation in the wrong spot * refactor: optimize fabric item serializing in-line with Bukkit * feat: implement viewer GUIs on Fabric * docs: Fabric is in Alpha for now --------- Co-authored-by: hanbings <hanbings@hanbings.io> Co-authored-by: Stampede <carterblowers01@gmail.com>
7.1 KiB
The HuskSync API (v3) provides methods for retrieving and updating data snapshots, a number of API Events for tracking when user data is synced and saved, and infrastructure for registering serializers to synchronise custom data types.
Compatibility
The HuskSync API shares version numbering with the plugin itself for consistency and convenience. Please note minor and patch plugin releases may make API additions and deprecations, but will not introduce breaking changes without notice.
| API Version | HuskSync Versions | Supported |
|---|---|---|
| v3.x | v3.0—Current | ✅ |
| v2.x | v2.0—v2.2.8 | ❌ |
| v1.x | v1.0—v1.4.1 | ❌️ |
Platforms
Note: For versions older than
v3.3, the HuskSync API was only distributed for the Bukkit platform (asnet.william278:husksync)
The HuskSync API is available for the following platforms:
bukkit- Bukkit, Spigot, Paper, etc. Provides Bukkit API event listeners and adapters toorg.bukkitobjects.fabric- Fabric API for Minecraft. Provides Fabric API event listeners and adapters tonet.minecraftobjects.common- Common API for all platforms.
Targeting older versions
- The HuskSync API was only distributed for the Bukkit module prior to
v3.3; the artifact ID wasnet.william278:husksyncinstead ofnet.william278.husksync:husksync-PLATFORM. - HuskSync versions prior to
v2.2.5are distributed on JitPack, and you will need to use thehttps://jitpack.iorepository instead.
Table of Contents
- API Introduction
- Adding HuskSync as a dependency
- Creating a class to interface with the API
- Checking if HuskSync is present and creating the hook
- Getting an instance of the API
- CompletableFuture and Optional basics
- Next steps
API Introduction
1.1 Setup with Maven
Maven setup information
Add the repository to your pom.xml as per below. You can alternatively specify /snapshots for the repository containing the latest development builds (not recommended).
<repositories>
<repository>
<id>william278.net</id>
<url>https://repo.william278.net/releases</url>
</repository>
</repositories>
Add the dependency to your pom.xml as per below. Replace VERSION with the latest version of HuskSync (without the v):
<dependency>
<groupId>net.william278.husksync</groupId>
<artifactId>husksync-PLATFORM</artifactId>
<version>VERSION</version>
<scope>provided</scope>
</dependency>
1.2 Setup with Gradle
Gradle setup information
Add the dependency as per below to your build.gradle. You can alternatively specify /snapshots for the repository containing the latest development builds (not recommended).
allprojects {
repositories {
maven { url 'https://repo.william278.net/releases' }
}
}
Add the dependency as per below. Replace VERSION with the latest version of HuskSync (without the v):
dependencies {
compileOnly 'net.william278.husksync:husksync-PLATFORM:VERSION'
}
2. Adding HuskSync as a dependency
- Add HuskSync to your
softdepend(if you want to optionally use HuskSync) ordepend(if your plugin relies on HuskSync) section inplugin.ymlof your project.
name: MyPlugin
version: 1.0
main: net.william278.myplugin.MyPlugin
author: William278
description: 'A plugin that hooks with the HuskSync API!'
softdepend: # Or, use 'depend' here
- HuskSync
3. Creating a class to interface with the API
- Unless your plugin completely relies on HuskSync, you shouldn't put HuskSync API calls into your main class, otherwise if HuskSync is not installed you'll encounter
ClassNotFoundExceptions
public class HuskSyncAPIHook {
public HuskSyncAPIHook() {
// Ready to do stuff with the API
}
}
4. Checking if HuskSync is present and creating the hook
- Check to make sure the HuskSync plugin is present before instantiating the API hook class
public class MyPlugin extends JavaPlugin {
public HuskSyncAPIHook huskSyncAPIHook;
@Override
public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("HuskSync") != null) {
this.huskSyncAPIHook = new HuskSyncAPIHook();
}
}
}
5. Getting an instance of the API
- You can now get the API instance by calling
HuskSyncAPI#getInstance() - If targeting the Bukkit platform, you can also use
BukkitHuskSyncAPI#getBukkitInstance()to get the Bukkit-extended API instance (recommended)
import net.william278.husksync.api.HuskSyncAPI;
public class HuskSyncAPIHook {
private final HuskSyncAPI huskSyncAPI;
public HuskSyncAPIHook() {
this.huskSyncAPI = HuskSyncAPI.getInstance();
}
}
6. CompletableFuture and Optional basics
- HuskSync's API methods often deal with
CompletableFutures andOptionals. - A
CompletableFutureis an asynchronous callback mechanism. The method will be processed asynchronously and the data returned when it has been retrieved. Then, useCompletableFuture#thenAccept(data -> {})to do what you want to do with thedatayou requested after it has asynchronously been retrieved, to prevent lag. - An
Optionalis a null-safe representation of data, or no data. You can check if the Optional is empty viaOptional#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 viaOptional#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.
7. Next steps
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