Merge branch 'general-devel' into commandhooks

This commit is contained in:
Lucas Nicodemus 2025-01-27 10:06:01 +09:00 committed by GitHub
commit 97d88b3b3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 1899 additions and 1069 deletions

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/>.
*/
using System.ComponentModel;
using TShockAPI.DB;
namespace TShockAPI.Hooks
{
@ -39,6 +40,31 @@ namespace TShockAPI.Hooks
}
}
public 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 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 delegate void AccountCreateD(AccountCreateEventArgs e);
@ -62,5 +88,25 @@ namespace TShockAPI.Hooks
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 AccountGroupUpdateEventArgs(account.Name, group);
AccountGroupUpdate?.Invoke(args);
group = args.Group;
return args.Handled;
}
}
}