Astral Realms Documentation Help

SnapshotCause

com.astralrealms.sync.model.snapshot.SnapshotCause

An enum representing the reason a player snapshot was created. Available in SnapshotCreatedEvent and stored in the snapshots database table.

Values

Value

Should Unload

Trigger

INITIALIZATION

No

The player's very first snapshot — fired on initial join for new players

DISCONNECT

Yes

The player disconnected from the server

DEATH

No

The player died

SERVER_SHUTDOWN

Yes

The server is shutting down (triggered during onDisable())

WORLD_SAVE

No

Periodic world save event

MANUAL

No

An admin triggered a snapshot via the /snapshots rollback GUI

shouldUnload()

public boolean shouldUnload()

When true, AstralSync calls UnloadableSnapshotAdapter.unload() on every registered UnloadableSnapshotAdapter after the snapshot is saved. Use this in adapters that need to release resources (e.g. clearing caches, removing registrations) when a player fully leaves the server.

Causes that unload: DISCONNECT, SERVER_SHUTDOWN.

Causes that do not unload: INITIALIZATION, DEATH, WORLD_SAVE, MANUAL — the player remains online and data stays loaded.

Example Usage

@EventHandler public void onSnapshotCreated(SnapshotCreatedEvent event) { SnapshotCause cause = event.getCause(); switch (cause) { case DEATH -> auditLog("Death snapshot for " + event.getPlayer().getName()); case DISCONNECT, SERVER_SHUTDOWN -> cleanup(event.getPlayer()); default -> { /* no-op */ } } }

Checking in an UnloadableSnapshotAdapter

AstralSync handles the shouldUnload() check internally — you do not need to check it yourself. Just implement UnloadableSnapshotAdapter and the unload() method will be called at the right time:

public class MyAdapter implements UnloadableSnapshotAdapter<MyData> { @Override public void unload(DataHolder holder, Player player, MyData data) { // Called automatically when cause.shouldUnload() == true data.clearCache(); } // ... other SnapshotAdapter methods }
24 April 2026