Fixes for GoldManager

This commit is contained in:
Jonathan Williams 2015-07-19 21:04:59 -07:00
parent 3b47b01aea
commit 0772f2e91e
6 changed files with 38 additions and 17 deletions

View File

@ -356,29 +356,42 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
for (Player player : _goldQueue.keySet())
{
updateGoldQueue(player);
updateGoldQueue(null, player);
}
//Clean
_goldQueue.clear();
}
public void updateGoldQueue(Player player)
public void updateGoldQueue(final Callback<Boolean> callback, final Player player)
{
String caller = null;
int total = 0;
String tempCaller = null;
int tempTotal = 0;
for (String curCaller : _goldQueue.get(player).keySet())
{
caller = curCaller;
total += _goldQueue.get(player).get(curCaller);
tempCaller = curCaller;
tempTotal += _goldQueue.get(player).get(curCaller);
}
final String caller = tempCaller;
final int total = tempTotal;
if (caller == null)
return;
//Actually Add Gold
rewardGold(null, caller, player.getName(), ClientManager.Get(player).getAccountId(), total, false);
if (player.isOnline() && player.isValid())
rewardGold(callback, caller, player.getName(), ClientManager.Get(player).getAccountId(), total, false);
else
{
Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
public void run()
{
rewardGold(callback, caller, player.getName(), ClientManager.getCachedClientAccountId(player.getUniqueId()), total, false);
}
});
}
System.out.println("Queue Added [" + player + "] with Gold [" + total + "] for [" + caller + "]");

View File

@ -72,7 +72,7 @@ public class GoldCommand extends CommandBase<DonationManager>
private void rewardGold(final Player caller, final Player target, final String targetName, final int accountId, final int gold)
{
Plugin.RewardGold(new Callback<Boolean>()
Plugin.rewardGold(new Callback<Boolean>()
{
public void run(Boolean completed)
{

View File

@ -202,13 +202,18 @@ public class DonationRepository extends RepositoryBase
statement.setInt(2, gold);
statement.registerOutParameter(3, Types.BOOLEAN);
ResultSet resultSet = statement.executeQuery();
Boolean hasResults = statement.execute();
if (hasResults)
{
ResultSet resultSet = statement.getResultSet();
while (resultSet.next())
{
callback.run(resultSet.getBoolean(1));
}
}
}
catch (SQLException exception)
{
exception.printStackTrace();

View File

@ -138,7 +138,7 @@ public class ConfirmationPage<PluginType extends MiniPlugin, ShopType extends Sh
showResultsPage(TransactionResponse.InsufficientFunds);
else
{
getDonationManager().RewardGold(new Callback<Boolean>()
getDonationManager().rewardGold(new Callback<Boolean>()
{
@Override
public void run(Boolean data)

View File

@ -9,5 +9,7 @@
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Minecraft.Game.Core"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/craftbukkit.jar" sourcepath="/REPO_DIR/GitHubLibraries/CraftBukkit/src"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/gson-2.2.1.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Database"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/jooq-3.5.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -174,13 +174,14 @@ public class GoldManager extends MiniPlugin
public void addGold(Player player, int amount)
{
if (amount >= 0)
_donationManager.RewardGoldLater("GoldManager", player, amount);
}
public void deductGold(Callback<Boolean> resultCallback, Player player, int amount)
{
_donationManager.RewardGoldLater("GoldManager", player, amount);
_donationManager.updateGoldQueue(player);
_donationManager.RewardGoldLater("GoldManager", player, -amount);
_donationManager.updateGoldQueue(resultCallback, player);
}
public void cashIn(Player player, GoldToken token)