Auto fix err shop record if possible

Former-commit-id: 6900202a84f6886806ee02909f11ee8831128fb6 [formerly b73fa96fbe29e20264fbb8a303c0334d85403467]
Former-commit-id: b7a5e3953077b747f757c7db7d82d1c283265901
This commit is contained in:
Ghost_chu committed 2019-06-14 20:31:44 +08:00
1 parent a072b8cd04
commit 485ee3a861
4 files changed
+23 -19

No files matched your search

@@ -158,8 +158,8 @@ public class DatabaseHelper {
}
public void createShop(@NotNull Database db, @NotNull String owner, double price, @NotNull ItemStack item, int unlimited, int shopType, @NotNull String world, int x, int y, int z) {
try {
public void createShop(@NotNull Database db, @NotNull String owner, double price, @NotNull ItemStack item, int unlimited, int shopType, @NotNull String world, int x, int y, int z)
throws SQLException {
String sqlString = "INSERT INTO " + QuickShop.instance
.getDbPrefix() + "shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
//QuickShop.instance.getDB().execute(q, owner, price, Util.serialize(item), x, y, z, world, unlimited, shopType);
@@ -174,9 +174,6 @@ public class DatabaseHelper {
ps.setInt(8, unlimited);
ps.setInt(9, shopType);
plugin.getDatabaseManager().add(ps);
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
public void sendMessage(@NotNull Database db, @NotNull UUID player, @NotNull String message, long time) {
@@ -160,25 +160,19 @@ public class ShopLoader {
try {
logger.warning("Connected: " + String.valueOf(plugin.getDatabase().getConnection().isClosed()));
} catch (SQLException | NullPointerException e) {
logger.warning("Connected: " + "FALSE - Failed reload status.");
logger.warning("Connected: " + "FALSE - Failed to load status.");
}
try {
logger.warning("Readonly: " + String.valueOf(plugin.getDatabase().getConnection().isReadOnly()));
} catch (SQLException | NullPointerException e) {
logger.warning("Readonly: " + "FALSE - Failed reload status.");
logger.warning("Readonly: " + "FALSE - Failed to load status.");
}
try {
logger.warning("ClientInfo: " + String.valueOf(plugin.getDatabase().getConnection().getClientInfo().toString()));
} catch (SQLException | NullPointerException e) {
logger.warning("ClientInfo: " + "FALSE - Failed reload status.");
}
try {
logger.warning("Metadata: " + String.valueOf(plugin.getDatabase().getConnection().getMetaData().toString()));
} catch (SQLException | NullPointerException e) {
logger.warning("Metadata: " + "FALSE - Failed reload status.");
logger.warning("ClientInfo: " + "FALSE - Failed to load status.");
}
logger.warning("#######################################");
@@ -1,5 +1,6 @@
package org.maxgamer.quickshop.Shop;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
@@ -68,9 +69,22 @@ public class ShopManager {
0), shop.getShopType().toID(), loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
// Add it to the world
addShop(loc.getWorld().getName(), shop);
} catch (Exception error) {
error.printStackTrace();
plugin.getLogger().log(Level.WARNING, "Could not create shop! Changes will revert after a reboot!");
} catch (SQLException error) {
plugin.getLogger().warning("SQLException detected, trying auto fixing...");
boolean backupSuccess = Util.backupDatabase();
try {
if (backupSuccess) {
plugin.getDatabaseHelper().removeShop(plugin.getDatabase(), loc.getBlockX(), loc.getBlockY(), loc
.getBlockZ(), loc.getWorld().getName());
} else {
plugin.getLogger().warning("Failed to backup database, all changes will revert after a reboot.");
}
} catch (SQLException error2) {
//Failed removing
plugin.getLogger().warning("Failed to autofix, all changes will revert after a reboot.");
error.printStackTrace();
error2.printStackTrace();
}
}
//Create sign
if (info.getSignBlock() != null && plugin.getConfig().getBoolean("shop.auto-sign")) {
@@ -1087,8 +1087,7 @@ public class Util {
return false;
}
String uuid = UUID.randomUUID().toString().replaceAll("_", "");
File bksqlfile = new File(dataFolder
.getAbsolutePath().toString() + "/shop_backup_" + uuid + ".db");
File bksqlfile = new File(dataFolder, "/shop_backup_" + uuid + ".db");
try {
Files.copy(sqlfile, bksqlfile);
} catch (Exception e1) {