From 05b1b91686598ce12065216304dcec75c8f53592 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Thu, 13 Aug 2015 03:32:31 -0500 Subject: [PATCH] Carl! --- .../bungee/playerTracker/PlayerTracker.java | 2 +- .../mineplex/core/bonuses/BonusManager.java | 99 +++++++++++++------ .../mineplex/core/bonuses/GiveDonorData.java | 50 ++++++++++ .../core/bonuses/gui/buttons/VoteButton.java | 11 +-- .../core/friend/data/FriendRepository.java | 4 +- .../serverdata/data/PlayerStatus.java | 2 +- .../mineplex/votifier/VotifierManager.java | 84 ++++++++++------ 7 files changed, 183 insertions(+), 69 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/bonuses/GiveDonorData.java diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java index 24e40892c..1b8117d04 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java @@ -56,7 +56,7 @@ public class PlayerTracker implements Listener { public void run() { - _repository.removeElement(event.getPlayer().getName()); + _repository.removeElement(event.getPlayer().getName().toLowerCase()); } }); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java index 2521d993c..8ed1721c4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java @@ -7,6 +7,8 @@ import java.util.Calendar; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; +import java.util.Queue; import java.util.TimeZone; import mineplex.core.MiniClientPlugin; @@ -53,11 +55,9 @@ import mineplex.serverdata.commands.ServerCommandManager; import org.jooq.SQLDialect; import org.jooq.impl.DSL; import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity; import org.bukkit.entity.Entity; -import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -133,6 +133,10 @@ public class BonusManager extends MiniClientPlugin implements I private ArrayList _voteList; + // Donor Queues + private Queue _coinQueue; + private Queue _gemQueue; + /** * THIS SHOULD ONLY BE USED FOR VOTIFIER! */ @@ -149,6 +153,9 @@ public class BonusManager extends MiniClientPlugin implements I _voteList.add("http://vote1.mineplex.com"); _voteList.add("http://vote2.mineplex.com"); + _coinQueue = new LinkedList(); + _gemQueue = new LinkedList(); + updateOffSet(); } @@ -176,6 +183,9 @@ public class BonusManager extends MiniClientPlugin implements I _voteList.add("http://vote2.mineplex.com"); _canVote = true; + _coinQueue = new LinkedList(); + _gemQueue = new LinkedList(); + if (npcManager != null) { @@ -279,7 +289,7 @@ public class BonusManager extends MiniClientPlugin implements I { addPendingExplosion(player, player.getName()); UtilPlayer.message(player, F.main("Carl", "Thanks for voting for Mineplex!")); - UtilPlayer.message(player, F.main("Carl", "You received " + gemsRecieved + " Gems and 1 Carl Spinner Ticket!")); + UtilPlayer.message(player, F.main("Carl", "You received " + F.elem(gemsRecieved + " Gems") + " and " + F.elem("1 Carl Spinner Ticket") + "!")); } }); } @@ -700,20 +710,7 @@ public class BonusManager extends MiniClientPlugin implements I if (gems > 0) { UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gems + " Gems"))); - _donationManager.RewardGems(new Callback() - { - @Override - public void run(Boolean data) - { - if (data) - { - } - else - { - UtilPlayer.message(player, F.main("Carl", "Failed to process Gems")); - } - } - }, "Earned", player.getName(), player.getUniqueId(), gems, true); + _gemQueue.add(new GiveDonorData(player.getName(), coreClient.getAccountId(), player.getUniqueId(), gems)); } if (gold > 0) @@ -738,20 +735,7 @@ public class BonusManager extends MiniClientPlugin implements I if (coins > 0) { UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(coins + " Coins"))); - _donationManager.RewardCoins(new Callback() - { - @Override - public void run(Boolean data) - { - if (data) - { - } - else - { - UtilPlayer.message(player, F.main("Carl", "Failed to process Coins")); - } - } - }, "Earned", player.getName(), coreClient.getAccountId(), coins, true); + _coinQueue.add(new GiveDonorData(player.getName(), coreClient.getAccountId(), player.getUniqueId(), coins)); } if (tickets > 0) @@ -1065,6 +1049,59 @@ public class BonusManager extends MiniClientPlugin implements I } } + @EventHandler + public void processQueue(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTER) + return; + + // Gems + final GiveDonorData gemData = _gemQueue.poll(); + if (gemData != null && gemData.getAttempts() < 10) + { + _donationManager.RewardGems(new Callback() + { + @Override + public void run(Boolean data) + { + if (data) + { + System.out.println("Successfully processed " + gemData.getGiveAmount() + " gems for " + gemData.getPlayerName()); + } + else + { + gemData.incrementAttempts(); + System.out.println("Failed to process gems for " + gemData.getPlayerName() + " adding to back of queue. Attempts: " + gemData.getAttempts()); + _gemQueue.add(gemData); + } + } + }, "Earned", gemData.getPlayerName(), gemData.getUuid(), gemData.getGiveAmount()); + } + + // Coins + final GiveDonorData coinData = _coinQueue.poll(); + if (coinData != null && coinData.getAttempts() < 10) + { + _donationManager.RewardCoins(new Callback() + { + @Override + public void run(Boolean data) + { + if (data) + { + System.out.println("Successfully processed " + coinData.getGiveAmount() + " coins for " + coinData.getPlayerName()); + } + else + { + coinData.incrementAttempts(); + System.out.println("Failed to process coins for " + coinData.getPlayerName() + " adding to back of queue. Attempts: " + coinData.getAttempts()); + _coinQueue.add(coinData); + } + } + }, "Earned", coinData.getPlayerName(), coinData.getAccountId(), coinData.getGiveAmount()); + } + } + public String getVoteLink() { long sqlTime = getSqlTime(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/GiveDonorData.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/GiveDonorData.java new file mode 100644 index 000000000..1aa07d0d5 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/GiveDonorData.java @@ -0,0 +1,50 @@ +package mineplex.core.bonuses; + +import java.util.UUID; + +public class GiveDonorData +{ + private String _playerName; + private int _accountId; + private UUID _uuid; + private int _giveAmount; + private int _attempts; + + public GiveDonorData(String playerName, int accountId, UUID uuid, int giveAmount) + { + _playerName = playerName; + _accountId = accountId; + _uuid = uuid; + _giveAmount = giveAmount; + } + + public String getPlayerName() + { + return _playerName; + } + + public int getAccountId() + { + return _accountId; + } + + public UUID getUuid() + { + return _uuid; + } + + public int getGiveAmount() + { + return _giveAmount; + } + + public int getAttempts() + { + return _attempts; + } + + public void incrementAttempts() + { + _attempts++; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java index f277129b9..6bd8f9638 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java @@ -72,17 +72,16 @@ public class VoteButton implements GuiItem, Listener { getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f); - UtilPlayer.message(getPlayer(), "----------------------------------------"); + UtilPlayer.message(getPlayer(), "----------------------------------------------------"); UtilPlayer.message(getPlayer(), ""); new JsonMessage("Click to Open in Web Browser").click(ClickEvent.OPEN_URL, _url).sendToPlayer(getPlayer()); new JsonMessage(C.cGreen + _url).click(ClickEvent.OPEN_URL, _url).sendToPlayer(getPlayer()); - UtilPlayer.message(getPlayer(), ""); - UtilPlayer.message(getPlayer(), "----------------------------------------"); - - - + UtilPlayer.message(getPlayer(), "Please be patient, votes may take a few minutes to register."); + UtilPlayer.message(getPlayer(), ""); + UtilPlayer.message(getPlayer(), "----------------------------------------------------"); + getPlayer().closeInventory(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java index 359220020..c7ab1ae90 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java @@ -159,7 +159,7 @@ public class FriendRepository extends RepositoryBase Set friendNames = new HashSet(); for(FriendStatus status : friendData.getFriends()) { - friendNames.add(status.Name); + friendNames.add(status.Name.toLowerCase()); } // Load PlayerStatus' for friends @@ -188,7 +188,7 @@ public class FriendRepository extends RepositoryBase */ public String fetchPlayerServer(String playerName) { - PlayerStatus status = _repository.getElement(playerName); + PlayerStatus status = _repository.getElement(playerName.toLowerCase()); return (status == null) ? null : status.getServer(); } diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/PlayerStatus.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/PlayerStatus.java index 509006ca0..605caa387 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/PlayerStatus.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/PlayerStatus.java @@ -28,6 +28,6 @@ public class PlayerStatus implements Data */ public String getDataId() { - return _name; + return _name.toLowerCase(); } } diff --git a/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java b/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java index de00742a1..c87ef4896 100644 --- a/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java +++ b/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java @@ -46,8 +46,8 @@ public class VotifierManager extends MiniPlugin private RedisConfig _usConfig; private RedisConfig _euConfig; -// private RedisDataRepository _usPlayerRepo; -// private RedisDataRepository _euPlayerRepo; + private RedisDataRepository _usPlayerRepo; + private RedisDataRepository _euPlayerRepo; private JedisPool _usWritePool; private JedisPool _euWritePool; @@ -62,10 +62,10 @@ public class VotifierManager extends MiniPlugin _usConfig = ServerManager.loadConfig("us-redis.dat"); _euConfig = ServerManager.loadConfig("eu-redis.dat"); -// _usPlayerRepo = new RedisDataRepository(_usConfig.getConnection(true, "DefaultConnection"), -// _usConfig.getConnection(false, "DefaultConnection"), Region.US, PlayerStatus.class, "playerStatus"); -// _euPlayerRepo = new RedisDataRepository(_euConfig.getConnection(true, "DefaultConnection"), -// _euConfig.getConnection(false, "DefaultConnection"), Region.EU, PlayerStatus.class, "playerStatus"); + _usPlayerRepo = new RedisDataRepository(_usConfig.getConnection(true, "DefaultConnection"), + _usConfig.getConnection(false, "DefaultConnection"), Region.US, PlayerStatus.class, "playerStatus"); + _euPlayerRepo = new RedisDataRepository(_euConfig.getConnection(true, "DefaultConnection"), + _euConfig.getConnection(false, "DefaultConnection"), Region.EU, PlayerStatus.class, "playerStatus"); _usWritePool = Utility.generatePool(_usConfig.getConnection(true, "DefaultConnection")); _euWritePool = Utility.generatePool(_euConfig.getConnection(true, "DefaultConnection")); @@ -74,32 +74,60 @@ public class VotifierManager extends MiniPlugin @EventHandler public void handleVote(VotifierEvent event) { - Vote vote = event.getVote(); + final Vote vote = event.getVote(); final String playerName = vote.getUsername(); System.out.println("New Vote: " + playerName); - UUID uuid = UUIDFetcher.getUUIDOf(playerName); - if (uuid == null) - { - System.out.println("Failed to load UUID of " + playerName + " from UUIDFetcher. Trying with database"); - uuid = _clientManager.loadUUIDFromDB(playerName); - - if (uuid == null) - { - System.out.println("Failed to load UUID from database. Giving up on " + playerName); - } - } - - System.out.println("Loaded " + playerName + " with uuid " + uuid); - System.out.println("Attempting to award bonus"); - awardBonus(playerName, uuid, new Callback() + runAsync(new Runnable() { @Override - public void run(Integer gems) + public void run() { - notifyServer(playerName, gems, false); - notifyServer(playerName, gems, true); + UUID uuid = UUIDFetcher.getUUIDOf(playerName); + if (uuid == null) + { + System.out.println("Failed to load UUID of " + playerName + " from UUIDFetcher. Trying with database"); + uuid = _clientManager.loadUUIDFromDB(playerName); + + if (uuid == null) + { + System.out.println("Failed to load UUID from database. Giving up on " + playerName); + } + } + + String lowerPlayerName = playerName.toLowerCase(); + final PlayerStatus usStatus = _usPlayerRepo.getElement(lowerPlayerName); + final PlayerStatus euStatus = _euPlayerRepo.getElement(lowerPlayerName); + + System.out.println("Loaded " + playerName + " with uuid " + uuid); + System.out.println("Attempting to award bonus"); + final UUID finalUuid = uuid; + awardBonus(playerName, finalUuid, new Callback() + { + @Override + public void run(final Integer gems) + { + runSync(new Runnable() + { + @Override + public void run() + { + if (usStatus != null) + { + System.out.println("Found " + playerName + " on US " + usStatus.getServer()); + notifyServer(playerName, gems, Region.US, usStatus.getServer()); + } + + if (euStatus != null) + { + System.out.println("Found " + playerName + " on EU " + euStatus.getServer()); + notifyServer(playerName, gems, Region.EU, euStatus.getServer()); + } + } + }); + } + }); } }); System.out.println(); @@ -140,11 +168,11 @@ public class VotifierManager extends MiniPlugin // notifyServer(playerName, true); } - private void notifyServer(String playerName, int gems, boolean eu) + private void notifyServer(String playerName, int gems, Region region, String targetServer) { - JedisPool writePool = eu ? _euWritePool : _usWritePool; + JedisPool writePool = region == Region.EU ? _euWritePool : _usWritePool; - VotifierCommand command = new VotifierCommand(playerName, gems); + VotifierCommand command = new VotifierCommand(playerName, gems, targetServer); publishCommand(command, writePool); }