From 604550340e9c33ad6fd73e7e144f82148b91d87d Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Fri, 20 Mar 2020 23:01:22 +0800 Subject: [PATCH] Check location loaded and backup before deleting Former-commit-id: d87334dee7d01ac39c998fe96fca58d6ee07dcd7 --- .../maxgamer/quickshop/Shop/ContainerShop.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index 2945638fa..616f4b4e9 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -132,12 +132,12 @@ public class ContainerShop implements Shop { case VIRTUALITEM: try { this.displayItem = new VirtualDisplayItem(this); - }catch(Exception e){ + } catch (Exception e) { plugin.getConfig().set("shop.display-type", 0); plugin.saveConfig(); this.displayItem = new RealDisplayItem(this); //do not throw - plugin.getLogger().log(Level.SEVERE,"Failed to initialize VirtualDisplayItem, fallback to RealDisplayItem, are you using the latest version of ProtocolLib?",e); + plugin.getLogger().log(Level.SEVERE, "Failed to initialize VirtualDisplayItem, fallback to RealDisplayItem, are you using the latest version of ProtocolLib?", e); } break; default: @@ -331,7 +331,7 @@ public class ContainerShop implements Shop { Util.debugLog("Shop deletion was canceled because a plugin canceled it."); return; } - isDeleted=true; + isDeleted = true; // Unload the shop if (isLoaded) { this.onUnload(); @@ -1022,10 +1022,18 @@ public class ContainerShop implements Shop { if (!this.isLoaded) { return; } + if (!Util.isLoaded(this.getLocation())) { + return; + } if (!Util.canBeShop(this.getLocation().getBlock())) { - Util.debugLog("Shop at " + this.getLocation() + " container was missing, remove..."); + Util.debugLog("Shop at " + this.getLocation() + "@" + this.getLocation().getBlock() + " container was missing, remove..."); this.onUnload(); - this.delete(); + if (!createBackup) { + this.createBackup = Util.backupDatabase(); + } + if (createBackup) { + this.delete(); + } } }