public async void SEconomyTransferAsync(Journal.IBankAccount From, Journal.IBankAccount To, Money Amount, string TxMessage, JsValue completedCallback) { BankTransferEventArgs result = null; if (JistPlugin.Instance == null || SEconomyPlugin.Instance == null || From == null || To == null) { return; } result = await From.TransferToAsync(To, Amount, Journal.BankAccountTransferOptions.AnnounceToSender, TxMessage, TxMessage); if (result == null) { result = new BankTransferEventArgs() { TransferSucceeded = false }; } Jist.JistPlugin.Instance.CallFunction(completedCallback, null, result); }
/// <summary> /// Processes all elements in the queue and transfers them /// </summary> protected async Task ProcessQueueAsync() { List <CachedTransaction> aggregatedFunds = new List <CachedTransaction>(); CachedTransaction fund; while (CachedTransactions.TryDequeue(out fund)) { //The idea of this is that the concurrent queue will aggregate everything with the same message. //So instead of spamming eye of ctaltlatlatututlutultu (shut up) it'll just agg them into one //and print something like "You gained 60 silver from 20 eyes" instead of spamming both the chat log //and the journal with bullshit CachedTransaction existingFund = aggregatedFunds.FirstOrDefault(i => i.Message == fund.Message && i.SourceBankAccountK == fund.SourceBankAccountK && i.DestinationBankAccountK == fund.DestinationBankAccountK); if (existingFund != null) { existingFund.Amount += fund.Amount; //indicate that this is an aggregate of a previous uncommitted fund existingFund.Aggregations++; } else { aggregatedFunds.Add(fund); } } foreach (CachedTransaction aggregatedFund in aggregatedFunds) { Journal.IBankAccount sourceAccount = SEconomyPlugin.Instance.RunningJournal.GetBankAccount(aggregatedFund.SourceBankAccountK); Journal.IBankAccount destAccount = SEconomyPlugin.Instance.RunningJournal.GetBankAccount(aggregatedFund.DestinationBankAccountK); if (sourceAccount != null && destAccount != null) { StringBuilder messageBuilder = new StringBuilder(aggregatedFund.Message); if (aggregatedFund.Aggregations > 1) { messageBuilder.Insert(0, aggregatedFund.Aggregations + " "); messageBuilder.Append("s"); } //transfer the money BankTransferEventArgs transfer = await sourceAccount.TransferToAsync(destAccount, aggregatedFund.Amount, aggregatedFund.Options, messageBuilder.ToString(), messageBuilder.ToString()); if (!transfer.TransferSucceeded) { if (transfer.Exception != null) { TShock.Log.ConsoleError(string.Format("seconomy cache: error source={0} dest={1}: {2}", aggregatedFund.SourceBankAccountK, aggregatedFund.DestinationBankAccountK, transfer.Exception)); } } } else { TShock.Log.ConsoleError(string.Format("seconomy cache: transaction cache has no source or destination. source key={0} dest key={1}", aggregatedFund.SourceBankAccountK, aggregatedFund.DestinationBankAccountK)); } } }