Merge remote-tracking branch 'refs/remotes/origin/develop' into feature/moba

This commit is contained in:
Sam 2017-06-06 19:31:20 +01:00
commit 16f9364772
3 changed files with 69 additions and 49 deletions

View File

@ -31,6 +31,7 @@ import com.google.common.collect.Sets;
import com.google.gson.Gson; import com.google.gson.Gson;
import mineplex.cache.player.PlayerCache; import mineplex.cache.player.PlayerCache;
import mineplex.cache.player.PlayerInfo;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.command.TestRank; import mineplex.core.account.command.TestRank;
import mineplex.core.account.command.UpdateRank; import mineplex.core.account.command.UpdateRank;
@ -260,6 +261,53 @@ public class CoreClientManager extends MiniPlugin
loadClientByName(playerName, client -> runnable.run()); loadClientByName(playerName, client -> runnable.run());
} }
public void loadClientByUUID(UUID uuid, Consumer<CoreClient> loadedClient)
{
runAsync(() ->
{
AtomicReference<CoreClient> loaded = new AtomicReference<>();
try
{
Gson gson = new Gson();
String response = _repository.getClientByUUID(uuid);
ClientToken token = gson.fromJson(response, ClientToken.class);
if (token.Name == null || token.Rank == null)
{
loaded.set(null);
return;
}
CoreClient client = Add(token.Name, uuid);
client.SetRank(Rank.valueOf(token.Rank), false);
client.setAccountId(_repository.login(_loginProcessors, uuid, client.getName()));
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
if (client.getAccountId() > 0)
{
PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid);
if (playerInfo != null)
{
PlayerCache.getInstance().updateAccountId(uuid, client.getAccountId());
}
}
loaded.set(client);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
UtilTasks.onMainThread(() -> loadedClient.accept(loaded.get())).run();
}
});
}
public void loadClientByName(String playerName, Consumer<CoreClient> loadedClient) public void loadClientByName(String playerName, Consumer<CoreClient> loadedClient)
{ {
runAsync(() -> runAsync(() ->

View File

@ -363,6 +363,10 @@ public class TreasureLocation implements Listener
{ {
return; return;
} }
if (_currentTreasure.getCenterBlock().getWorld() != event.getTo().getWorld())
{
return;
}
double toDistanceFromCenter = _currentTreasure.getCenterBlock().getLocation().add(0.5, 1.5, 0.5).distanceSquared(event.getTo()); double toDistanceFromCenter = _currentTreasure.getCenterBlock().getLocation().add(0.5, 1.5, 0.5).distanceSquared(event.getTo());
if (toDistanceFromCenter <= 16) if (toDistanceFromCenter <= 16)
{ {

View File

@ -2,17 +2,13 @@ package mineplex.enjinTranslator;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.AbstractMap;
import java.util.Date; import java.util.Date;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
@ -20,15 +16,12 @@ import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager; import mineplex.core.inventory.InventoryManager;
import mineplex.core.powerplayclub.PowerPlayClubRepository; import mineplex.core.powerplayclub.PowerPlayClubRepository;
import mineplex.core.punish.Category; import mineplex.core.punish.Category;
import mineplex.core.punish.Punish; import mineplex.core.punish.Punish;
import mineplex.core.server.util.TransactionResponse; import mineplex.core.server.util.TransactionResponse;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.enjinTranslator.purchase.PurchaseManager; import mineplex.enjinTranslator.purchase.PurchaseManager;
public class Enjin extends MiniPlugin implements CommandExecutor public class Enjin extends MiniPlugin implements CommandExecutor
@ -40,7 +33,6 @@ public class Enjin extends MiniPlugin implements CommandExecutor
private PowerPlayClubRepository _powerPlayClubRepository; private PowerPlayClubRepository _powerPlayClubRepository;
private Punish _punish; private Punish _punish;
private NautHashMap<String, Entry<UUID, Long>> _cachedUUIDs = new NautHashMap<String, Entry<UUID, Long>>();
private static Object _commandLock = new Object(); private static Object _commandLock = new Object();
public long _lastPoll = System.currentTimeMillis() - 120000; public long _lastPoll = System.currentTimeMillis() - 120000;
@ -63,21 +55,6 @@ public class Enjin extends MiniPlugin implements CommandExecutor
plugin.getCommand("pull").setExecutor(this); plugin.getCommand("pull").setExecutor(this);
} }
@EventHandler
public void expireCachedUUIDs(UpdateEvent event)
{
if (event.getType() != UpdateType.MIN_01)
return;
for (Iterator<Entry<String, Entry<UUID, Long>>> iterator = _cachedUUIDs.entrySet().iterator(); iterator.hasNext(); )
{
Entry<String, Entry<UUID, Long>> entry = iterator.next();
if (System.currentTimeMillis() > entry.getValue().getValue())
iterator.remove();
}
}
@Override @Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args)
{ {
@ -90,35 +67,26 @@ public class Enjin extends MiniPlugin implements CommandExecutor
if (label.equalsIgnoreCase("enjin_mineplex")) if (label.equalsIgnoreCase("enjin_mineplex"))
{ {
final String name = args[1]; final UUID uuid;
try
{
uuid = UUID.fromString(args[1]);
}
catch (IllegalArgumentException e)
{
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + args[1] + "; invalid UUID.");
return true;
}
_clientManager.loadClientByName(name, client -> _clientManager.loadClientByUUID(uuid, client ->
{ {
if (client == null) if (client == null)
{ {
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + ", isn't in our database."); System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + uuid + ", isn't in our database.");
} }
else else
{ {
UUID uuid = null; final String name = client.getName();
if (_cachedUUIDs.containsKey(name))
uuid = _cachedUUIDs.get(name).getKey();
else
{
// Fails if not in DB and if duplicate.
uuid = _clientManager.loadUUIDFromDB(name);
}
if (uuid == null)
{
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + ", no UUID.");
return;
}
final UUID playerUUID = uuid;
_cachedUUIDs.put(name, new AbstractMap.SimpleEntry<UUID, Long>(playerUUID, System.currentTimeMillis() + 240000));
if (args[0].equalsIgnoreCase("chargeback")) if (args[0].equalsIgnoreCase("chargeback"))
{ {
@ -129,15 +97,15 @@ public class Enjin extends MiniPlugin implements CommandExecutor
if (!checkForClansPurchase(args, name, client)) if (!checkForClansPurchase(args, name, client))
{ {
if (!checkForBoosterPurchase(args, name, playerUUID, client)) if (!checkForBoosterPurchase(args, name, uuid, client))
{ {
if (!checkForCoinPurchase(args, name, playerUUID, client)) if (!checkForCoinPurchase(args, name, uuid, client))
{ {
if (!checkForRankPurchase(args, name, playerUUID, client)) if (!checkForRankPurchase(args, name, uuid, client))
{ {
if (!checkForPurchase(args, name, client)) if (!checkForPurchase(args, name, client))
{ {
if (!checkForPowerPlayClub(args, name, playerUUID, client)) if (!checkForPowerPlayClub(args, name, uuid, client))
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();