9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-25 17:49:20 +00:00

Add ability to save user data on player death

This commit is contained in:
William
2022-10-11 20:58:19 +01:00
parent acd97a1cb0
commit 89d8b79ae3
3 changed files with 28 additions and 1 deletions

View File

@@ -26,6 +26,12 @@ public enum DataSaveCause {
* @since 2.0
*/
WORLD_SAVE,
/**
* Indicates data saved when the user died
*
* @since 2.1
*/
DEATH,
/**
* Indicates data saved when the server shut down
*

View File

@@ -176,6 +176,20 @@ public abstract class EventListener {
userData -> plugin.getDatabase().setUserData(user, userData, DataSaveCause.WORLD_SAVE).join()));
}
/**
* Asynchronously handles a player death
*
* @param user The user who died
*/
protected void handlePlayerDeath(@NotNull OnlineUser user) {
if (disabling || !plugin.getSettings().saveOnDeath) {
return;
}
user.getUserData(plugin.getLoggingAdapter(), plugin.getSettings())
.thenAccept(data -> data.ifPresent(userData -> plugin.getDatabase()
.setUserData(user, userData, DataSaveCause.DEATH)));
}
/**
* Handle an inventory menu closing
*