This commit is contained in:
Shaun Bennett 2015-08-13 03:32:31 -05:00
parent 37e5e97020
commit 05b1b91686
7 changed files with 183 additions and 69 deletions

View File

@ -56,7 +56,7 @@ public class PlayerTracker implements Listener
{ {
public void run() public void run()
{ {
_repository.removeElement(event.getPlayer().getName()); _repository.removeElement(event.getPlayer().getName().toLowerCase());
} }
}); });
} }

View File

@ -7,6 +7,8 @@ import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.TimeZone; import java.util.TimeZone;
import mineplex.core.MiniClientPlugin; import mineplex.core.MiniClientPlugin;
@ -53,11 +55,9 @@ import mineplex.serverdata.commands.ServerCommandManager;
import org.jooq.SQLDialect; import org.jooq.SQLDialect;
import org.jooq.impl.DSL; import org.jooq.impl.DSL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -133,6 +133,10 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
private ArrayList<String> _voteList; private ArrayList<String> _voteList;
// Donor Queues
private Queue<GiveDonorData> _coinQueue;
private Queue<GiveDonorData> _gemQueue;
/** /**
* THIS SHOULD ONLY BE USED FOR VOTIFIER! * THIS SHOULD ONLY BE USED FOR VOTIFIER!
*/ */
@ -149,6 +153,9 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
_voteList.add("http://vote1.mineplex.com"); _voteList.add("http://vote1.mineplex.com");
_voteList.add("http://vote2.mineplex.com"); _voteList.add("http://vote2.mineplex.com");
_coinQueue = new LinkedList<GiveDonorData>();
_gemQueue = new LinkedList<GiveDonorData>();
updateOffSet(); updateOffSet();
} }
@ -176,6 +183,9 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
_voteList.add("http://vote2.mineplex.com"); _voteList.add("http://vote2.mineplex.com");
_canVote = true; _canVote = true;
_coinQueue = new LinkedList<GiveDonorData>();
_gemQueue = new LinkedList<GiveDonorData>();
if (npcManager != null) if (npcManager != null)
{ {
@ -279,7 +289,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{ {
addPendingExplosion(player, player.getName()); addPendingExplosion(player, player.getName());
UtilPlayer.message(player, F.main("Carl", "Thanks for voting for Mineplex!")); 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<BonusClientData> implements I
if (gems > 0) if (gems > 0)
{ {
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gems + " Gems"))); UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gems + " Gems")));
_donationManager.RewardGems(new Callback<Boolean>() _gemQueue.add(new GiveDonorData(player.getName(), coreClient.getAccountId(), player.getUniqueId(), gems));
{
@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);
} }
if (gold > 0) if (gold > 0)
@ -738,20 +735,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (coins > 0) if (coins > 0)
{ {
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(coins + " Coins"))); UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(coins + " Coins")));
_donationManager.RewardCoins(new Callback<Boolean>() _coinQueue.add(new GiveDonorData(player.getName(), coreClient.getAccountId(), player.getUniqueId(), coins));
{
@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);
} }
if (tickets > 0) if (tickets > 0)
@ -1065,6 +1049,59 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> 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<Boolean>()
{
@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<Boolean>()
{
@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() public String getVoteLink()
{ {
long sqlTime = getSqlTime(); long sqlTime = getSqlTime();

View File

@ -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++;
}
}

View File

@ -72,17 +72,16 @@ public class VoteButton implements GuiItem, Listener {
getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f); getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f);
UtilPlayer.message(getPlayer(), "----------------------------------------"); 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("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()); new JsonMessage(C.cGreen + _url).click(ClickEvent.OPEN_URL, _url).sendToPlayer(getPlayer());
UtilPlayer.message(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(); getPlayer().closeInventory();
} }

View File

@ -159,7 +159,7 @@ public class FriendRepository extends RepositoryBase
Set<String> friendNames = new HashSet<String>(); Set<String> friendNames = new HashSet<String>();
for(FriendStatus status : friendData.getFriends()) for(FriendStatus status : friendData.getFriends())
{ {
friendNames.add(status.Name); friendNames.add(status.Name.toLowerCase());
} }
// Load PlayerStatus' for friends // Load PlayerStatus' for friends
@ -188,7 +188,7 @@ public class FriendRepository extends RepositoryBase
*/ */
public String fetchPlayerServer(String playerName) public String fetchPlayerServer(String playerName)
{ {
PlayerStatus status = _repository.getElement(playerName); PlayerStatus status = _repository.getElement(playerName.toLowerCase());
return (status == null) ? null : status.getServer(); return (status == null) ? null : status.getServer();
} }

View File

@ -28,6 +28,6 @@ public class PlayerStatus implements Data
*/ */
public String getDataId() public String getDataId()
{ {
return _name; return _name.toLowerCase();
} }
} }

View File

@ -46,8 +46,8 @@ public class VotifierManager extends MiniPlugin
private RedisConfig _usConfig; private RedisConfig _usConfig;
private RedisConfig _euConfig; private RedisConfig _euConfig;
// private RedisDataRepository<PlayerStatus> _usPlayerRepo; private RedisDataRepository<PlayerStatus> _usPlayerRepo;
// private RedisDataRepository<PlayerStatus> _euPlayerRepo; private RedisDataRepository<PlayerStatus> _euPlayerRepo;
private JedisPool _usWritePool; private JedisPool _usWritePool;
private JedisPool _euWritePool; private JedisPool _euWritePool;
@ -62,10 +62,10 @@ public class VotifierManager extends MiniPlugin
_usConfig = ServerManager.loadConfig("us-redis.dat"); _usConfig = ServerManager.loadConfig("us-redis.dat");
_euConfig = ServerManager.loadConfig("eu-redis.dat"); _euConfig = ServerManager.loadConfig("eu-redis.dat");
// _usPlayerRepo = new RedisDataRepository<PlayerStatus>(_usConfig.getConnection(true, "DefaultConnection"), _usPlayerRepo = new RedisDataRepository<PlayerStatus>(_usConfig.getConnection(true, "DefaultConnection"),
// _usConfig.getConnection(false, "DefaultConnection"), Region.US, PlayerStatus.class, "playerStatus"); _usConfig.getConnection(false, "DefaultConnection"), Region.US, PlayerStatus.class, "playerStatus");
// _euPlayerRepo = new RedisDataRepository<PlayerStatus>(_euConfig.getConnection(true, "DefaultConnection"), _euPlayerRepo = new RedisDataRepository<PlayerStatus>(_euConfig.getConnection(true, "DefaultConnection"),
// _euConfig.getConnection(false, "DefaultConnection"), Region.EU, PlayerStatus.class, "playerStatus"); _euConfig.getConnection(false, "DefaultConnection"), Region.EU, PlayerStatus.class, "playerStatus");
_usWritePool = Utility.generatePool(_usConfig.getConnection(true, "DefaultConnection")); _usWritePool = Utility.generatePool(_usConfig.getConnection(true, "DefaultConnection"));
_euWritePool = Utility.generatePool(_euConfig.getConnection(true, "DefaultConnection")); _euWritePool = Utility.generatePool(_euConfig.getConnection(true, "DefaultConnection"));
@ -74,32 +74,60 @@ public class VotifierManager extends MiniPlugin
@EventHandler @EventHandler
public void handleVote(VotifierEvent event) public void handleVote(VotifierEvent event)
{ {
Vote vote = event.getVote(); final Vote vote = event.getVote();
final String playerName = vote.getUsername(); final String playerName = vote.getUsername();
System.out.println("New Vote: " + playerName); System.out.println("New Vote: " + playerName);
UUID uuid = UUIDFetcher.getUUIDOf(playerName); runAsync(new Runnable()
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<Integer>()
{ {
@Override @Override
public void run(Integer gems) public void run()
{ {
notifyServer(playerName, gems, false); UUID uuid = UUIDFetcher.getUUIDOf(playerName);
notifyServer(playerName, gems, true); 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<Integer>()
{
@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(); System.out.println();
@ -140,11 +168,11 @@ public class VotifierManager extends MiniPlugin
// notifyServer(playerName, true); // 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); publishCommand(command, writePool);
} }