Make sure a user has enough gold to make a purchase.
This commit is contained in:
parent
2c05743f62
commit
8a2efa2f0b
@ -27,7 +27,7 @@ public class DonationRepository extends MinecraftRepository
|
||||
private static String CREATE_GEM_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountGemTransactions (id INT NOT NULL AUTO_INCREMENT, accountId INT, reason VARCHAR(100), gems INT, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));";
|
||||
private static String INSERT_COIN_TRANSACTION = "INSERT INTO accountCoinTransactions(accountId, reason, coins) VALUES(?, ?, ?);";
|
||||
private static String UPDATE_ACCOUNT_COINS = "UPDATE accounts SET coins = coins + ? WHERE id = ?;";
|
||||
private static String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE id = ?;";
|
||||
private static String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE id = ? && gold >= ?;";
|
||||
private static String SET_ACCOUNT_GOLD = "UPDATE accounts SET gold = ? WHERE id = ?;";
|
||||
private static String UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_ = "UPDATE accounts SET gems = ?, coins = ? WHERE id = ? AND gems IS NULL AND coins IS NULL;";
|
||||
|
||||
@ -191,7 +191,8 @@ public class DonationRepository extends MinecraftRepository
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
boolean success = executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnInt("id", accountId)) > 0;
|
||||
ColumnInt min = new ColumnInt("gold", gold < 0 ? -gold : 0);
|
||||
boolean success = executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnInt("id", accountId), min) > 0;
|
||||
callback.run(success);
|
||||
}
|
||||
}), "Error updating player gold amount in DonationRepository : ");
|
||||
@ -199,6 +200,10 @@ public class DonationRepository extends MinecraftRepository
|
||||
|
||||
public void setGold(final Callback<Boolean> callback, final String giver, final String name, final int accountId, final int gold)
|
||||
{
|
||||
if (gold < 0)
|
||||
{
|
||||
throw new IllegalArgumentException("gold cannot be negative");
|
||||
}
|
||||
handleDatabaseCall(new DatabaseRunnable(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
|
Loading…
Reference in New Issue
Block a user