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(); 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 = ?, " + "container_location = ?, sign_location = ?, price = ?, amount = ?, balance = ?, " +
"item = ?, last_transaction = ? WHERE id = ?"; "item = ?, last_transaction = ? WHERE id = ?";
databaseManager().addDatabaseQuery( databaseManager().addDatabaseQuery(
new DatabaseQuery(query, ps -> { new DatabaseQuery(query, new DatabaseQuery.DatabaseTask() {
ps.setString(1, shop.getOwnerName()); @Override
ps.setString(2, shop.getOwnerUUID().toString()); public void edit(PreparedStatement ps) throws SQLException {
ps.setString(3, shop.getType().toString()); ps.setString(1, shop.getOwnerName());
ps.setString(4, shop.getServer()); ps.setString(2, shop.getOwnerUUID().toString());
ps.setString(5, ShopUtil.locationToString(shop.getShopLocation())); ps.setString(3, shop.getType().toString());
ps.setString(6, ShopUtil.locationToString(shop.getSignLocation())); ps.setString(4, shop.getServer());
ps.setDouble(7, shop.getPrice()); ps.setString(5, ShopUtil.locationToString(shop.getShopLocation()));
ps.setInt(8, shop.getAmount()); ps.setString(6, ShopUtil.locationToString(shop.getSignLocation()));
ps.setDouble(9, shop.getBalance()); ps.setDouble(7, shop.getPrice());
ItemStack itemStack = shop.getItemStack(); ps.setInt(8, shop.getAmount());
if (itemStack != null && !itemStack.getType().equals(Material.AIR)) { ps.setDouble(9, shop.getBalance());
ps.setBytes(10, shop.getItemStack().serializeAsBytes()); ItemStack itemStack = shop.getItemStack();
} else { if (itemStack != null && !itemStack.getType().equals(Material.AIR)) {
ps.setBytes(10, null); 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 }), queue
); );
} }