Carl!
This commit is contained in:
parent
37e5e97020
commit
05b1b91686
@ -56,7 +56,7 @@ public class PlayerTracker implements Listener
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_repository.removeElement(event.getPlayer().getName());
|
||||
_repository.removeElement(event.getPlayer().getName().toLowerCase());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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<BonusClientData> implements I
|
||||
|
||||
private ArrayList<String> _voteList;
|
||||
|
||||
// Donor Queues
|
||||
private Queue<GiveDonorData> _coinQueue;
|
||||
private Queue<GiveDonorData> _gemQueue;
|
||||
|
||||
/**
|
||||
* 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://vote2.mineplex.com");
|
||||
|
||||
_coinQueue = new LinkedList<GiveDonorData>();
|
||||
_gemQueue = new LinkedList<GiveDonorData>();
|
||||
|
||||
updateOffSet();
|
||||
}
|
||||
|
||||
@ -176,6 +183,9 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
||||
_voteList.add("http://vote2.mineplex.com");
|
||||
|
||||
_canVote = true;
|
||||
_coinQueue = new LinkedList<GiveDonorData>();
|
||||
_gemQueue = new LinkedList<GiveDonorData>();
|
||||
|
||||
|
||||
if (npcManager != null)
|
||||
{
|
||||
@ -279,7 +289,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> 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<BonusClientData> implements I
|
||||
if (gems > 0)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gems + " Gems")));
|
||||
_donationManager.RewardGems(new Callback<Boolean>()
|
||||
{
|
||||
@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<BonusClientData> implements I
|
||||
if (coins > 0)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(coins + " Coins")));
|
||||
_donationManager.RewardCoins(new Callback<Boolean>()
|
||||
{
|
||||
@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<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()
|
||||
{
|
||||
long sqlTime = getSqlTime();
|
||||
|
@ -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++;
|
||||
}
|
||||
}
|
@ -72,16 +72,15 @@ 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();
|
||||
|
||||
|
@ -159,7 +159,7 @@ public class FriendRepository extends RepositoryBase
|
||||
Set<String> friendNames = new HashSet<String>();
|
||||
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();
|
||||
}
|
||||
|
@ -28,6 +28,6 @@ public class PlayerStatus implements Data
|
||||
*/
|
||||
public String getDataId()
|
||||
{
|
||||
return _name;
|
||||
return _name.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
@ -46,8 +46,8 @@ public class VotifierManager extends MiniPlugin
|
||||
|
||||
private RedisConfig _usConfig;
|
||||
private RedisConfig _euConfig;
|
||||
// private RedisDataRepository<PlayerStatus> _usPlayerRepo;
|
||||
// private RedisDataRepository<PlayerStatus> _euPlayerRepo;
|
||||
private RedisDataRepository<PlayerStatus> _usPlayerRepo;
|
||||
private RedisDataRepository<PlayerStatus> _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<PlayerStatus>(_usConfig.getConnection(true, "DefaultConnection"),
|
||||
// _usConfig.getConnection(false, "DefaultConnection"), Region.US, PlayerStatus.class, "playerStatus");
|
||||
// _euPlayerRepo = new RedisDataRepository<PlayerStatus>(_euConfig.getConnection(true, "DefaultConnection"),
|
||||
// _euConfig.getConnection(false, "DefaultConnection"), Region.EU, PlayerStatus.class, "playerStatus");
|
||||
_usPlayerRepo = new RedisDataRepository<PlayerStatus>(_usConfig.getConnection(true, "DefaultConnection"),
|
||||
_usConfig.getConnection(false, "DefaultConnection"), Region.US, PlayerStatus.class, "playerStatus");
|
||||
_euPlayerRepo = new RedisDataRepository<PlayerStatus>(_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,11 +74,16 @@ 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);
|
||||
|
||||
runAsync(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
UUID uuid = UUIDFetcher.getUUIDOf(playerName);
|
||||
if (uuid == null)
|
||||
{
|
||||
@ -91,15 +96,38 @@ public class VotifierManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
awardBonus(playerName, uuid, new Callback<Integer>()
|
||||
final UUID finalUuid = uuid;
|
||||
awardBonus(playerName, finalUuid, new Callback<Integer>()
|
||||
{
|
||||
@Override
|
||||
public void run(Integer gems)
|
||||
public void run(final Integer gems)
|
||||
{
|
||||
notifyServer(playerName, gems, false);
|
||||
notifyServer(playerName, gems, true);
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user