diff --git a/common/src/main/java/net/william278/husksync/listener/EventListener.java b/common/src/main/java/net/william278/husksync/listener/EventListener.java index 96522fbe..ea8cca60 100644 --- a/common/src/main/java/net/william278/husksync/listener/EventListener.java +++ b/common/src/main/java/net/william278/husksync/listener/EventListener.java @@ -82,7 +82,7 @@ protected final void saveOnWorldSave(@NotNull List 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) )); } @@ -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); } /** @@ -170,7 +170,6 @@ private Map.Entry toEntry() { return Map.entry(name().toLowerCase(), defaultPriority.name()); } - @SuppressWarnings("unchecked") @NotNull public static Map getDefaults() { diff --git a/common/src/main/java/net/william278/husksync/sync/DataSyncer.java b/common/src/main/java/net/william278/husksync/sync/DataSyncer.java index bf6747c6..f69f8117 100644 --- a/common/src/main/java/net/william278/husksync/sync/DataSyncer.java +++ b/common/src/main/java/net/william278/husksync/sync/DataSyncer.java @@ -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 not 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,