Added Key/Chest support for EnjinListener

This commit is contained in:
Jonathan Williams 2014-12-01 02:03:46 -08:00
parent 9d39cb922c
commit 3584c0d8af
2 changed files with 64 additions and 8 deletions

View File

@ -20,11 +20,14 @@ import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager;
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;
@ -32,6 +35,7 @@ public class Enjin extends MiniPlugin implements CommandExecutor
{
private CoreClientManager _clientManager;
private DonationManager _donationManager;
private InventoryManager _inventoryManager;
private Punish _punish;
private TempRepository _repository;
@ -44,12 +48,13 @@ public class Enjin extends MiniPlugin implements CommandExecutor
private SimpleDateFormat _dateFormat = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
public Enjin(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Punish punish)
public Enjin(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, Punish punish)
{
super("Enjin", plugin);
_clientManager = clientManager;
_donationManager = donationManager;
_inventoryManager = inventoryManager;
_punish = punish;
_repository = new TempRepository(plugin);
@ -140,25 +145,27 @@ public class Enjin extends MiniPlugin implements CommandExecutor
if (label.equalsIgnoreCase("enjin_mineplex"))
{
final String name = args[1];
UUID playerUUID = null;
UUID uuid = null;
if (_cachedUUIDs.containsKey(name))
playerUUID = _cachedUUIDs.get(name).getKey();
uuid = _cachedUUIDs.get(name).getKey();
else
{
// Fails if not in DB and if duplicate.
playerUUID = _clientManager.loadUUIDFromDB(name);
uuid = _clientManager.loadUUIDFromDB(name);
if (playerUUID == null)
playerUUID = UUIDFetcher.getUUIDOf(name);
if (uuid == null)
uuid = UUIDFetcher.getUUIDOf(name);
}
if (playerUUID == null)
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<UUID, Long>(playerUUID, System.currentTimeMillis() + 240000));
if (args.length == 3 && args[0].equalsIgnoreCase("gem"))
@ -209,6 +216,54 @@ public class Enjin extends MiniPlugin implements CommandExecutor
_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]);
_donationManager.PurchaseUnknownSalesPackage(new Callback<TransactionResponse>()
{
public void run(TransactionResponse data)
{
_inventoryManager.addItemToInventoryForOffline(new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Keys" + ".");
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.");
}
}
}, playerUUID.toString(), "Treasure", "Treasure Key", amount);
}
}, name, playerUUID, "Treasure Key" + amount, false, 0, false);
}
else if (args.length == 3 && args[0].equalsIgnoreCase("chest"))
{
final int amount = Integer.parseInt(args[2]);
_donationManager.PurchaseUnknownSalesPackage(new Callback<TransactionResponse>()
{
public void run(TransactionResponse data)
{
_inventoryManager.addItemToInventoryForOffline(new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + ".");
else
{
_commandQueue.add(new QueuedCommand(sender, command, label, args));
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Chests. Queuing for run later.");
}
}
}, playerUUID.toString(), "Utility", "Treasure Chest", amount);
}
}, name, playerUUID, "Treasure Chest" + amount, false, 0, false);
}
else if (args.length == 4 && args[0].equalsIgnoreCase("rank"))
{
final String rank = args[2];

View File

@ -3,6 +3,7 @@ package mineplex.enjinTranslator;
import mineplex.core.account.CoreClientManager;
import mineplex.core.command.CommandCenter;
import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.punish.Punish;
import mineplex.core.updater.Updater;
@ -31,7 +32,7 @@ public class EnjinTranslator extends JavaPlugin
Punish punish = new Punish(this, GetWebServerAddress(), clientManager);
//Main Modules
new Enjin(this, clientManager, donationManager, punish);
new Enjin(this, clientManager, donationManager, new InventoryManager(this, clientManager), punish);
new Updater(this);
}