Adapter Interfaces
An adapter is a self-contained handler for one type of player data. AstralSync calls all registered adapters in sequence during save and load operations. Each adapter is responsible for:
Capturing current player state into a data object
Serializing that object to a binary stream
Deserializing it back from a binary stream
Applying it to the player
SnapshotAdapter\<T\>
com.astralrealms.sync.adapter.SnapshotAdapter
The base interface all adapters must implement.
Method Reference
key()
Returns the unique namespaced key identifying this adapter. Must be unique across all registered adapters.
Use a namespace that matches your plugin name:
create(Player)
Called when a player joins for the first time and no snapshot exists yet. Returns the default data instance. This is also used to initialize the holder entry if the adapter was not present in an older snapshot.
update(Player, T)
Called just before serialization. Updates object to reflect the player's current state and returns it. You may mutate object in place and return it, or return a new instance.
apply(Player, T)
Called on the main server thread after deserialization. Applies the loaded data to the player.
deserialize(DataHolder, BinaryMessage)
Reads a data object from the binary stream. Called during the load operation. If deserialization fails, AstralSync calls create(player) instead and logs a warning — this ensures a corrupted chunk does not prevent the rest of the snapshot from loading.
serialize(DataHolder, T, BinaryMessage)
Writes the data object to the binary stream. Called during the save operation. A serialization failure aborts the entire snapshot save.
VersionedSnapshotAdapter\<T extends VersionedData\>
com.astralrealms.sync.adapter.VersionedSnapshotAdapter
Extends SnapshotAdapter<T> and VersionedData. Use this when your data format may change across plugin versions.
Your data class must implement VersionedData:
How versioning works
AdapterContainer stores all registered versions of an adapter under the same key. When a snapshot is written, the current version number is stored alongside the data. When deserializing, the stored version is read first, and the matching adapter version is used to read the data.
This lets you add a v2 adapter while still being able to read old v1 snapshots from the database.
Example
Register both versions in onEnable():
UnloadableSnapshotAdapter\<T\>
com.astralrealms.sync.adapter.UnloadableSnapshotAdapter
Extends SnapshotAdapter<T>. Use this when your adapter allocates resources that must be released when the player fully leaves.
unload(DataHolder, Player, T)
Called automatically by AstralSync after a successful save whose SnapshotCause.shouldUnload() returns true (DISCONNECT, SERVER_SHUTDOWN).
You do not need to check shouldUnload() yourself — AstralSync handles this internally.
AdapterContainer
com.astralrealms.sync.container.AdapterContainer
Singleton registry that manages all registered adapters.
Instance: AdapterContainer.INSTANCE
Methods
Method | Description |
|---|---|
| Register an adapter (prefer |
| Remove all versions of an adapter by key |
| Find the latest version of an adapter |
| Find a specific version of an adapter |
| Map of key → latest adapter version |
| Map of key → all versions map |