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:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user