Updated CoreClientManager to pull all account data via name request.

Cleaned up some code with pet administrator.

added logging if 0 rows were being saved in CommitChanges
This commit is contained in:
Jonathan Williams 2014-09-18 21:12:37 -10:00
parent c7e0ebefd1
commit 7906f48262
7 changed files with 509 additions and 438 deletions

View File

@ -168,9 +168,38 @@ public class CoreClientManager extends MiniPlugin
client.SetAccountId(token.AccountId); client.SetAccountId(token.AccountId);
client.SetRank(Rank.valueOf(token.Rank)); client.SetRank(Rank.valueOf(token.Rank));
final RetrieveClientInformationEvent clientInformationEvent = new RetrieveClientInformationEvent(client.GetPlayerName(), uuid);
clientInformationEvent.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
_mysqlRepository.login(uuid.toString(), client.GetPlayerName());
Bukkit.getServer().getPluginManager().callEvent(clientInformationEvent);
clientInformationEvent.decreaseProcessingCount();
}
});
// JSON sql response // JSON sql response
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response)); Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response));
// Load client in miniplugins
Bukkit.getServer().getPluginManager().callEvent(new AsyncClientLoadEvent(token, client));
while (clientInformationEvent.processing())
{
try
{
Thread.sleep(1);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
Bukkit.getServer().getScheduler().runTask(GetPlugin(), new Runnable() Bukkit.getServer().getScheduler().runTask(GetPlugin(), new Runnable()
{ {
public void run() public void run()

View File

@ -19,6 +19,7 @@ import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
@ -99,21 +100,49 @@ public class CustomerSupport extends MiniPlugin
caller.sendMessage(C.cDGreen + C.Strike + "============================================="); caller.sendMessage(C.cDGreen + C.Strike + "=============================================");
caller.sendMessage(C.cBlue + "Name : " + C.cYellow + playerName); caller.sendMessage(C.cBlue + "Name : " + C.cYellow + playerName);
caller.sendMessage(C.cBlue + "Rank : " + C.cYellow + (client.GetRank().Name.isEmpty() ? "Regular" : client.GetRank().Name)); caller.sendMessage(C.cBlue + "Rank : " + C.cYellow + (client.GetRank().Name.isEmpty() ? "Regular" : client.GetRank().Name));
caller.sendMessage(C.cBlue + "Transactions : "); caller.sendMessage(C.cBlue + "Coins : " + C.cYellow + donor.getCoins());
caller.sendMessage(C.cBlue + "Gems : " + C.cYellow + donor.GetGems());
int coinTransactionTotal = 0;
int enjinCoinsReceived = 0;
int coinSpentTotal = 0;
int enjinBoostersReceived = 0;
for (CoinTransactionToken transaction : donor.getCoinTransactions()) for (CoinTransactionToken transaction : donor.getCoinTransactions())
{ {
if (transaction.Source.equalsIgnoreCase("Poll") || transaction.Source.equalsIgnoreCase("Coin Party Bomb Pickup") || transaction.Source.contains("Reward")) if (transaction.Source.equalsIgnoreCase("Poll") || transaction.Source.equalsIgnoreCase("Coin Party Bomb Pickup") || transaction.Source.contains("Reward") || transaction.Source.contains("purchase"))
continue; {
coinTransactionTotal += transaction.Amount;
caller.sendMessage(C.cYellow + _date.format(transaction.Date) + C.cGray + " - " + C.cYellow + transaction.Amount + " Coins - Applied via " + transaction.Source); if (transaction.Source.contains("purchase"))
enjinCoinsReceived += transaction.Amount;
}
} }
for (TransactionToken transaction : donor.getTransactions()) for (TransactionToken transaction : donor.getTransactions())
{ {
if (transaction.Coins == 0 && transaction.Gems == 0 && transaction.SalesPackageName.contains("Gem Booster")) coinSpentTotal += transaction.Coins;
caller.sendMessage(C.cYellow + _date.format(transaction.Date) + C.cGray + " - " + C.cYellow + transaction.SalesPackageName);
if (transaction.SalesPackageName.contains("Gem Booster"))
{
if (transaction.SalesPackageName.startsWith("Gem Booster") && transaction.Coins == 0 && transaction.Gems == 0 && transaction.SalesPackageName.split(" ").length == 3)
enjinBoostersReceived += Integer.parseInt(transaction.SalesPackageName.split(" ")[2]);
}
} }
caller.sendMessage(C.cBlue + "Enjin Coin Total Received : " + C.cYellow + enjinCoinsReceived);
caller.sendMessage(C.cBlue + "Enjin Booster Total Received : " + C.cYellow + enjinBoostersReceived);
int coinsMissing = coinTransactionTotal - (donor.getCoins() + coinSpentTotal);
if (coinsMissing > 0)
{
caller.sendMessage(C.cRed + "Coins missing!");
new JsonMessage("[").color("blue").extra(C.cGreen + "Apply Missing Coins").color("green").click("run_command", "/sales coin " + playerName + " " + coinsMissing)
.add("] ").color("blue").add("Missing Coins.").color("yellow").sendToPlayer(caller);
}
caller.sendMessage(C.cDGreen + C.Strike + "============================================="); caller.sendMessage(C.cDGreen + C.Strike + "=============================================");
_salesPackageManager.displaySalesPackages(caller, playerName); _salesPackageManager.displaySalesPackages(caller, playerName);
caller.sendMessage(C.cDGreen + C.Strike + "============================================="); caller.sendMessage(C.cDGreen + C.Strike + "=============================================");

View File

@ -52,7 +52,14 @@
const string PREFIX = "CommitChanges() failed because: "; const string PREFIX = "CommitChanges() failed because: ";
try try
{ {
Context.SaveChanges(); if (Context.SaveChanges() == 0)
Log("WARNING", "No entities to save: " + Environment.StackTrace);
/*
* List<Object> modifiedOrAddedEntities = context.ChangeTracker.Entries()
.Where(x => x.State == System.Data.EntityState.Modified
|| x.State == System.Data.EntityState.Added)
.Select(x=>x.Entity).ToList();
* */
} }
catch (DbEntityValidationException ex) catch (DbEntityValidationException ex)
{ {

View File

@ -559,17 +559,12 @@
if (rank == null) if (rank == null)
return account.Rank.ToString(); return account.Rank.ToString();
repository.Attach(account);
repository.Edit(account);
var expire = DateTime.Now.AddMonths(1).AddMilliseconds(-DateTime.Now.Millisecond); var expire = DateTime.Now.AddMonths(1).AddMilliseconds(-DateTime.Now.Millisecond);
account.Rank = rank; account.Rank = rank;
account.RankExpire = expire; account.RankExpire = expire;
account.RankPerm = token.Perm; account.RankPerm = token.Perm;
repository.CommitChanges();
repository.Edit(account); repository.Edit(account);
if ((rank.Name == "HERO" || rank.Name == "ULTRA") && token.Perm) if ((rank.Name == "HERO" || rank.Name == "ULTRA") && token.Perm)

View File

@ -21,12 +21,15 @@
{ {
using (var repository = _repositoryFactory.CreateRepository()) using (var repository = _repositoryFactory.CreateRepository())
{ {
bool added = false;
foreach (var item in petTokens.Where(item => !repository.Any<Pet>(x => x.PetType == item.PetType))) foreach (var item in petTokens.Where(item => !repository.Any<Pet>(x => x.PetType == item.PetType)))
{ {
repository.Add(item); repository.Add(item);
added = true;
} }
repository.CommitChanges(); if (added)
repository.CommitChanges();
return repository.GetAll<Pet>().Include(x => x.SalesPackage).ToList(); return repository.GetAll<Pet>().Include(x => x.SalesPackage).ToList();
} }
@ -36,12 +39,15 @@
{ {
using (var repository = _repositoryFactory.CreateRepository()) using (var repository = _repositoryFactory.CreateRepository())
{ {
bool added = false;
foreach (var item in petExtraTokens.Where(item => !repository.Any<PetExtra>(x => x.Name == item.Name && x.Material == item.Material))) foreach (var item in petExtraTokens.Where(item => !repository.Any<PetExtra>(x => x.Name == item.Name && x.Material == item.Material)))
{ {
repository.Add(item); repository.Add(item);
added = true;
} }
repository.CommitChanges(); if (added)
repository.CommitChanges();
return repository.GetAll<PetExtra>().Include(x => x.SalesPackage).ToList(); return repository.GetAll<PetExtra>().Include(x => x.SalesPackage).ToList();
} }
@ -76,6 +82,8 @@
if (pet == null) if (pet == null)
return; return;
account.Pets.RemoveAll(x => x.PetType.Equals(token.PetType) && x.OwnedPetId != pet.OwnedPetId);
pet.PetName = token.PetName; pet.PetName = token.PetName;
repository.Edit(pet); repository.Edit(pet);

View File

@ -35,12 +35,15 @@
{ {
using (var repository = RepositoryFactory.CreateRepository()) using (var repository = RepositoryFactory.CreateRepository())
{ {
bool added = false;
foreach (var skill in skills.Where(skill => !repository.Any<Skill>(x => x.Name == skill.Name && x.Level == skill.Level))) foreach (var skill in skills.Where(skill => !repository.Any<Skill>(x => x.Name == skill.Name && x.Level == skill.Level)))
{ {
repository.Add(skill); repository.Add(skill);
added = true;
} }
repository.CommitChanges(); if (added)
repository.CommitChanges();
return repository.GetAll<Skill>().Include(x => x.SalesPackage).ToList(); return repository.GetAll<Skill>().Include(x => x.SalesPackage).ToList();
} }

File diff suppressed because it is too large Load Diff