diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/RunnableStatus.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/RunnableStatus.java new file mode 100644 index 000000000..409cfc0fc --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/RunnableStatus.java @@ -0,0 +1,6 @@ +package mineplex.core.common.util; + +public interface RunnableStatus +{ + public boolean run(); +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java index 973c7da2d..dd157d0af 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java @@ -11,7 +11,6 @@ import java.util.Iterator; import mineplex.core.common.util.NautHashMap; import mineplex.core.database.column.Column; import mineplex.core.logger.Logger; -import mineplex.core.timing.TimingManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -229,14 +228,7 @@ public abstract class RepositoryBase implements Listener } catch (Exception exception) { - Logger.Instance.log(errorMessage + exception.getMessage()); - - databaseRunnable.incrementFailCount(); - - synchronized (_queueLock) - { - _failedQueue.put(databaseRunnable, errorMessage); - } + processFailedDatabaseCall(databaseRunnable, exception.getMessage(), errorMessage); } } }); @@ -244,6 +236,25 @@ public abstract class RepositoryBase implements Listener asyncThread.start(); } + protected void processFailedDatabaseCall(DatabaseRunnable databaseRunnable, String errorPreMessage, String runnableMessage) + { + if (databaseRunnable.getFailedCounts() < 4) + { + databaseRunnable.incrementFailCount(); + + synchronized (_queueLock) + { + _failedQueue.put(databaseRunnable, runnableMessage); + } + + Logger.Instance.log(errorPreMessage + runnableMessage); + } + else + { + Logger.Instance.log("Abandoning database call : " + runnableMessage); + } + } + @EventHandler public void processDatabaseQueue(UpdateEvent event) { @@ -259,37 +270,8 @@ public abstract class RepositoryBase implements Listener { for (Iterator runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext();) { - final DatabaseRunnable databaseRunnable = runnablesIterator.next(); - - Thread asyncThread = new Thread(new Runnable() - { - public void run() - { - try - { - databaseRunnable.run(); - } - catch (Exception exception) - { - Logger.Instance.log(_failedQueue.get(databaseRunnable) + exception.getMessage()); - - if (databaseRunnable.getFailedCounts() < 4) - { - synchronized (_queueLock) - { - _failedQueue.put(databaseRunnable, _failedQueue.get(databaseRunnable)); - } - } - else - { - Logger.Instance.log("Abandoning database call : " + _failedQueue.get(databaseRunnable)); - } - } - } - }); - - runnablesIterator.remove(); - asyncThread.start(); + DatabaseRunnable databaseRunnable = runnablesIterator.next(); + handleDatabaseCall(databaseRunnable, _failedQueue.get(databaseRunnable)); } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index 70049fe90..b17cb0aa7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -30,6 +30,7 @@ public class DonationManager extends MiniPlugin private NautHashMap> _gemQueue = new NautHashMap>(); private NautHashMap> _coinQueue = new NautHashMap>(); + private NautHashMap> _goldQueue = new NautHashMap>(); public DonationManager(JavaPlugin plugin, String webAddress) { @@ -301,6 +302,88 @@ public class DonationManager extends MiniPlugin //Clean _coinQueue.clear(); } + + public void RewardGold(Callback callback, String caller, String name, UUID uuid, int amount) + { + RewardGold(callback, caller, name, uuid, amount, true); + } + + public void RewardGold(final Callback callback, final String caller, final String name, final UUID uuid, final int amount, final boolean updateTotal) + { + _repository.rewardGold(new Callback() + { + public void run(Boolean success) + { + if (success) + { + if (updateTotal) + { + Donor donor = Get(name); + + if (donor != null) + { + donor.addGold(amount); + } + } + + if (callback != null) + callback.run(true); + } + } + }, caller, name, uuid.toString(), amount); + } + + public void RewardGoldLater(final String caller, final Player player, final int amount) + { + if (!_goldQueue.containsKey(player)) + _goldQueue.put(player, new NautHashMap()); + + int totalAmount = amount; + + if (_goldQueue.get(player).containsKey(caller)) + totalAmount += _goldQueue.get(player).get(caller); + + _goldQueue.get(player).put(caller, totalAmount); + + //Do Temp Change + Donor donor = Get(player.getName()); + + if (donor != null) + donor.addGold(amount); + } + + @EventHandler + public void UpdateGoldQueue(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOWER) + return; + + for (Player player : _goldQueue.keySet()) + { + String caller = null; + int total = 0; + + for (String curCaller : _goldQueue.get(player).keySet()) + { + caller = curCaller; + total += _goldQueue.get(player).get(curCaller); + } + + if (caller == null) + continue; + + //Actually Add Gold + RewardGold(null, caller, player.getName(), player.getUniqueId(), total, false); + + System.out.println("Queue Added [" + player + "] with Gold [" + total + "] for [" + caller + "]"); + + //Clean + _goldQueue.get(player).clear(); + } + + //Clean + _goldQueue.clear(); + } public void applyKits(String playerName) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java index a1f2ef1dd..af5dcd692 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java @@ -12,6 +12,7 @@ public class Donor { private int _gems; private int _coins; + private int _gold; private boolean _donated; private List _salesPackagesOwned; private List _unknownSalesPackagesOwned; @@ -159,9 +160,19 @@ public class Donor { _coins += amount; } + + public void addGold(int amount) + { + _gold += amount; + } public List getCoinTransactions() { return _coinTransactions; } + + public int getGold() + { + return _gold; + } } 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 8166c808e..755c35f28 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java @@ -13,6 +13,7 @@ import mineplex.core.database.column.ColumnVarChar; import mineplex.core.donation.repository.token.GemRewardToken; import mineplex.core.donation.repository.token.PurchaseToken; import mineplex.core.donation.repository.token.UnknownPurchaseToken; +import mineplex.core.logger.Logger; import mineplex.core.server.remotecall.AsyncJsonWebCall; import mineplex.core.server.remotecall.JsonWebCall; import mineplex.core.server.util.TransactionResponse; @@ -23,6 +24,7 @@ public class DonationRepository extends RepositoryBase private static String CREATE_GEM_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountGemTransactions (id INT NOT NULL AUTO_INCREMENT, accounts_uuid VARCHAR(100), reason VARCHAR(100), gems INT, PRIMARY KEY (id), FOREIGN KEY (accounts_uuid) REFERENCES accounts(uuid), INDEX gemUuidIndex (accounts_uuid));"; private static String INSERT_COIN_TRANSACTION = "INSERT INTO accountCoinTransactions(accounts_uuid, reason, coins) VALUES(?, ?, ?);"; private static String UPDATE_ACCOUNT_COINS = "UPDATE accounts SET coins = coins + ? WHERE uuid = ?;"; + private static String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE uuid = ?;"; private static String UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_ = "UPDATE accounts SET gems = ?, coins = ? WHERE uuid = ? AND gems IS NULL AND coins IS NULL;"; private String _webAddress; @@ -174,6 +176,25 @@ public class DonationRepository extends RepositoryBase } }), "Error updating player coin amount in DonationRepository : "); } + + public void rewardGold(final Callback callback, final String giver, final String name, final String uuid, final int gold) + { + final GemRewardToken token = new GemRewardToken(); + token.Source = giver; + token.Name = name; + token.Amount = gold; + + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + public void run() + { + if (executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnVarChar("uuid", 100, uuid)) < 1) + { + Logger.Instance.log("Account gold wasn't updated for " + name); + } + } + }), "Error updating player gold amount in DonationRepository : "); + } @Override protected void initialize() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/BuildingPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/BuildingPage.java index 607cbca6e..69bf2b835 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/BuildingPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/BuildingPage.java @@ -1,5 +1,7 @@ package mineplex.game.clans.shop; +import org.bukkit.Material; + import mineplex.core.account.CoreClientManager; import mineplex.core.donation.DonationManager; import mineplex.core.shop.page.ShopPageBase; @@ -15,6 +17,7 @@ public class BuildingPage extends ShopPageBase @Override protected void BuildPage() { - + PvpItem item = new PvpItem(Material.STONE, (byte)0, 1, "Stone", 25, 64); + AddButton(1, item, new PvpShopButton(this, item)); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/PvpItem.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/PvpItem.java new file mode 100644 index 000000000..5d6aca0f7 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/PvpItem.java @@ -0,0 +1,25 @@ +package mineplex.game.clans.shop; + +import org.bukkit.Material; + +import mineplex.core.common.util.C; +import mineplex.core.shop.item.ShopItem; + +public class PvpItem extends ShopItem +{ + private static String LEFT_CLICK_BUY = C.cWhite + "Left-Click to Buy 1"; + + public PvpItem(Material type, byte data, int displayAmount, String name, int price, int bulkCount) + { + super(type, data, name, new String[] + { + C.cYellow + C.Bold + name, + C.cWhite + " ", + LEFT_CLICK_BUY, + C.cWhite + "Costs " + C.cGreen + "$" + price, + C.cWhite + " ", + C.cWhite + "Shift Left-Click to Buy " + bulkCount, + C.cWhite + "Costs " + C.cGreen + "$" + (price * bulkCount), + }, 0, false, false); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/PvpShopButton.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/PvpShopButton.java new file mode 100644 index 000000000..1117664e5 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/PvpShopButton.java @@ -0,0 +1,42 @@ +package mineplex.game.clans.shop; + +import org.bukkit.entity.Player; + +import mineplex.core.shop.item.ComplexButton; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.clans.ClansManager; + +public class PvpShopButton> extends ComplexButton +{ + protected PageType Page; + protected PvpItem Item; + + public PvpShopButton(PageType page, PvpItem item) + { + Page = page; + Item = item; + } + + @Override + public void ClickedLeft(Player player) + { + int balance = Page.getDonationManager().Get(player.getName()).getGold(); + + + } + + @Override + public void ClickedShiftLeft(Player player) + { + } + + @Override + public void ClickedRight(Player player) + { + } + + @Override + public void ClickedShiftRight(Player player) + { + } +} diff --git a/Website/LOCWebsite.suo b/Website/LOCWebsite.suo index 3db6bb26f..738ecd2f8 100644 Binary files a/Website/LOCWebsite.suo and b/Website/LOCWebsite.suo differ