Updated EnjinTranslator to new backend processing.

This commit is contained in:
Jonathan Williams 2015-03-25 15:00:27 -07:00
parent 4b81f6cd8b
commit a8eaf1014f
2 changed files with 222 additions and 202 deletions

View File

@ -18,6 +18,9 @@
<fileset dir="../Mineplex.EnjinTranslator">
<include name="*.yml"/>
</fileset>
<fileset dir="../Mineplex.ServerData/bin">
<include name="**/*.class"/>
</fileset>
<zipfileset src="../Libraries/jooq-3.5.2.jar" />
<zipfileset src="../Libraries/httpclient-4.2.jar" />

View File

@ -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<UUID, Long>(playerUUID, System.currentTimeMillis() + 240000));
if (args.length == 3 && args[0].equalsIgnoreCase("gem"))
{
final int amount = Integer.parseInt(args[2]);
_donationManager.RewardGems(new Callback<Boolean>()
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.");
}
}
}, "purchase", name, playerUUID, amount);
}
else if (args.length == 3 && args[0].equalsIgnoreCase("coin"))
{
final int amount = Integer.parseInt(args[2]);
// Fails if not in DB and if duplicate.
uuid = _clientManager.loadUUIDFromDB(name);
_donationManager.RewardCoins(new Callback<Boolean>()
{
public void run (Boolean response)
{
if (response)
{
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " coins.");
if (uuid == null)
uuid = UUIDFetcher.getUUIDOf(name);
}
else
if (uuid == null)
{
_commandQueue.add(new QueuedCommand(sender, command, label, args));
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " coins. Queuing for run later.");
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + ", no UUID.");
return;
}
}
}, "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]);
final UUID playerUUID = uuid;
if (args.length == 4)
{
_inventoryManager.addItemToInventoryForOffline(new Callback<Boolean>()
{
public void run(Boolean success)
_cachedUUIDs.put(name, new AbstractMap.SimpleEntry<UUID, Long>(playerUUID, System.currentTimeMillis() + 240000));
if (args.length == 3 && args[0].equalsIgnoreCase("gem"))
{
if (success)
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Keys" + ".");
else
final int amount = Integer.parseInt(args[2]);
_donationManager.RewardGems(new Callback<Boolean>()
{
// 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);
}
}, playerUUID.toString(), "Treasure", "Treasure Key", amount);
}
else
{
_donationManager.PurchaseUnknownSalesPackage(new Callback<TransactionResponse>()
{
public void run(TransactionResponse data)
else if (args.length == 3 && args[0].equalsIgnoreCase("coin"))
{
if (data == TransactionResponse.Success)
final int amount = Integer.parseInt(args[2]);
_donationManager.RewardCoins(new Callback<Boolean>()
{
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);
}
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"))
{
final int amount = Integer.parseInt(args[2]);
if (args.length == 4)
{
_inventoryManager.addItemToInventoryForOffline(new Callback<Boolean>()
{
@ -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<TransactionResponse>()
{
public void run(TransactionResponse data)
{
if (data == TransactionResponse.Success)
{
_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
{
// 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<Boolean>()
{
public void run(Boolean success)
else if (args.length >= 3 && args[0].equalsIgnoreCase("chest"))
{
if (success)
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + ".");
final int amount = Integer.parseInt(args[2]);
if (args.length == 4)
{
_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
{
// 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<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
{
// 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<TransactionResponse>()
{
public void run(TransactionResponse data)
else if (args.length == 4 && args[0].equalsIgnoreCase("rank"))
{
_inventoryManager.addItemToInventoryForOffline(new Callback<Boolean>()
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];
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<TransactionResponse>()
{
public void run(TransactionResponse data)
{
if (data == TransactionResponse.Success)
{
_inventoryManager.addItemToInventoryForOffline(new Callback<Boolean>()
for (int i = 5; i < args.length; i++)
{
public void run(Boolean success)
tempName += " " + args[i];
}
final String packageName = tempName;
_donationManager.PurchaseUnknownSalesPackage(new Callback<TransactionResponse>()
{
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<Boolean>()
{
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
else if (args.length >= 3 && args[0].equalsIgnoreCase("unban"))
{
_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.");
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)