diff --git a/Plugins/BuildFiles/EnjinTranslator.xml b/Plugins/BuildFiles/EnjinTranslator.xml index 491280349..bf3c1fb4a 100644 --- a/Plugins/BuildFiles/EnjinTranslator.xml +++ b/Plugins/BuildFiles/EnjinTranslator.xml @@ -18,6 +18,9 @@ + + + diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java index 8301f97d5..e663d6e77 100644 --- a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java +++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java @@ -17,6 +17,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; @@ -144,105 +145,95 @@ public class Enjin extends MiniPlugin implements CommandExecutor if (label.equalsIgnoreCase("enjin_mineplex")) { final String name = args[1]; - UUID uuid = null; - if (_cachedUUIDs.containsKey(name)) - uuid = _cachedUUIDs.get(name).getKey(); - else + _clientManager.loadClientByName(name, new Runnable() { - // Fails if not in DB and if duplicate. - uuid = _clientManager.loadUUIDFromDB(name); - - if (uuid == null) - uuid = UUIDFetcher.getUUIDOf(name); - } - - if (uuid == null) - { - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + ", no UUID."); - return true; - } - - final UUID playerUUID = uuid; - - _cachedUUIDs.put(name, new AbstractMap.SimpleEntry(playerUUID, System.currentTimeMillis() + 240000)); - - if (args.length == 3 && args[0].equalsIgnoreCase("gem")) - { - final int amount = Integer.parseInt(args[2]); - - _donationManager.RewardGems(new Callback() + public void run() { - public void run (Boolean response) + final CoreClient client = _clientManager.Get(name); + + if (client == null) { - if (response) - { - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " gems."); - } + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + ", isn't in our database."); + } + else + { + UUID uuid = null; + + if (_cachedUUIDs.containsKey(name)) + uuid = _cachedUUIDs.get(name).getKey(); else { - _commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " gems. Queuing for run later."); + // Fails if not in DB and if duplicate. + uuid = _clientManager.loadUUIDFromDB(name); + + if (uuid == null) + uuid = UUIDFetcher.getUUIDOf(name); } - } - }, "purchase", name, playerUUID, amount); - } - else if (args.length == 3 && args[0].equalsIgnoreCase("coin")) - { - final int amount = Integer.parseInt(args[2]); - - _donationManager.RewardCoins(new Callback() - { - public void run (Boolean response) - { - if (response) + + if (uuid == null) { - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " coins."); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + ", no UUID."); + return; } - else - { - _commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " coins. Queuing for run later."); - } - } - }, "purchase", name, playerUUID, amount); - } - else if (args.length == 3 && args[0].equalsIgnoreCase("booster")) - { - int amount = Integer.parseInt(args[2]); - - _donationManager.PurchaseUnknownSalesPackage(null, name, playerUUID, "Gem Booster " + amount, false, 0, false); - _repository.addGemBooster(name, amount); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Gem Boosters" + "."); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("key")) - { - final int amount = Integer.parseInt(args[2]); - - if (args.length == 4) - { - _inventoryManager.addItemToInventoryForOffline(new Callback() - { - public void run(Boolean success) - { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Keys" + "."); - else + + final UUID playerUUID = uuid; + + _cachedUUIDs.put(name, new AbstractMap.SimpleEntry(playerUUID, System.currentTimeMillis() + 240000)); + + if (args.length == 3 && args[0].equalsIgnoreCase("gem")) + { + final int amount = Integer.parseInt(args[2]); + + _donationManager.RewardGems(new Callback() { - // Add arg so we don't add back to windows api call - _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); - } + public void run (Boolean response) + { + if (response) + { + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " gems."); + } + else + { + _commandQueue.add(new QueuedCommand(sender, command, label, args)); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " gems. Queuing for run later."); + } + } + }, "purchase", name, playerUUID, amount); + } + else if (args.length == 3 && args[0].equalsIgnoreCase("coin")) + { + final int amount = Integer.parseInt(args[2]); + + _donationManager.RewardCoins(new Callback() + { + public void run (Boolean response) + { + if (response) + { + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " coins."); + } + else + { + _commandQueue.add(new QueuedCommand(sender, command, label, args)); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " coins. Queuing for run later."); + } + } + }, "purchase", name, client.getAccountId(), amount); } - }, playerUUID.toString(), "Treasure", "Treasure Key", amount); - } - else - { - _donationManager.PurchaseUnknownSalesPackage(new Callback() - { - public void run(TransactionResponse data) + else if (args.length == 3 && args[0].equalsIgnoreCase("booster")) + { + int amount = Integer.parseInt(args[2]); + + _donationManager.PurchaseUnknownSalesPackage(null, name, client.getAccountId(), "Gem Booster " + amount, false, 0, false); + _repository.addGemBooster(name, amount); + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Gem Boosters" + "."); + } + else if (args.length >= 3 && args[0].equalsIgnoreCase("key")) { - if (data == TransactionResponse.Success) + final int amount = Integer.parseInt(args[2]); + + if (args.length == 4) { _inventoryManager.addItemToInventoryForOffline(new Callback() { @@ -257,149 +248,175 @@ public class Enjin extends MiniPlugin implements CommandExecutor System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); } } - }, playerUUID.toString(), "Treasure", "Treasure Key", amount); + }, playerUUID, "Treasure", "Treasure Key", amount); } else { - _commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); + _donationManager.PurchaseUnknownSalesPackage(new Callback() + { + public void run(TransactionResponse data) + { + if (data == TransactionResponse.Success) + { + _inventoryManager.addItemToInventoryForOffline(new Callback() + { + public void run(Boolean success) + { + if (success) + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Keys" + "."); + else + { + // Add arg so we don't add back to windows api call + _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); + } + } + }, playerUUID, "Treasure", "Treasure Key", amount); + } + else + { + _commandQueue.add(new QueuedCommand(sender, command, label, args)); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); + } + } + }, name, client.getAccountId(), "Treasure Key " + amount, false, 0, false); } } - }, name, playerUUID, "Treasure Key " + amount, false, 0, false); - } - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("chest")) - { - final int amount = Integer.parseInt(args[2]); - - if (args.length == 4) - { - _inventoryManager.addItemToInventoryForOffline(new Callback() - { - public void run(Boolean success) - { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + "."); + else if (args.length >= 3 && args[0].equalsIgnoreCase("chest")) + { + final int amount = Integer.parseInt(args[2]); + + if (args.length == 4) + { + _inventoryManager.addItemToInventoryForOffline(new Callback() + { + public void run(Boolean success) + { + if (success) + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + "."); + else + { + // Add arg so we don't add back to windows api call + _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Chests. Queuing for run later."); + } + } + }, playerUUID, "Utility", "Treasure Chest", amount); + } else { - // Add arg so we don't add back to windows api call - _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Chests. Queuing for run later."); + _donationManager.PurchaseUnknownSalesPackage(new Callback() + { + public void run(TransactionResponse data) + { + _inventoryManager.addItemToInventoryForOffline(new Callback() + { + public void run(Boolean success) + { + if (success) + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + "."); + else + { + // Add arg so we don't add back to windows api call + _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Chests. Queuing for run later."); + } + } + }, playerUUID, "Utility", "Treasure Chest", amount); + } + }, name, client.getAccountId(), "Treasure Chest " + amount, false, 0, false); } } - }, playerUUID.toString(), "Utility", "Treasure Chest", amount); - } - else - { - _donationManager.PurchaseUnknownSalesPackage(new Callback() - { - public void run(TransactionResponse data) + else if (args.length == 4 && args[0].equalsIgnoreCase("rank")) { - _inventoryManager.addItemToInventoryForOffline(new Callback() + final Rank rank = mineplex.core.common.Rank.valueOf(args[2]); + final boolean perm = Boolean.parseBoolean(args[3]); + + _clientManager.loadClientByName(name, new Runnable() { - public void run(Boolean success) + public void run() { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + "."); + if (_clientManager.Get(name).GetRank() == Rank.ALL || !_clientManager.Get(name).GetRank().Has(rank) || _clientManager.Get(name).GetRank() == rank) + { + _clientManager.SaveRank(name, playerUUID, rank, perm); + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + rank + " " + (perm ? "permanently." : "for 1 month.")); + } else { - // Add arg so we don't add back to windows api call - _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Chests. Queuing for run later."); + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " DENIED INFERIOR " + rank + " " + (perm ? "permanently." : "for 1 month.")); } } - }, playerUUID.toString(), "Utility", "Treasure Chest", amount); + }); } - }, name, playerUUID, "Treasure Chest " + amount, false, 0, false); - } - } - else if (args.length == 4 && args[0].equalsIgnoreCase("rank")) - { - final Rank rank = mineplex.core.common.Rank.valueOf(args[2]); - final boolean perm = Boolean.parseBoolean(args[3]); - - _clientManager.loadClientByName(name, new Runnable() - { - public void run() - { - if (_clientManager.Get(name).GetRank() == Rank.ALL || !_clientManager.Get(name).GetRank().Has(rank) || _clientManager.Get(name).GetRank() == rank) + else if (args.length >= 3 && args[0].equalsIgnoreCase("purchase")) { - _clientManager.SaveRank(name, playerUUID, rank, perm); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + rank + " " + (perm ? "permanently." : "for 1 month.")); - } - else - { - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " DENIED INFERIOR " + rank + " " + (perm ? "permanently." : "for 1 month.")); - } - } - }); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("purchase")) - { - final int amount = Integer.parseInt(args[2]); - final String category = args[3]; - String tempName = args[4]; - - for (int i = 5; i < args.length; i++) - { - tempName += " " + args[i]; - } - - final String packageName = tempName; - - _donationManager.PurchaseUnknownSalesPackage(new Callback() - { - public void run(TransactionResponse data) - { - if (data == TransactionResponse.Success) - { - _inventoryManager.addItemToInventoryForOffline(new Callback() + final int amount = Integer.parseInt(args[2]); + final String category = args[3]; + String tempName = args[4]; + + for (int i = 5; i < args.length; i++) { - public void run(Boolean success) + tempName += " " + args[i]; + } + + final String packageName = tempName; + + _donationManager.PurchaseUnknownSalesPackage(new Callback() + { + public void run(TransactionResponse data) { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " " + packageName + "."); + if (data == TransactionResponse.Success) + { + _inventoryManager.addItemToInventoryForOffline(new Callback() + { + public void run(Boolean success) + { + if (success) + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " " + packageName + "."); + else + { + // Add arg so we don't add back to windows api call + _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + packageName + ". Queuing for run later."); + } + } + }, playerUUID, category, packageName, amount); + } else { - // Add arg so we don't add back to windows api call - _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + packageName + ". Queuing for run later."); + _commandQueue.add(new QueuedCommand(sender, command, label, args)); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); } } - }, playerUUID.toString(), category, packageName, amount); + }, name, client.getAccountId(), packageName, false, 0, false); } - else - { - _commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); + else if (args.length >= 3 && args[0].equalsIgnoreCase("unban")) + { + String reason = args[2]; + + for (int i = 3; i < args.length; i++) + { + reason += " " + args[i]; + } + + _punish.RemoveBan(name, reason); + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " unbanned for " + reason); + } + else if (args.length >= 3 && args[0].equalsIgnoreCase("ban")) + { + String reason = args[2]; + + for (int i = 3; i < args.length; i++) + { + reason += " " + args[i]; + } + + _punish.AddPunishment(name, Category.Other, reason, null, 3, true, -1); + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " banned for " + reason); } } - }, name, playerUUID, packageName, false, 0, false); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("unban")) - { - String reason = args[2]; - - for (int i = 3; i < args.length; i++) - { - reason += " " + args[i]; } - - _punish.RemoveBan(name, reason); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " unbanned for " + reason); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("ban")) - { - String reason = args[2]; - - for (int i = 3; i < args.length; i++) - { - reason += " " + args[i]; - } - - _punish.AddPunishment(name, Category.Other, reason, null, 3, true, -1); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " banned for " + reason); - } + }); } } catch (Exception exception)