From 6a9cd9db1c9553737570faf234d08d89fd685f79 Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Sat, 6 Oct 2018 13:41:24 -0400 Subject: [PATCH] Auto Save --- .../events/InventoryListeners.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/songoda/ultimatekits/events/InventoryListeners.java b/src/main/java/com/songoda/ultimatekits/events/InventoryListeners.java index d683f06..5d201cc 100644 --- a/src/main/java/com/songoda/ultimatekits/events/InventoryListeners.java +++ b/src/main/java/com/songoda/ultimatekits/events/InventoryListeners.java @@ -318,32 +318,37 @@ public class InventoryListeners implements Listener { @EventHandler public void onClose(InventoryCloseEvent event) { try { - final Player p = (Player) event.getPlayer(); + final Player player = (Player) event.getPlayer(); - KitEditorPlayerData kitPlayerData = instance.getKitEditor().getDataFor(p); + KitEditorPlayerData kitPlayerData = instance.getKitEditor().getDataFor(player); + + if (instance.getBlockEditor().getDataFor(player).getEditorType() != BlockEditorPlayerData.EditorType.NOTIN) { + KitEditor edit = instance.getKitEditor(); + edit.saveKit(player, player.getOpenInventory().getTopInventory()); + } if (!kitPlayerData.isInInventory() && kitPlayerData.getInventory().length != 0) { - p.getInventory().setContents(kitPlayerData.getInventory()); + player.getInventory().setContents(kitPlayerData.getInventory()); kitPlayerData.setInInventory(true); - p.updateInventory(); + player.updateInventory(); } kitPlayerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN); - BlockEditorPlayerData blockPlayerData = instance.getBlockEditor().getDataFor(p); + BlockEditorPlayerData blockPlayerData = instance.getBlockEditor().getDataFor(player); blockPlayerData.setEditorType(BlockEditorPlayerData.EditorType.NOTIN); - instance.buy.remove(p.getUniqueId()); + instance.buy.remove(player.getUniqueId()); - if (!instance.whereAt.containsKey(p.getUniqueId())) { + if (!instance.whereAt.containsKey(player.getUniqueId())) { return; } - instance.whereAt.remove(p.getUniqueId()); + instance.whereAt.remove(player.getUniqueId()); Bukkit.getScheduler().runTaskLater(instance, () -> { - if (!p.getOpenInventory().getTopInventory().getType().equals(InventoryType.CHEST)) - p.closeInventory(); + if (!player.getOpenInventory().getTopInventory().getType().equals(InventoryType.CHEST)) + player.closeInventory(); }, 1L); } catch (Exception ex) { Debugger.runReport(ex);