Fix the "delete(true)" and disallow ShopLoader to delete the shop

Former-commit-id: 6547be8913f204cb8701ccec54e12ca69e4f1ad0
This commit is contained in:
Ghost_chu committed 2020-08-12 20:58:42 +08:00
1 parent 173ab10f82
commit daf12860ea
3 files changed
+41 -30

No files matched your search

@@ -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());
@@ -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.");
// }
}
}
@@ -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;
}