Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
2eaa326929
@ -11,6 +11,9 @@
|
||||
<fileset dir="../Mineplex.Database/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.PlayerCache/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
|
||||
<fileset dir="../Mineplex.EnjinTranslator/bin">
|
||||
<include name="**/*.class"/>
|
||||
|
@ -81,7 +81,7 @@ public class LobbyBalancer implements Listener, Runnable
|
||||
InetSocketAddress socketAddress = new InetSocketAddress(server.getPublicAddress(), server.getPort());
|
||||
_plugin.getProxy().getServers().put(server.getName(), _plugin.getProxy().constructServerInfo(server.getName(), socketAddress, "LobbyBalancer", false));
|
||||
|
||||
if (server.getName().toUpperCase().contains("LOBBY"))
|
||||
if (server.getName().toUpperCase().startsWith("LOBBY"))
|
||||
{
|
||||
if (server.getMotd() == null || !server.getMotd().contains("Restarting"))
|
||||
{
|
||||
|
@ -426,6 +426,25 @@ public class CoreClientManager extends MiniPlugin
|
||||
}, name, uuid, rank, perm);
|
||||
}
|
||||
|
||||
public void SaveRank(final Callback<Rank> callback, final String name, final UUID uuid, Rank rank, boolean perm)
|
||||
{
|
||||
_repository.saveRank(new Callback<Rank>()
|
||||
{
|
||||
public void run(Rank newRank)
|
||||
{
|
||||
if (_plugin.getServer().getPlayer(name) != null)
|
||||
{
|
||||
CoreClient client = Get(name);
|
||||
|
||||
client.SetRank(newRank, false);
|
||||
}
|
||||
|
||||
if (callback != null)
|
||||
callback.run(newRank);
|
||||
}
|
||||
}, name, uuid, rank, perm);
|
||||
}
|
||||
|
||||
public void checkPlayerNameExact(final Callback<Boolean> callback, final String playerName)
|
||||
{
|
||||
_repository.matchPlayerName(new Callback<List<String>>()
|
||||
|
@ -121,6 +121,17 @@ public class InventoryManager extends MiniDbClientPlugin<ClientInventory>
|
||||
}
|
||||
|
||||
public void addItemToInventoryForOffline(final Callback<Boolean> callback, final UUID uuid, final String item, final int count)
|
||||
{
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
addItemToInventoryForOffline(callback, PlayerCache.getInstance().getPlayer(uuid).getAccountId(), item, count);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addItemToInventoryForOffline(final Callback<Boolean> callback, final int accountId, final String item, final int count)
|
||||
{
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
@ -139,7 +150,7 @@ public class InventoryManager extends MiniDbClientPlugin<ClientInventory>
|
||||
|
||||
synchronized (_inventoryLock)
|
||||
{
|
||||
final boolean success = _repository.incrementClientInventoryItem(PlayerCache.getInstance().getPlayer(uuid).getAccountId(), _items.get(item).Id, count);
|
||||
final boolean success = _repository.incrementClientInventoryItem(accountId, _items.get(item).Id, count);
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
|
@ -2,10 +2,8 @@ package mineplex.enjinTranslator;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -25,30 +23,27 @@ 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;
|
||||
import mineplex.enjinTranslator.purchase.PurchaseManager;
|
||||
|
||||
public class Enjin extends MiniPlugin implements CommandExecutor
|
||||
{
|
||||
private CoreClientManager _clientManager;
|
||||
private DonationManager _donationManager;
|
||||
private InventoryManager _inventoryManager;
|
||||
private Punish _punish;
|
||||
|
||||
private TempRepository _repository;
|
||||
private PurchaseManager _purchaseManager;
|
||||
|
||||
private NautHashMap<String, Entry<UUID, Long>> _cachedUUIDs = new NautHashMap<String, Entry<UUID, Long>>();
|
||||
private List<QueuedCommand> _commandQueue = new ArrayList<QueuedCommand>();
|
||||
private static Object _commandLock = new Object();
|
||||
|
||||
public long _lastPoll = System.currentTimeMillis() - 120000;
|
||||
|
||||
private SimpleDateFormat _dateFormat = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
|
||||
|
||||
public Enjin(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, Punish punish)
|
||||
public Enjin(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager)
|
||||
{
|
||||
super("Enjin", plugin);
|
||||
|
||||
@ -56,8 +51,7 @@ public class Enjin extends MiniPlugin implements CommandExecutor
|
||||
_donationManager = donationManager;
|
||||
_inventoryManager = inventoryManager;
|
||||
|
||||
_punish = punish;
|
||||
_repository = new TempRepository(plugin);
|
||||
_purchaseManager = new PurchaseManager(plugin);
|
||||
|
||||
plugin.getCommand("enjin_mineplex").setExecutor(this);
|
||||
plugin.getCommand("pull").setExecutor(this);
|
||||
@ -77,60 +71,6 @@ public class Enjin extends MiniPlugin implements CommandExecutor
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void processCommandQueue(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.MIN_01 || _commandQueue.size() == 0)
|
||||
return;
|
||||
|
||||
List<QueuedCommand> commandCopyQueue = new ArrayList<QueuedCommand>();
|
||||
|
||||
synchronized (_commandLock)
|
||||
{
|
||||
for (QueuedCommand command : _commandQueue)
|
||||
commandCopyQueue.add(command);
|
||||
|
||||
_commandQueue.clear();
|
||||
}
|
||||
|
||||
System.out.println("=====] Processing queued commands [=====");
|
||||
for (QueuedCommand command : commandCopyQueue)
|
||||
{
|
||||
try
|
||||
{
|
||||
onCommand(command.Sender, command.Command, command.Label, command.Args);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println("========================================");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void pollLastPurchases(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.MIN_01)
|
||||
return;
|
||||
|
||||
/*
|
||||
@SuppressWarnings("serial")
|
||||
List<EnjinPurchase> purchases = new JsonWebCall("http://www.mineplex.com/api/m-shopping-purchases/m/14702725").Execute(new TypeToken<List<EnjinPurchase>>(){}.getType(), null);
|
||||
_lastPoll = System.currentTimeMillis();
|
||||
|
||||
int i = 0;
|
||||
for (EnjinPurchase purchase : purchases)
|
||||
{
|
||||
if (i > 10)
|
||||
break;
|
||||
|
||||
purchase.logInfoToConsole();
|
||||
i++;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args)
|
||||
@ -180,240 +120,20 @@ public class Enjin extends MiniPlugin implements CommandExecutor
|
||||
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 (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<Boolean>()
|
||||
{
|
||||
public void run (Boolean response)
|
||||
if (!checkForCoinPurchase(args, name, playerUUID, client))
|
||||
if (!checkForRankPurchase(args, name, playerUUID, client))
|
||||
if(!checkForPurchase(args, name, client))
|
||||
{
|
||||
if (response)
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (String arg : args)
|
||||
{
|
||||
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.");
|
||||
sb.append(arg + " ");
|
||||
}
|
||||
|
||||
System.out.println("Received Command : " + sb.toString());
|
||||
}
|
||||
}, "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>()
|
||||
{
|
||||
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
|
||||
{
|
||||
_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);
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
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
|
||||
{
|
||||
_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);
|
||||
}
|
||||
}
|
||||
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 (rank == Rank.ALL || _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
|
||||
{
|
||||
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<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 + " " + 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
|
||||
{
|
||||
//_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(), 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -436,4 +156,111 @@ public class Enjin extends MiniPlugin implements CommandExecutor
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean checkForRankPurchase(String[] args, final String name, final UUID playerUUID, final CoreClient client)
|
||||
{
|
||||
if (args.length != 4 || !args[0].equalsIgnoreCase("rank"))
|
||||
return false;;
|
||||
|
||||
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 (rank == Rank.ALL || _clientManager.Get(name).GetRank() == Rank.ALL || !_clientManager.Get(name).GetRank().has(rank) || _clientManager.Get(name).GetRank() == rank)
|
||||
{
|
||||
_clientManager.SaveRank(new Callback<Rank>()
|
||||
{
|
||||
public void run(Rank data)
|
||||
{
|
||||
_purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), rank.Name + (perm ? " Permanent" : " Monthly"), 1, data == rank);
|
||||
}
|
||||
}, 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."));
|
||||
_purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), rank.Name + (perm ? " Permanent" : " Monthly"), 1, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean checkForPurchase(String[] args, final String name, final CoreClient client)
|
||||
{
|
||||
if (args.length < 3 || !args[0].equalsIgnoreCase("purchase"))
|
||||
return false;
|
||||
|
||||
final int amount = Integer.parseInt(args[2]);
|
||||
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>()
|
||||
{
|
||||
public void run(Boolean success)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
_purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), packageName, amount, true);
|
||||
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " " + packageName + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + packageName + ". Queuing for run later.");
|
||||
_purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), packageName, amount, false);
|
||||
}
|
||||
}
|
||||
}, client.getAccountId(), packageName, amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + ". Queuing for run later.");
|
||||
_purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), packageName, amount, data == TransactionResponse.Success);
|
||||
}
|
||||
}
|
||||
}, name, client.getAccountId(), amount == 1 ? packageName : packageName + " " + amount, false, 0, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean checkForCoinPurchase(String[] args, final String name, final UUID playerUUID, final CoreClient client)
|
||||
{
|
||||
if (args.length != 3 || !args[0].equalsIgnoreCase("coin"))
|
||||
return false;
|
||||
|
||||
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
|
||||
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " coins. Queuing for run later.");
|
||||
|
||||
_purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), "Coins", amount, response);
|
||||
}
|
||||
}, "purchase", name, client.getAccountId(), amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -28,11 +28,9 @@ public class EnjinTranslator extends JavaPlugin
|
||||
CommandCenter.Instance.setClientManager(clientManager);
|
||||
|
||||
DonationManager donationManager = new DonationManager(this, clientManager, GetWebServerAddress());
|
||||
//Other Modules
|
||||
Punish punish = new Punish(this, GetWebServerAddress(), clientManager);
|
||||
|
||||
//Main Modules
|
||||
new Enjin(this, clientManager, donationManager, new InventoryManager(this, clientManager), punish);
|
||||
new Enjin(this, clientManager, donationManager, new InventoryManager(this, clientManager));
|
||||
|
||||
new Updater(this);
|
||||
}
|
||||
|
@ -0,0 +1,75 @@
|
||||
package mineplex.enjinTranslator.purchase;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.database.ResultSetCallable;
|
||||
import mineplex.enjinTranslator.purchase.data.PurchaseRepository;
|
||||
import mineplex.enjinTranslator.purchase.data.Package;
|
||||
|
||||
public class PurchaseManager extends MiniPlugin
|
||||
{
|
||||
private static Object _purchaseLock = new Object();
|
||||
|
||||
private PurchaseRepository _repository;
|
||||
private NautHashMap<String, Package> _purchases = new NautHashMap<String, Package>();
|
||||
|
||||
public PurchaseManager(JavaPlugin plugin)
|
||||
{
|
||||
super("Purchase Manager", plugin);
|
||||
|
||||
_repository = new PurchaseRepository(plugin);
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
updatePackages();
|
||||
}
|
||||
}, 20L);
|
||||
}
|
||||
|
||||
private void updatePackages()
|
||||
{
|
||||
List<Package> packages = _repository.retrievePackages();
|
||||
|
||||
synchronized (_purchaseLock)
|
||||
{
|
||||
for (mineplex.enjinTranslator.purchase.data.Package purchasePackage : packages)
|
||||
{
|
||||
_purchases.put(purchasePackage.getName(), purchasePackage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addAccountPurchaseToQueue(int accountId, final String packageName, int count, boolean success)
|
||||
{
|
||||
synchronized (_purchaseLock)
|
||||
{
|
||||
if (!_purchases.containsKey(packageName))
|
||||
{
|
||||
_repository.addPackage(packageName, new ResultSetCallable()
|
||||
{
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
while (resultSet.next())
|
||||
{
|
||||
int packageId = resultSet.getInt(1);
|
||||
|
||||
_purchases.put(packageName, new Package(packageId, packageName));
|
||||
System.out.println("Added new package : " + packageName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_repository.addAccountPurchase(accountId, _purchases.get(packageName).getId(), count, success);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package mineplex.enjinTranslator.purchase.data;
|
||||
|
||||
public class Package
|
||||
{
|
||||
private int _id;
|
||||
private String _name;
|
||||
|
||||
public Package(int id, String name)
|
||||
{
|
||||
_id = id;
|
||||
_name = name;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package mineplex.enjinTranslator.purchase.data;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.ResultSetCallable;
|
||||
import mineplex.core.database.column.ColumnBoolean;
|
||||
import mineplex.core.database.column.ColumnInt;
|
||||
import mineplex.core.database.column.ColumnVarChar;
|
||||
|
||||
public class PurchaseRepository extends RepositoryBase
|
||||
{
|
||||
private static String INSERT_ACCOUNT_PURCHASE = "INSERT INTO accountPurchases (accountId, packageId, amount, date, success) VALUES (?, ?, ?, now(), ?);";
|
||||
|
||||
private static String INSERT_PACKAGE = "INSERT INTO packages (packageName) VALUES (?);";
|
||||
private static String RETRIEVE_PACKAGES = "SELECT id, packageName FROM packages;";
|
||||
|
||||
public PurchaseRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initialize() { }
|
||||
|
||||
@Override
|
||||
protected void update() { }
|
||||
|
||||
public void addPackage(String name, ResultSetCallable callable)
|
||||
{
|
||||
executeInsert(INSERT_PACKAGE, callable, new ColumnVarChar("packageName", 100, name));
|
||||
}
|
||||
|
||||
public List<Package> retrievePackages()
|
||||
{
|
||||
final List<Package> packages = new ArrayList<Package>();
|
||||
|
||||
executeQuery(RETRIEVE_PACKAGES, new ResultSetCallable()
|
||||
{
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
while (resultSet.next())
|
||||
{
|
||||
packages.add(new Package(resultSet.getInt(1), resultSet.getString(2)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return packages;
|
||||
}
|
||||
|
||||
public boolean addAccountPurchase(int accountId, int packageId, int count, boolean success)
|
||||
{
|
||||
return executeInsert(INSERT_ACCOUNT_PURCHASE, null, new ColumnInt("accountId", accountId), new ColumnInt("packageId", packageId), new ColumnInt("count", count), new ColumnBoolean("success", success)) > 0;
|
||||
}
|
||||
}
|
@ -94,7 +94,7 @@ public class TrickOrTreatManager extends MiniPlugin
|
||||
|
||||
_tricks.add(new Blindness(plugin));
|
||||
_tricks.add(new Nausea(plugin));
|
||||
_tricks.add(new RandomTeleport(plugin));
|
||||
//_tricks.add(new RandomTeleport(plugin));
|
||||
_tricks.add(new ShockingStrikes(plugin));
|
||||
}
|
||||
|
||||
|
@ -588,12 +588,10 @@ public class ServerManager extends MiniPlugin
|
||||
|
||||
if (largestServer.getAvailableSlots() >= MIN_SLOTS_REQUIRED || largestServer.MaxPlayers > 40)
|
||||
{
|
||||
System.out.println("Largest.");
|
||||
return largestServer;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Random.");
|
||||
return servers.get(random.nextInt(count));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user