Merge branch 'clans/beta' of https://github.com/Mineplex-LLC/Minecraft-PC into clans/beta

This commit is contained in:
Ben 2016-04-09 00:37:40 +01:00
commit 4bf19eebad
1 changed files with 30 additions and 25 deletions

View File

@ -27,20 +27,20 @@ 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 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 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_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 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;"; private static String UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_ = "UPDATE accounts SET gems = ?, coins = ? WHERE id = ? AND gems IS NULL AND coins IS NULL;";
private String _webAddress; private String _webAddress;
public DonationRepository(JavaPlugin plugin, String webAddress) public DonationRepository(JavaPlugin plugin, String webAddress)
{ {
super(plugin, DBPool.getAccount()); super(plugin, DBPool.getAccount());
_webAddress = webAddress; _webAddress = webAddress;
} }
public void PurchaseKnownSalesPackage(final Callback<TransactionResponse> callback, String name, final String uuid, final int cost, final int salesPackageId) public void PurchaseKnownSalesPackage(final Callback<TransactionResponse> callback, String name, final String uuid, final int cost, final int salesPackageId)
{ {
final PurchaseToken token = new PurchaseToken(); final PurchaseToken token = new PurchaseToken();
token.AccountName = name; token.AccountName = name;
@ -61,7 +61,7 @@ public class DonationRepository extends MinecraftRepository
}); });
} }
}; };
handleDatabaseCall(new DatabaseRunnable(new Runnable() handleDatabaseCall(new DatabaseRunnable(new Runnable()
{ {
public void run() public void run()
@ -70,7 +70,7 @@ public class DonationRepository extends MinecraftRepository
} }
}), "Error purchasing known sales package in DonationRepository : "); }), "Error purchasing known sales package in DonationRepository : ");
} }
public void PurchaseUnknownSalesPackage(final Callback<TransactionResponse> callback, final String name, final int accountId, final String packageName, final CurrencyType currencyType, final int cost) public void PurchaseUnknownSalesPackage(final Callback<TransactionResponse> callback, final String name, final int accountId, final String packageName, final CurrencyType currencyType, final int cost)
{ {
final UnknownPurchaseToken token = new UnknownPurchaseToken(); final UnknownPurchaseToken token = new UnknownPurchaseToken();
@ -96,7 +96,7 @@ public class DonationRepository extends MinecraftRepository
executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", -cost), new ColumnInt("id", accountId)); executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", -cost), new ColumnInt("id", accountId));
} }
} }
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
{ {
@Override @Override
@ -107,7 +107,7 @@ public class DonationRepository extends MinecraftRepository
}); });
} }
}; };
handleDatabaseCall(new DatabaseRunnable(new Runnable() handleDatabaseCall(new DatabaseRunnable(new Runnable()
{ {
public void run() public void run()
@ -116,18 +116,18 @@ public class DonationRepository extends MinecraftRepository
} }
}), "Error purchasing unknown sales package in DonationRepository : "); }), "Error purchasing unknown sales package in DonationRepository : ");
} }
public void gemReward(final Callback<Boolean> callback, final String giver, String name, final String uuid, final int greenGems) public void gemReward(final Callback<Boolean> callback, final String giver, String name, final String uuid, final int greenGems)
{ {
final GemRewardToken token = new GemRewardToken(); final GemRewardToken token = new GemRewardToken();
token.Source = giver; token.Source = giver;
token.Name = name; token.Name = name;
token.Amount = greenGems; token.Amount = greenGems;
final Callback<Boolean> extraCallback = new Callback<Boolean>() final Callback<Boolean> extraCallback = new Callback<Boolean>()
{ {
public void run(final Boolean response) public void run(final Boolean response)
{ {
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
{ {
@Override @Override
@ -138,7 +138,7 @@ public class DonationRepository extends MinecraftRepository
}); });
} }
}; };
handleDatabaseCall(new DatabaseRunnable(new Runnable() handleDatabaseCall(new DatabaseRunnable(new Runnable()
{ {
public void run() public void run()
@ -147,14 +147,14 @@ public class DonationRepository extends MinecraftRepository
} }
}), "Error updating player gem amount in DonationRepository : "); }), "Error updating player gem amount in DonationRepository : ");
} }
public void rewardCoins(final Callback<Boolean> callback, final String giver, String name, final int accountId, final int coins) public void rewardCoins(final Callback<Boolean> callback, final String giver, String name, final int accountId, final int coins)
{ {
final GemRewardToken token = new GemRewardToken(); final GemRewardToken token = new GemRewardToken();
token.Source = giver; token.Source = giver;
token.Name = name; token.Name = name;
token.Amount = coins; token.Amount = coins;
final Callback<Boolean> extraCallback = new Callback<Boolean>() final Callback<Boolean> extraCallback = new Callback<Boolean>()
{ {
public void run(final Boolean response) public void run(final Boolean response)
@ -164,7 +164,7 @@ public class DonationRepository extends MinecraftRepository
//executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", coins), new ColumnInt("id", accountId)); //executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", coins), new ColumnInt("id", accountId));
//executeUpdate(INSERT_COIN_TRANSACTION, new ColumnInt("id", accountId), new ColumnVarChar("reason", 100, "Rewarded by " + giver), new ColumnInt("coins", coins)); //executeUpdate(INSERT_COIN_TRANSACTION, new ColumnInt("id", accountId), new ColumnVarChar("reason", 100, "Rewarded by " + giver), new ColumnInt("coins", coins));
} }
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
{ {
@Override @Override
@ -175,7 +175,7 @@ public class DonationRepository extends MinecraftRepository
}); });
} }
}; };
handleDatabaseCall(new DatabaseRunnable(new Runnable() handleDatabaseCall(new DatabaseRunnable(new Runnable()
{ {
public void run() public void run()
@ -184,21 +184,26 @@ public class DonationRepository extends MinecraftRepository
} }
}), "Error updating player coin amount in DonationRepository : "); }), "Error updating player coin amount in DonationRepository : ");
} }
public void rewardGold(final Callback<Boolean> callback, final String giver, final String name, final int accountId, final int gold) public void rewardGold(final Callback<Boolean> callback, final String giver, final String name, final int accountId, final int gold)
{ {
handleDatabaseCall(new DatabaseRunnable(new Runnable() handleDatabaseCall(new DatabaseRunnable(new Runnable()
{ {
public void run() 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); callback.run(success);
} }
}), "Error updating player gold amount in DonationRepository : "); }), "Error updating player gold amount in DonationRepository : ");
} }
public void setGold(final Callback<Boolean> callback, final String giver, final String name, final int accountId, final int gold) 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() handleDatabaseCall(new DatabaseRunnable(new Runnable()
{ {
public void run() public void run()
@ -208,7 +213,7 @@ public class DonationRepository extends MinecraftRepository
} }
}), "Error updating player gold amount in DonationRepository : "); }), "Error updating player gold amount in DonationRepository : ");
} }
@Override @Override
protected void initialize() protected void initialize()
{ {
@ -240,12 +245,12 @@ public class DonationRepository extends MinecraftRepository
public Donor retrieveDonorInfo(ResultSet resultSet) throws SQLException public Donor retrieveDonorInfo(ResultSet resultSet) throws SQLException
{ {
Donor donor = new Donor(); Donor donor = new Donor();
while (resultSet.next()) while (resultSet.next())
{ {
donor.setGold(resultSet.getInt(1)); donor.setGold(resultSet.getInt(1));
} }
return donor; return donor;
} }
} }