Added a hook AccountHooks.AccountGroupUpdate.

This commit is contained in:
AkjaHAsLk1IALk0MasH 2023-05-14 12:08:11 +07:00
parent 22d8575e01
commit 8a0920b6ea

View file

@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using System.ComponentModel;
using TShockAPI.DB; using TShockAPI.DB;
namespace TShockAPI.Hooks namespace TShockAPI.Hooks
{ {
@ -39,6 +40,37 @@ namespace TShockAPI.Hooks
} }
} }
public abstract class AccountGroupUpdateEventArgs : HandledEventArgs
{
public string AccountName { get; private set; }
public Group Group { get; set; }
public AccountGroupUpdateEventArgs(string accountName, Group group)
{
this.AccountName = accountName;
this.Group = group;
}
}
public class AccountGroupUpdateByPluginEventArgs : AccountGroupUpdateEventArgs
{
public AccountGroupUpdateByPluginEventArgs(string accountName, Group group) : base(accountName, group)
{
}
}
public class AccountGroupUpdateByPlayerEventArgs : AccountGroupUpdateEventArgs
{
/// <summary>
/// The player who updated the user's group
/// </summary>
public TSPlayer Player { get; private set; }
public AccountGroupUpdateByPlayerEventArgs(TSPlayer player, string accountName, Group group) : base(accountName, group)
{
this.Player = player;
}
}
public class AccountHooks public class AccountHooks
{ {
public delegate void AccountCreateD(AccountCreateEventArgs e); public delegate void AccountCreateD(AccountCreateEventArgs e);
@ -62,5 +94,25 @@ namespace TShockAPI.Hooks
AccountDelete(new AccountDeleteEventArgs(u)); AccountDelete(new AccountDeleteEventArgs(u));
} }
public delegate void AccountGroupUpdateD(AccountGroupUpdateEventArgs e);
public static event AccountGroupUpdateD AccountGroupUpdate;
public static bool OnAccountGroupUpdate(UserAccount account, TSPlayer author, ref Group group)
{
AccountGroupUpdateEventArgs args = new AccountGroupUpdateByPlayerEventArgs(author, account.Name, group);
AccountGroupUpdate?.Invoke(args);
group = args.Group;
return args.Handled;
}
public static bool OnAccountGroupUpdate(UserAccount account, ref Group group)
{
AccountGroupUpdateEventArgs args = new AccountGroupUpdateByPluginEventArgs(account.Name, group);
AccountGroupUpdate?.Invoke(args);
group = args.Group;
return args.Handled;
}
} }
} }