From 0772f2e91e35295532701d8b77c66343dd37afba Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Sun, 19 Jul 2015 21:04:59 -0700 Subject: [PATCH] Fixes for GoldManager --- .../core/donation/DonationManager.java | 29 ++++++++++++++----- .../core/donation/command/GoldCommand.java | 2 +- .../repository/DonationRepository.java | 13 ++++++--- .../core/shop/page/ConfirmationPage.java | 2 +- Plugins/Mineplex.Game.Clans/.classpath | 2 ++ .../game/clans/economy/GoldManager.java | 7 +++-- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index 48c3acc06..41410dfd6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -356,29 +356,42 @@ public class DonationManager extends MiniDbClientPlugin for (Player player : _goldQueue.keySet()) { - updateGoldQueue(player); + updateGoldQueue(null, player); } //Clean _goldQueue.clear(); } - public void updateGoldQueue(Player player) + public void updateGoldQueue(final Callback 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 + "]"); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/command/GoldCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/command/GoldCommand.java index 6fa015312..80bbacbf3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/command/GoldCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/command/GoldCommand.java @@ -72,7 +72,7 @@ public class GoldCommand extends CommandBase private void rewardGold(final Player caller, final Player target, final String targetName, final int accountId, final int gold) { - Plugin.RewardGold(new Callback() + Plugin.rewardGold(new Callback() { public void run(Boolean completed) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java index 92f0ab42b..414f2aad7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java @@ -202,11 +202,16 @@ public class DonationRepository extends RepositoryBase statement.setInt(2, gold); statement.registerOutParameter(3, Types.BOOLEAN); - ResultSet resultSet = statement.executeQuery(); - - while (resultSet.next()) + Boolean hasResults = statement.execute(); + + if (hasResults) { - callback.run(resultSet.getBoolean(1)); + ResultSet resultSet = statement.getResultSet(); + + while (resultSet.next()) + { + callback.run(resultSet.getBoolean(1)); + } } } catch (SQLException exception) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java index 6e4ec5264..3b7c39b97 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java @@ -138,7 +138,7 @@ public class ConfirmationPage() + getDonationManager().rewardGold(new Callback() { @Override public void run(Boolean data) diff --git a/Plugins/Mineplex.Game.Clans/.classpath b/Plugins/Mineplex.Game.Clans/.classpath index d60d74d9e..33cd9fb00 100644 --- a/Plugins/Mineplex.Game.Clans/.classpath +++ b/Plugins/Mineplex.Game.Clans/.classpath @@ -9,5 +9,7 @@ + + diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java index 20c2f92b4..d15574122 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java @@ -174,13 +174,14 @@ public class GoldManager extends MiniPlugin public void addGold(Player player, int amount) { - _donationManager.RewardGoldLater("GoldManager", player, amount); + if (amount >= 0) + _donationManager.RewardGoldLater("GoldManager", player, amount); } public void deductGold(Callback 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)