diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index a8bc40c04..0c096b119 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -31,6 +31,7 @@ import com.google.common.collect.Sets; import com.google.gson.Gson; import mineplex.cache.player.PlayerCache; +import mineplex.cache.player.PlayerInfo; import mineplex.core.MiniPlugin; import mineplex.core.account.command.TestRank; import mineplex.core.account.command.UpdateRank; @@ -260,6 +261,53 @@ public class CoreClientManager extends MiniPlugin loadClientByName(playerName, client -> runnable.run()); } + public void loadClientByUUID(UUID uuid, Consumer loadedClient) + { + runAsync(() -> + { + AtomicReference 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 loadedClient) { runAsync(() -> diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java index 264da1eae..b3fdc3e2a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java @@ -363,6 +363,10 @@ public class TreasureLocation implements Listener { return; } + if (_currentTreasure.getCenterBlock().getWorld() != event.getTo().getWorld()) + { + return; + } double toDistanceFromCenter = _currentTreasure.getCenterBlock().getLocation().add(0.5, 1.5, 0.5).distanceSquared(event.getTo()); if (toDistanceFromCenter <= 16) { diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java index f9bf43da3..b36ab85d8 100644 --- a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java +++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java @@ -2,17 +2,13 @@ package mineplex.enjinTranslator; import java.text.SimpleDateFormat; import java.time.LocalDate; -import java.util.AbstractMap; import java.util.Date; -import java.util.Iterator; -import java.util.Map.Entry; import java.util.UUID; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClient; @@ -20,15 +16,12 @@ import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.Callback; -import mineplex.core.common.util.NautHashMap; import mineplex.core.donation.DonationManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.powerplayclub.PowerPlayClubRepository; import mineplex.core.punish.Category; import mineplex.core.punish.Punish; import mineplex.core.server.util.TransactionResponse; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; import mineplex.enjinTranslator.purchase.PurchaseManager; public class Enjin extends MiniPlugin implements CommandExecutor @@ -40,7 +33,6 @@ public class Enjin extends MiniPlugin implements CommandExecutor private PowerPlayClubRepository _powerPlayClubRepository; private Punish _punish; - private NautHashMap> _cachedUUIDs = new NautHashMap>(); private static Object _commandLock = new Object(); public long _lastPoll = System.currentTimeMillis() - 120000; @@ -63,21 +55,6 @@ public class Enjin extends MiniPlugin implements CommandExecutor plugin.getCommand("pull").setExecutor(this); } - @EventHandler - public void expireCachedUUIDs(UpdateEvent event) - { - if (event.getType() != UpdateType.MIN_01) - return; - - for (Iterator>> iterator = _cachedUUIDs.entrySet().iterator(); iterator.hasNext(); ) - { - Entry> entry = iterator.next(); - - if (System.currentTimeMillis() > entry.getValue().getValue()) - iterator.remove(); - } - } - @Override 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")) { - 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) { - 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 { - UUID uuid = null; - - 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(playerUUID, System.currentTimeMillis() + 240000)); + final String name = client.getName(); if (args[0].equalsIgnoreCase("chargeback")) { @@ -129,15 +97,15 @@ public class Enjin extends MiniPlugin implements CommandExecutor 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 (!checkForPowerPlayClub(args, name, playerUUID, client)) + if (!checkForPowerPlayClub(args, name, uuid, client)) { StringBuilder sb = new StringBuilder();