From daf12860ea00893ef8ad7234a75eefa25bb66fb6 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Wed, 12 Aug 2020 20:55:44 +0800 Subject: [PATCH] Fix the "delete(true)" and disallow ShopLoader to delete the shop Former-commit-id: 6547be8913f204cb8701ccec54e12ca69e4f1ad0 --- .../quickshop/database/DatabaseHelper.java | 8 +++- .../quickshop/shop/ContainerShop.java | 39 ++++++++++--------- .../maxgamer/quickshop/shop/ShopLoader.java | 24 +++++++----- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/database/DatabaseHelper.java b/src/main/java/org/maxgamer/quickshop/database/DatabaseHelper.java index 005ea7e12..f3c2a46c6 100644 --- a/src/main/java/org/maxgamer/quickshop/database/DatabaseHelper.java +++ b/src/main/java/org/maxgamer/quickshop/database/DatabaseHelper.java @@ -182,7 +182,13 @@ public class DatabaseHelper { ps.setInt(4, location.getBlockX()); ps.setInt(5, location.getBlockY()); ps.setInt(6, location.getBlockZ()); - ps.setString(7, location.getWorld().getName()); + String worldName = "undefined"; + if (location.getWorld() != null) { + worldName = location.getWorld().getName(); + } else { + plugin.getLogger().warning("Warning: Shop " + shop + " had null world name due we will save it as undefined world to trying keep data."); + } + ps.setString(7, worldName); ps.setInt(8, shop.isUnlimited() ? 1 : 0); ps.setInt(9, shop.getShopType().toID()); ps.setString(10, shop.saveExtraToJson()); diff --git a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java index 0a7ae1bcc..7b2300622 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java @@ -360,19 +360,19 @@ public class ContainerShop implements Shop { if (isLoaded) { this.onUnload(); } - // Delete the signs around it - for (Sign s : this.getSigns()) { - s.getBlock().setType(Material.AIR); - } - // Delete it from the database - // Refund if necessary - if (plugin.getConfig().getBoolean("shop.refund")) { - plugin.getEconomy().deposit(this.getOwner(), plugin.getConfig().getDouble("shop.cost")); - } if (memoryOnly) { // Delete it from memory plugin.getShopManager().removeShop(this); } else { + // Delete the signs around it + for (Sign s : this.getSigns()) { + s.getBlock().setType(Material.AIR); + } + // Delete it from the database + // Refund if necessary + if (plugin.getConfig().getBoolean("shop.refund")) { + plugin.getEconomy().deposit(this.getOwner(), plugin.getConfig().getDouble("shop.cost")); + } plugin.getShopManager().removeShop(this); plugin.getDatabaseHelper().removeShop(this); } @@ -1132,17 +1132,18 @@ public class ContainerShop implements Shop { return; } if (!Util.canBeShop(this.getLocation().getBlock())) { - Util.debugLog("Shop at " + this.getLocation() + "@" + this.getLocation().getBlock() + " container was missing, remove..."); + Util.debugLog("Shop at " + this.getLocation() + "@" + this.getLocation().getBlock() + " container was missing, unload from memory..."); this.onUnload(); - if (!createBackup) { - this.createBackup = Util.backupDatabase(); - } - if (createBackup) { - plugin.log("Deleting shop " + this + " request by non-shopable container."); - this.delete(); - } else { - Util.debugLog("Failed to create backup, shop at " + this.toString() + " won't to delete."); - } + this.delete(true); +// if (!createBackup) { +// this.createBackup = Util.backupDatabase(); +// } +// if (createBackup) { +// plugin.log("Deleting shop " + this + " request by non-shopable container."); +// this.delete(); +// } else { +// Util.debugLog("Failed to create backup, shop at " + this.toString() + " won't to delete."); +// } } } diff --git a/src/main/java/org/maxgamer/quickshop/shop/ShopLoader.java b/src/main/java/org/maxgamer/quickshop/shop/ShopLoader.java index 443b3ec78..74eed9ae6 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ShopLoader.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ShopLoader.java @@ -126,16 +126,20 @@ public class ShopLoader { Util.debugLog("Target block can't be a shop, removing it from the database..."); // shop.delete(); plugin.getShopManager().removeShop(shop); // Remove from Mem - if (!backupedDatabaseInDeleteProcess) { // Only backup db one time. - backupedDatabaseInDeleteProcess = Util.backupDatabase(); - if (backupedDatabaseInDeleteProcess) { - plugin.log("[SHOP LOADER] Removing shop in the database: " + shop.toString() + " - The block can't be shop"); - plugin.getDatabaseHelper().removeShop(shop); - } - } else { - plugin.log("[SHOP LOADER] Removing shop in the database: " + shop.toString() + " - The block can't be shop"); - plugin.getDatabaseHelper().removeShop(shop); - } + + //TODO: Only remove from memory, so if it actually is a bug, user won't lost all shops. + //TODO: Old shop will be deleted when in same location creating new shop. + +// if (!backupedDatabaseInDeleteProcess) { // Only backup db one time. +// backupedDatabaseInDeleteProcess = Util.backupDatabase(); +// if (backupedDatabaseInDeleteProcess) { +// plugin.log("[SHOP LOADER] Removing shop in the database: " + shop.toString() + " - The block can't be shop"); +// plugin.getDatabaseHelper().removeShop(shop); +// } +// } else { +// plugin.log("[SHOP LOADER] Removing shop in the database: " + shop.toString() + " - The block can't be shop"); +// plugin.getDatabaseHelper().removeShop(shop); +// } singleShopLoaded(singleShopLoadTimer); continue; }