Log error when shop can't be saved.

This commit is contained in:
Len 2022-10-03 20:36:49 +02:00
parent 76c68f6bfa
commit 69d90e16b5
2 changed files with 35 additions and 17 deletions

View File

@ -355,4 +355,14 @@ public class PlayerShop {
updateSign();
}
@Override
public String toString() {
return "Shop: " + this.getShopID()
+ "type :" + this.type
+ "server :" + this.server
+ "price :" + this.price
+ "amount :" + this.amount
+ "balance :" + this.balance
+ "lastTransaction :" + this.lastTransaction;
}
}

View File

@ -171,24 +171,32 @@ public record DatabaseHelper(PlayerShops plugin, DatabaseManager databaseManager
"container_location = ?, sign_location = ?, price = ?, amount = ?, balance = ?, " +
"item = ?, last_transaction = ? WHERE id = ?";
databaseManager().addDatabaseQuery(
new DatabaseQuery(query, ps -> {
ps.setString(1, shop.getOwnerName());
ps.setString(2, shop.getOwnerUUID().toString());
ps.setString(3, shop.getType().toString());
ps.setString(4, shop.getServer());
ps.setString(5, ShopUtil.locationToString(shop.getShopLocation()));
ps.setString(6, ShopUtil.locationToString(shop.getSignLocation()));
ps.setDouble(7, shop.getPrice());
ps.setInt(8, shop.getAmount());
ps.setDouble(9, shop.getBalance());
ItemStack itemStack = shop.getItemStack();
if (itemStack != null && !itemStack.getType().equals(Material.AIR)) {
ps.setBytes(10, shop.getItemStack().serializeAsBytes());
} else {
ps.setBytes(10, null);
new DatabaseQuery(query, new DatabaseQuery.DatabaseTask() {
@Override
public void edit(PreparedStatement ps) throws SQLException {
ps.setString(1, shop.getOwnerName());
ps.setString(2, shop.getOwnerUUID().toString());
ps.setString(3, shop.getType().toString());
ps.setString(4, shop.getServer());
ps.setString(5, ShopUtil.locationToString(shop.getShopLocation()));
ps.setString(6, ShopUtil.locationToString(shop.getSignLocation()));
ps.setDouble(7, shop.getPrice());
ps.setInt(8, shop.getAmount());
ps.setDouble(9, shop.getBalance());
ItemStack itemStack = shop.getItemStack();
if (itemStack != null && !itemStack.getType().equals(Material.AIR)) {
ps.setBytes(10, shop.getItemStack().serializeAsBytes());
} else {
ps.setBytes(10, null);
}
ps.setLong(11, shop.getLastTransaction());
ps.setString(12, shop.getShopID().toString());
}
@Override
public void onFailure(SQLException e) {
Logger.error("Could not save shop to database " + shop.toString() + "\n" + e);
}
ps.setLong(11, shop.getLastTransaction());
ps.setString(12, shop.getShopID().toString());
}), queue
);
}