From 633847a254b6fc86884c18b2e1776d9b83f2248f Mon Sep 17 00:00:00 2001 From: William Date: Wed, 8 Jun 2022 11:17:53 +0100 Subject: [PATCH] Fix inventory clearing on world save --- .../java/net/william278/husksync/HuskSyncBukkit.java | 4 ++++ .../husksync/bukkit/listener/BukkitEventListener.java | 9 ++++++++- .../william278/husksync/bukkit/util/PlayerSetter.java | 4 ---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bukkit/src/main/java/net/william278/husksync/HuskSyncBukkit.java b/bukkit/src/main/java/net/william278/husksync/HuskSyncBukkit.java index 4757bc31..88f1f7ef 100644 --- a/bukkit/src/main/java/net/william278/husksync/HuskSyncBukkit.java +++ b/bukkit/src/main/java/net/william278/husksync/HuskSyncBukkit.java @@ -145,6 +145,10 @@ public void onDisable() { getLogger().info("Saving data for remaining online players..."); for (Player player : Bukkit.getOnlinePlayers()) { PlayerSetter.updatePlayerData(player, false); + + // Clear player inventory and ender chest + player.getInventory().clear(); + player.getEnderChest().clear(); } getLogger().info("Data save complete!"); } diff --git a/bukkit/src/main/java/net/william278/husksync/bukkit/listener/BukkitEventListener.java b/bukkit/src/main/java/net/william278/husksync/bukkit/listener/BukkitEventListener.java index 0f16ddb7..26f7cb19 100644 --- a/bukkit/src/main/java/net/william278/husksync/bukkit/listener/BukkitEventListener.java +++ b/bukkit/src/main/java/net/william278/husksync/bukkit/listener/BukkitEventListener.java @@ -39,7 +39,14 @@ public void onPlayerQuit(PlayerQuitEvent event) { return; // If the plugin has not been initialized correctly // Update the player's data - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> PlayerSetter.updatePlayerData(player, true)); + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + // Update data to proxy + PlayerSetter.updatePlayerData(player, true); + + // Clear player inventory and ender chest + player.getInventory().clear(); + player.getEnderChest().clear(); + }); } @EventHandler(priority = EventPriority.LOWEST) diff --git a/bukkit/src/main/java/net/william278/husksync/bukkit/util/PlayerSetter.java b/bukkit/src/main/java/net/william278/husksync/bukkit/util/PlayerSetter.java index 6ec80c5d..c2bcd52b 100644 --- a/bukkit/src/main/java/net/william278/husksync/bukkit/util/PlayerSetter.java +++ b/bukkit/src/main/java/net/william278/husksync/bukkit/util/PlayerSetter.java @@ -108,10 +108,6 @@ public static void updatePlayerData(Player player, boolean bounceBack) { } catch (IOException e) { plugin.getLogger().log(Level.SEVERE, "Failed to send a PlayerData update to the proxy", e); } - - // Clear player inventory and ender chest - player.getInventory().clear(); - player.getEnderChest().clear(); } /**