From 10697c1f2efae488a3cd7d4264096799ee19c891 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Fri, 20 Mar 2020 21:50:00 +0800 Subject: [PATCH] Backup shops before we deleted Former-commit-id: c3ecbf3cfb78eaa93d5586e7fa488eae6a1220e1 --- .../maxgamer/quickshop/Shop/ContainerShop.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index 279fb635f..2945638fa 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -62,7 +62,10 @@ public class ContainerShop implements Shop { private volatile boolean isLoaded = false; @EqualsAndHashCode.Exclude - private volatile boolean isDeleted= false; + private volatile boolean isDeleted = false; + + @EqualsAndHashCode.Exclude + private volatile boolean createBackup = false; private ShopModerator moderator; @@ -929,6 +932,7 @@ public class ContainerShop implements Shop { /** * @return The chest this shop is based on. */ + public @Nullable Inventory getInventory() { try { if (location.getBlock().getState().getType() == Material.ENDER_CHEST @@ -950,8 +954,16 @@ public class ContainerShop implements Shop { container = (InventoryHolder) this.location.getBlock().getState(); return container.getInventory(); } catch (Exception e) { - this.delete(); - Util.debugLog("Inventory doesn't exist anymore: " + this + " shop was removed."); + if (!createBackup) { + createBackup = Util.backupDatabase(); + if (createBackup) { + this.delete(); + Util.debugLog("Inventory doesn't exist anymore: " + this + " shop was removed."); + } + } else { + this.delete(); + Util.debugLog("Inventory doesn't exist anymore: " + this + " shop was removed."); + } return null; } }