Skip to content

Commit

Permalink
fix: death save updating player
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Feb 17, 2024
1 parent a5d3015 commit 67ef488
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected final void saveOnWorldSave(@NotNull List<OnlineUser> usersInWorld) {
usersInWorld.stream()
.filter(user -> !plugin.isLocked(user.getUuid()) && !user.isNpc())
.forEach(user -> plugin.getDataSyncer().saveData(
user, user.createSnapshot(DataSnapshot.SaveCause.WORLD_SAVE), null
user, user.createSnapshot(DataSnapshot.SaveCause.WORLD_SAVE)
));
}

Expand All @@ -101,7 +101,7 @@ protected void saveOnPlayerDeath(@NotNull OnlineUser user, @NotNull Data.Items i

final DataSnapshot.Packed snapshot = user.createSnapshot(DataSnapshot.SaveCause.DEATH);
snapshot.edit(plugin, (data -> data.getInventory().ifPresent(inventory -> inventory.setContents(items))));
plugin.getDataSyncer().saveData(user, snapshot, (u, d) -> plugin.getRedisManager().sendUserDataUpdate(u, d));
plugin.getDataSyncer().saveData(user, snapshot);
}

/**
Expand Down Expand Up @@ -170,7 +170,6 @@ private Map.Entry<String, String> toEntry() {
return Map.entry(name().toLowerCase(), defaultPriority.name());
}


@SuppressWarnings("unchecked")
@NotNull
public static Map<String, String> getDefaults() {
Expand Down
16 changes: 16 additions & 0 deletions common/src/main/java/net/william278/husksync/sync/DataSyncer.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ public void saveData(@NotNull User user, @NotNull DataSnapshot.Packed data,
);
}

/**
* Save a {@link DataSnapshot.Packed user's data snapshot} to the database,
* first firing the {@link net.william278.husksync.event.DataSaveEvent}. This will not update data on Redis.
*
* @param user the user to save the data for
* @param data the data to save
* @apiNote Data will not be saved if the {@link net.william278.husksync.event.DataSaveEvent} is cancelled.
* Note that this method can also edit the data before saving it.
* @implNote Note that the {@link net.william278.husksync.event.DataSaveEvent} will <b>not</b> be fired if the
* save cause is {@link DataSnapshot.SaveCause#SERVER_SHUTDOWN}.
* @since 3.3.3
*/
public void saveData(@NotNull User user, @NotNull DataSnapshot.Packed data) {
saveData(user, data, null);
}

// Adds a snapshot to the database and runs the after consumer
@Blocking
private void addSnapshotToDatabase(@NotNull User user, @NotNull DataSnapshot.Packed data,
Expand Down

0 comments on commit 67ef488

Please sign in to comment.