Inheritance: System.EventArgs
示例#1
0
		/// <summary>
		/// Occurs when someone executes an alias command
		/// </summary>
		internal void ChatCommand_AliasExecuted(TShockAPI.CommandArgs e)
		{
			string commandIdentifier = e.Message;

			if (!string.IsNullOrEmpty(e.Message)) {
				commandIdentifier = e.Message.Split(' ').FirstOrDefault();
			}

			if (AliasExecuted != null) {
				AliasExecutedEventArgs args = new AliasExecutedEventArgs() {
					CommandIdentifier = commandIdentifier,
					CommandArgs = e
				};

				AliasExecuted(this, args);
			}
		}
示例#2
0
        /// <summary>
        /// Occurs when someone executes an alias command
        /// </summary>
        protected void ChatCommand_AliasExecuted(TShockAPI.CommandArgs e)
        {
            string commandIdentifier = e.Message;

            if (!string.IsNullOrEmpty(e.Message))
            {
                commandIdentifier = e.Message.Split(' ').FirstOrDefault();
            }

            if (AliasExecuted != null)
            {
                AliasExecutedEventArgs args = new AliasExecutedEventArgs()
                {
                    CommandIdentifier = commandIdentifier,
                    CommandArgs       = e
                };

                AliasExecuted(null, args);
            }
        }
示例#3
0
		internal async void JistAlias_AliasExecuted(object sender, AliasExecutedEventArgs e)
		{
			//Get the corresponding alias in the config that matches what the user typed.
			foreach (JScriptAliasCommand alias in jsAliases.Where(i => i.CommandAlias == e.CommandIdentifier)) {
				DateTime canRunNext = DateTime.MinValue;
				Money commandCost = 0;
				IBankAccount account;

				if (alias == null) {
					continue;
				}

				//cooldown key is a pair of the user's character name, and the command they have called.
				KeyValuePair<string, AliasCommand> cooldownReference = new KeyValuePair<string, AliasCommand>(e.CommandArgs.Player.User.Name, alias);
				if (CooldownList.ContainsKey(cooldownReference)) {
					//UTC time so we don't get any daylight saving shit cuntery
					canRunNext = CooldownList[cooldownReference];
				}

				//has the time elapsed greater than the cooldown period?
				if (DateTime.UtcNow <= canRunNext
				    && e.CommandArgs.Player.Group.HasPermission("aliascmd.bypasscooldown") == false) {
					e.CommandArgs.Player.SendErrorMessage("{0}: You need to wait {1:0} more seconds to be able to use that.",
						alias.CommandAlias,
						canRunNext.Subtract(DateTime.UtcNow).TotalSeconds);
					return;
				}

				if (string.IsNullOrEmpty(alias.Cost) == true
				    || e.CommandArgs.Player.Group.HasPermission("aliascmd.bypasscost") == true
				    || Money.TryParse(alias.Cost, out commandCost) == false
				    || commandCost == 0) {

					if (Jist.JistPlugin.Instance == null) {
						return;
					}

					try {
						/*
                         * Populate cooldown list first before the function's
                         * called, because the function might override it to
                         * something else.
                         */
						PopulateCooldownList(cooldownReference);
						Jist.JistPlugin.Instance.CallFunction(alias.func, alias, e.CommandArgs.Player, e.CommandArgs.Parameters);
						return;
					} catch {
						/*
                         * Command failed.
                         */
					}
				}

				/*
                 * SEconomy may be null.
                 * If this is the case and the command is
                 * not free, bail out.
                 */
				if (SEconomyPlugin.Instance == null) {
					return;
				}

                
				if ((account = SEconomyPlugin.Instance.GetBankAccount(e.CommandArgs.Player)) == null) {
					e.CommandArgs.Player.SendErrorMessage("This command costs money and you don't have a bank account.  Please log in first.");
					return;
				}

				if (account.IsAccountEnabled == false) {
					e.CommandArgs.Player.SendErrorMessage("This command costs money and your account is disabled.");
					return;
				}

				if (account.Balance < commandCost) {
					Money difference = commandCost - account.Balance;
					e.CommandArgs.Player.SendErrorMessage("This command costs {0}. You need {1} more to be able to use this.",
						commandCost.ToLongString(),
						difference.ToLongString());
				}

				try {
					/*
                     * Take money off the player, and indicate 
                     * that this is a payment for something 
                     * tangible.
                     */
					Journal.BankTransferEventArgs trans = await account.TransferToAsync(SEconomyPlugin.Instance.WorldAccount,
						                                      commandCost,
						                                      Journal.BankAccountTransferOptions.AnnounceToSender | Journal.BankAccountTransferOptions.IsPayment,
						                                      "",
						                                      string.Format("AC: {0} cmd {1}", e.CommandArgs.Player.Name, alias.CommandAlias));

					if (trans.TransferSucceeded == false) {
						e.CommandArgs.Player.SendErrorMessage("Your payment failed.");
						return;
					}

					if (Jist.JistPlugin.Instance == null) {
						return;
					}

					try {
						/*
                         * Populate cooldown list first before the function's
                         * called, because the function might override it to
                         * something else.
                         */
						PopulateCooldownList(cooldownReference);
						Jist.JistPlugin.Instance.CallFunction(alias.func, alias, e.CommandArgs.Player.Name, e.CommandArgs.Parameters);
					} catch (Exception) {
						/*
                         * Command failed but the person paid money for it.
                         * Refund the full cost of the command if an
                         * exception happens.
                         */
						Jist.ScriptLog.ErrorFormat("alias",
							"{0} paid {1} for alias {2} but it failed and was refunded.",
							e.CommandArgs.Player.Name,
							commandCost.ToString(),
							alias.CommandAlias);
						RefundAlias(commandCost, e.CommandArgs.Player);
					}
				} catch (Exception ex) {
					e.CommandArgs.Player.SendErrorMessage("An error occured in the alias.");
					TShock.Log.ConsoleError("aliascmd error: {0} tried to execute alias {1} which failed with error {2}: {3}",
						e.CommandArgs.Player.Name,
						e.CommandIdentifier,
						ex.Message,
						ex.ToString());
					return;
				}
			}
		}
示例#4
0
		protected void CmdAliasPlugin_AliasExecuted(object sender, AliasExecutedEventArgs e)
		{
			//Get the corresponding alias in the config that matches what the user typed.
			foreach (AliasCommand alias in Configuration.CommandAliases.Where(i => i.CommandAlias == e.CommandIdentifier)) {
				DateTime canRunNext = DateTime.MinValue;
				Money commandCost = 0;
				IBankAccount playerAccount;

				if (alias == null || SEconomyPlugin.Instance == null) {
					continue;
				}

				//cooldown key is a pair of the user's character name, and the command they have called.
				KeyValuePair<string, AliasCommand> cooldownReference = new KeyValuePair<string, AliasCommand>(e.CommandArgs.Player.UserAccountName, alias);
				if (CooldownList.ContainsKey(cooldownReference)) {
					//UTC time so we don't get any daylight saving shit cuntery
					canRunNext = CooldownList[cooldownReference];
				}

				//has the time elapsed greater than the cooldown period?
				if (DateTime.UtcNow <= canRunNext
				    && e.CommandArgs.Player.Group.HasPermission("aliascmd.bypasscooldown") == false) {
					e.CommandArgs.Player.SendErrorMessage("{0}: You need to wait {1:0} more seconds to be able to use that.",
						alias.CommandAlias,
						canRunNext.Subtract(DateTime.UtcNow).TotalSeconds);
					return;
				}

				if (string.IsNullOrEmpty(alias.Cost) == true
				    || e.CommandArgs.Player.Group.HasPermission("aliascmd.bypasscost") == true
				    || Money.TryParse(alias.Cost, out commandCost) == false
				    || commandCost == 0) {

					DoCommands(alias, e.CommandArgs.Player, e.CommandArgs.Parameters);
					PopulateCooldownList(cooldownReference);
					return;
				}

                
				if ((playerAccount = SEconomyPlugin.Instance.GetBankAccount(e.CommandArgs.Player)) == null) {
					e.CommandArgs.Player.SendErrorMessage("This command costs money and you don't have a bank account.  Please log in first.");
					return;
				}

				if (playerAccount.IsAccountEnabled == false) {
					e.CommandArgs.Player.SendErrorMessage("This command costs money and your account is disabled.");
					return;
				}

				if (playerAccount.Balance < commandCost) {
					Money difference = commandCost - playerAccount.Balance;
					e.CommandArgs.Player.SendErrorMessage("This command costs {0}. You need {1} more to be able to use this.", commandCost.ToLongString(), difference.ToLongString());
				}

				try {
					//Take money off the player, and indicate that this is a payment for something tangible.
					Journal.BankTransferEventArgs trans = playerAccount.TransferTo(SEconomyPlugin.Instance.WorldAccount, commandCost, Journal.BankAccountTransferOptions.AnnounceToSender | Journal.BankAccountTransferOptions.IsPayment, 
						                                      "", 
						                                      string.Format("AC: {0} cmd {1}", e.CommandArgs.Player.Name, alias.CommandAlias));
					if (trans.TransferSucceeded) {
						DoCommands(alias, e.CommandArgs.Player, e.CommandArgs.Parameters);
						PopulateCooldownList(cooldownReference);
						return;
					}

					e.CommandArgs.Player.SendErrorMessage("Your payment failed.");
				} catch (Exception ex) {
					e.CommandArgs.Player.SendErrorMessage("An error occured in the alias.");
					TShock.Log.ConsoleError("aliascmd error: {0} tried to execute alias {1} which failed with error {2}: {3}", e.CommandArgs.Player.Name, e.CommandIdentifier, ex.Message, ex.ToString());
					return;
				}
			}
		}
示例#5
0
        protected void CmdAliasPlugin_AliasExecuted(object sender, AliasExecutedEventArgs e)
        {
            //Get the corresponding alias in the config that matches what the user typed.
            foreach (AliasCommand alias in Configuration.CommandAliases.Where(i => i.CommandAlias == e.CommandIdentifier))
            {
                DateTime     canRunNext  = DateTime.MinValue;
                Money        commandCost = 0;
                IBankAccount playerAccount;

                if (alias == null || SEconomyPlugin.Instance == null)
                {
                    continue;
                }

                //cooldown key is a pair of the user's character name, and the command they have called.
                KeyValuePair <string, AliasCommand> cooldownReference = new KeyValuePair <string, AliasCommand>(e.CommandArgs.Player.Name, alias);
                if (CooldownList.ContainsKey(cooldownReference))
                {
                    //UTC time so we don't get any daylight saving shit cuntery
                    canRunNext = CooldownList[cooldownReference];
                }

                //has the time elapsed greater than the cooldown period?
                if (DateTime.UtcNow <= canRunNext &&
                    e.CommandArgs.Player.Group.HasPermission("aliascmd.bypasscooldown") == false)
                {
                    e.CommandArgs.Player.SendErrorMessage("{0}: You need to wait {1:0} more seconds to be able to use that.",
                                                          alias.CommandAlias,
                                                          canRunNext.Subtract(DateTime.UtcNow).TotalSeconds);
                    return;
                }

                if (string.IsNullOrEmpty(alias.Cost) == true ||
                    e.CommandArgs.Player.Group.HasPermission("aliascmd.bypasscost") == true ||
                    Money.TryParse(alias.Cost, out commandCost) == false ||
                    commandCost == 0)
                {
                    DoCommands(alias, e.CommandArgs.Player, e.CommandArgs.Parameters);
                    PopulateCooldownList(cooldownReference);
                    return;
                }


                if ((playerAccount = SEconomyPlugin.Instance.GetBankAccount(e.CommandArgs.Player)) == null)
                {
                    e.CommandArgs.Player.SendErrorMessage("This command costs money and you don't have a bank account. Please log in first.");
                    return;
                }

                if (playerAccount.IsAccountEnabled == false)
                {
                    e.CommandArgs.Player.SendErrorMessage("This command costs money but your bank account is disabled.");
                    return;
                }

                if (playerAccount.Balance < commandCost)
                {
                    Money difference = commandCost - playerAccount.Balance;
                    e.CommandArgs.Player.SendErrorMessage("This command costs {0}. You need {1} more to be able to use this.", commandCost.ToString(), difference.ToString());
                }

                try {
                    //Take money off the player, and indicate that this is a payment for something tangible.
                    Journal.BankTransferEventArgs trans = playerAccount.TransferTo(SEconomyPlugin.Instance.WorldAccount, commandCost, Journal.BankAccountTransferOptions.AnnounceToSender | Journal.BankAccountTransferOptions.IsPayment,
                                                                                   "",
                                                                                   string.Format("AC: {0} cmd {1}", e.CommandArgs.Player.Name, alias.CommandAlias));
                    if (trans.TransferSucceeded)
                    {
                        DoCommands(alias, e.CommandArgs.Player, e.CommandArgs.Parameters);
                        PopulateCooldownList(cooldownReference);
                        return;
                    }

                    e.CommandArgs.Player.SendErrorMessage("Your payment failed.");
                } catch (Exception ex) {
                    e.CommandArgs.Player.SendErrorMessage("An error occured in the alias.");
                    TShock.Log.ConsoleError("aliascmd error: {0} tried to execute alias {1} which failed with error {2}: {3}", e.CommandArgs.Player.Name, e.CommandIdentifier, ex.Message, ex.ToString());
                    return;
                }
            }
        }