Add PlayerPermission hook, replace p.Group.HasPermission by p.HasPermission everywhere possible.
This commit is contained in:
parent
21f16e5908
commit
aa419283a9
13 changed files with 467 additions and 232 deletions
|
|
@ -21,66 +21,214 @@ using System.ComponentModel;
|
|||
|
||||
namespace TShockAPI.Hooks
|
||||
{
|
||||
/// <summary>
|
||||
/// EventArgs used for the <see cref="PlayerHooks.PlayerPostLogin"/> event.
|
||||
/// </summary>
|
||||
public class PlayerPostLoginEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The player who fired the event.
|
||||
/// </summary>
|
||||
public TSPlayer Player { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the PlayerPostLoginEventArgs class.
|
||||
/// </summary>
|
||||
/// <param name="ply">The player who fired the event.</param>
|
||||
public PlayerPostLoginEventArgs(TSPlayer ply)
|
||||
{
|
||||
Player = ply;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EventArgs used for the <see cref="PlayerHooks.PlayerPreLogin"/> event.
|
||||
/// </summary>
|
||||
public class PlayerPreLoginEventArgs : HandledEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The player who fired the event.
|
||||
/// </summary>
|
||||
public TSPlayer Player { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The player's login name.
|
||||
/// </summary>
|
||||
public string LoginName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The player's raw password.
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EventArgs used for the <see cref="PlayerHooks.PlayerLogout"/> event.
|
||||
/// </summary>
|
||||
public class PlayerLogoutEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The player who fired the event.
|
||||
/// </summary>
|
||||
public TSPlayer Player { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the PlayerLogoutEventArgs class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player who fired the event.</param>
|
||||
public PlayerLogoutEventArgs(TSPlayer player)
|
||||
{
|
||||
Player = player;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EventArgs used for the <see cref="PlayerHooks.PlayerCommand"/> event.
|
||||
/// </summary>
|
||||
public class PlayerCommandEventArgs : HandledEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The player who fired the event.
|
||||
/// </summary>
|
||||
public TSPlayer Player { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The command's name that follows the <see cref="Commands.Specifier"/>.
|
||||
/// </summary>
|
||||
public string CommandName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The command's full text.
|
||||
/// </summary>
|
||||
public string CommandText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The command's parameters extracted from <see cref="CommandText"/>.
|
||||
/// </summary>
|
||||
public List<string> Parameters { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The full list of server commands.
|
||||
/// </summary>
|
||||
public IEnumerable<Command> CommandList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The prefix used to send the command (either <see cref="Commands.Specifier"/> or <see cref="Commands.SilentSpecifier"/>).
|
||||
/// </summary>
|
||||
public string CommandPrefix { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EventArgs used for the <see cref="PlayerHooks.PlayerChat"/> event.
|
||||
/// </summary>
|
||||
public class PlayerChatEventArgs : HandledEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The player who fired the event.
|
||||
/// </summary>
|
||||
public TSPlayer Player { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The raw chat text as received by the server.
|
||||
/// </summary>
|
||||
public string RawText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="RawText"/> string after being formatted by TShock as specified in the config file.
|
||||
/// </summary>
|
||||
public string TShockFormattedText { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EventArgs used for the <see cref="PlayerHooks.PlayerPermission"/> event.
|
||||
/// </summary>
|
||||
public class PlayerPermissionEventArgs : HandledEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The player who fired the event.
|
||||
/// </summary>
|
||||
public TSPlayer Player { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the PlayerPermissionEventArgs class.
|
||||
/// </summary>
|
||||
/// <param name="player"></param>
|
||||
public PlayerPermissionEventArgs(TSPlayer player)
|
||||
{
|
||||
Player = player;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A collection of events fired by players that can be hooked to.
|
||||
/// </summary>
|
||||
public static class PlayerHooks
|
||||
{
|
||||
/// <summary>
|
||||
/// The delegate of the <see cref="PlayerPostLogin"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e">The EventArgs for this event.</param>
|
||||
public delegate void PlayerPostLoginD(PlayerPostLoginEventArgs e);
|
||||
/// <summary>
|
||||
/// Fired by players after they've successfully logged in to a user account.
|
||||
/// </summary>
|
||||
public static event PlayerPostLoginD PlayerPostLogin;
|
||||
|
||||
/// <summary>
|
||||
/// The delegate of the <see cref="PlayerPreLogin"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e">The EventArgs for this event.</param>
|
||||
public delegate void PlayerPreLoginD(PlayerPreLoginEventArgs e);
|
||||
/// <summary>
|
||||
/// Fired by players when sending login credentials to the server.
|
||||
/// </summary>
|
||||
public static event PlayerPreLoginD PlayerPreLogin;
|
||||
|
||||
/// <summary>
|
||||
/// The delegate of the <see cref="PlayerLogout"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e">The EventArgs for this event.</param>
|
||||
public delegate void PlayerLogoutD(PlayerLogoutEventArgs e);
|
||||
/// <summary>
|
||||
/// Fired by players upon logging out from a user account.
|
||||
/// </summary>
|
||||
public static event PlayerLogoutD PlayerLogout;
|
||||
|
||||
/// <summary>
|
||||
/// The delegate of the <see cref="PlayerCommand"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e">The EventArgs for this event.</param>
|
||||
public delegate void PlayerCommandD(PlayerCommandEventArgs e);
|
||||
/// <summary>
|
||||
/// Fired by players when using a command.
|
||||
/// </summary>
|
||||
public static event PlayerCommandD PlayerCommand;
|
||||
|
||||
/// <summary>
|
||||
/// The delegate of the <see cref="PlayerChat"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e">The EventArgs for this event.</param>
|
||||
public delegate void PlayerChatD(PlayerChatEventArgs e);
|
||||
/// <summary>
|
||||
/// Fired by players when they send a chat message packet to the server
|
||||
/// and before it is transmitted to the rest of the players.
|
||||
/// </summary>
|
||||
public static event PlayerChatD PlayerChat;
|
||||
|
||||
/// <summary>
|
||||
/// The delegate of the <see cref="PlayerPermission"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e">The EventArgs for this event.</param>
|
||||
public delegate void PlayerPermissionD(PlayerPermissionEventArgs e);
|
||||
/// <summary>
|
||||
/// Fired by players every time a permission check involving them occurs.
|
||||
/// </summary>
|
||||
public static event PlayerPermissionD PlayerPermission;
|
||||
|
||||
/// <summary>
|
||||
/// Fires the <see cref="PlayerPostLogin"/> event.
|
||||
/// </summary>
|
||||
/// <param name="ply">The player firing the event.</param>
|
||||
public static void OnPlayerPostLogin(TSPlayer ply)
|
||||
{
|
||||
if (PlayerPostLogin == null)
|
||||
|
|
@ -92,6 +240,16 @@ namespace TShockAPI.Hooks
|
|||
PlayerPostLogin(args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires the <see cref="PlayerCommand"/> event.
|
||||
/// </summary>
|
||||
/// <param name="player">The player firing the event.</param>
|
||||
/// <param name="cmdName">The command name.</param>
|
||||
/// <param name="cmdText">The raw command text.</param>
|
||||
/// <param name="args">The command args extracted from the command text.</param>
|
||||
/// <param name="commands">The list of commands.</param>
|
||||
/// <param name="cmdPrefix">The command specifier used.</param>
|
||||
/// <returns>True if the event has been handled.</returns>
|
||||
public static bool OnPlayerCommand(TSPlayer player, string cmdName, string cmdText, List<string> args, ref IEnumerable<Command> commands, string cmdPrefix)
|
||||
{
|
||||
if (PlayerCommand == null)
|
||||
|
|
@ -111,6 +269,13 @@ namespace TShockAPI.Hooks
|
|||
return playerCommandEventArgs.Handled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires the <see cref="PlayerPreLogin"/> event.
|
||||
/// </summary>
|
||||
/// <param name="ply">The player firing the event.</param>
|
||||
/// <param name="name">The user name.</param>
|
||||
/// <param name="pass">The password.</param>
|
||||
/// <returns>True if the event has been handled.</returns>
|
||||
public static bool OnPlayerPreLogin(TSPlayer ply, string name, string pass)
|
||||
{
|
||||
if (PlayerPreLogin == null)
|
||||
|
|
@ -121,6 +286,10 @@ namespace TShockAPI.Hooks
|
|||
return args.Handled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires the <see cref="PlayerLogout"/> event.
|
||||
/// </summary>
|
||||
/// <param name="ply">The player firing the event.</param>
|
||||
public static void OnPlayerLogout(TSPlayer ply)
|
||||
{
|
||||
if (PlayerLogout == null)
|
||||
|
|
@ -130,6 +299,12 @@ namespace TShockAPI.Hooks
|
|||
PlayerLogout(args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires the <see cref="PlayerChat"/> event.
|
||||
/// </summary>
|
||||
/// <param name="ply">The player firing the event.</param>
|
||||
/// <param name="rawtext">The raw chat text sent by the player.</param>
|
||||
/// <param name="tshockText">The chat text after being formatted.</param>
|
||||
public static void OnPlayerChat(TSPlayer ply, string rawtext, ref string tshockText)
|
||||
{
|
||||
if (PlayerChat == null)
|
||||
|
|
@ -139,5 +314,20 @@ namespace TShockAPI.Hooks
|
|||
PlayerChat(args);
|
||||
tshockText = args.TShockFormattedText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires the <see cref="PlayerPermission"/> event.
|
||||
/// </summary>
|
||||
/// <param name="player">The player firing the event.</param>
|
||||
/// <returns>True if the event has been handled.</returns>
|
||||
public static bool OnPlayerPermission(TSPlayer player)
|
||||
{
|
||||
if (PlayerPermission == null)
|
||||
return false;
|
||||
|
||||
var args = new PlayerPermissionEventArgs(player);
|
||||
PlayerPermission(args);
|
||||
return args.Handled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue