diff --git a/TShockAPI/DB/ItemManager.cs b/TShockAPI/DB/ItemManager.cs index 0ff89b40..54ae8ee5 100644 --- a/TShockAPI/DB/ItemManager.cs +++ b/TShockAPI/DB/ItemManager.cs @@ -201,8 +201,9 @@ namespace TShockAPI.DB if (ply.HasPermission(Permissions.usebanneditem)) return true; - if (PlayerHooks.OnPlayerItembanPermission(ply, this)) - return true; + PermissionResult hookResult = PlayerHooks.OnPlayerItembanPermission(ply, this); + if (hookResult != PermissionResult.Inconclusive) + return hookResult == PermissionResult.Granted; var cur = ply.Group; var traversed = new List(); diff --git a/TShockAPI/DB/ProjectileManager.cs b/TShockAPI/DB/ProjectileManager.cs index 79bf9a37..234d3cca 100644 --- a/TShockAPI/DB/ProjectileManager.cs +++ b/TShockAPI/DB/ProjectileManager.cs @@ -206,8 +206,9 @@ namespace TShockAPI.DB if (ply.HasPermission(Permissions.canusebannedprojectiles)) return true; - if (PlayerHooks.OnPlayerProjbanPermission(ply, this)) - return true; + PermissionResult hookResult = PlayerHooks.OnPlayerProjbanPermission(ply, this); + if (hookResult != PermissionResult.Inconclusive) + return hookResult == PermissionResult.Granted; var cur = ply.Group; var traversed = new List(); diff --git a/TShockAPI/DB/TileManager.cs b/TShockAPI/DB/TileManager.cs index 90a235f8..83b079ab 100644 --- a/TShockAPI/DB/TileManager.cs +++ b/TShockAPI/DB/TileManager.cs @@ -206,8 +206,9 @@ namespace TShockAPI.DB if (ply.HasPermission(Permissions.canusebannedtiles)) return true; - if (PlayerHooks.OnPlayerTilebanPermission(ply, this)) - return true; + PermissionResult hookResult = PlayerHooks.OnPlayerTilebanPermission(ply, this); + if (hookResult != PermissionResult.Inconclusive) + return hookResult == PermissionResult.Granted; var cur = ply.Group; var traversed = new List(); diff --git a/TShockAPI/Hooks/PlayerHooks.cs b/TShockAPI/Hooks/PlayerHooks.cs index 062a78b8..7f2e8601 100644 --- a/TShockAPI/Hooks/PlayerHooks.cs +++ b/TShockAPI/Hooks/PlayerHooks.cs @@ -155,6 +155,11 @@ namespace TShockAPI.Hooks /// public string Permission { get; set; } + /// + /// of the hook. + /// + public PermissionResult Result { get; set; } + /// /// Initializes a new instance of the PlayerPermissionEventArgs class. /// @@ -164,6 +169,7 @@ namespace TShockAPI.Hooks { Player = player; Permission = permission; + Result = PermissionResult.Inconclusive; } } @@ -182,15 +188,21 @@ namespace TShockAPI.Hooks /// public ItemBan BannedItem { get; set; } + /// + /// of the hook. + /// + public PermissionResult Result { get; set; } + /// /// Initializes a new instance of the PlayerItembanPermissionEventArgs class. /// /// The player who fired the event. - /// The permission being checked. + /// The banned item being checked. public PlayerItembanPermissionEventArgs(TSPlayer player, ItemBan bannedItem) { Player = player; BannedItem = bannedItem; + Result = PermissionResult.Inconclusive; } } @@ -209,6 +221,11 @@ namespace TShockAPI.Hooks /// public ProjectileBan BannedProjectile { get; set; } + /// + /// of the hook. + /// + public PermissionResult Result { get; set; } + /// /// Initializes a new instance of the PlayerProjbanPermissionEventArgs class. /// @@ -218,6 +235,7 @@ namespace TShockAPI.Hooks { Player = player; BannedProjectile = checkedProjectile; + Result = PermissionResult.Inconclusive; } } @@ -236,6 +254,11 @@ namespace TShockAPI.Hooks /// public TileBan BannedTile { get; set; } + /// + /// of the hook. + /// + public PermissionResult Result { get; set; } + /// /// Initializes a new instance of the PlayerTilebanPermissionEventArgs class. /// @@ -245,6 +268,7 @@ namespace TShockAPI.Hooks { Player = player; BannedTile = checkedTile; + Result = PermissionResult.Inconclusive; } } @@ -439,60 +463,91 @@ namespace TShockAPI.Hooks /// Fires the event. /// /// The player firing the event. - /// True if the event has been handled. - public static bool OnPlayerPermission(TSPlayer player, string permission) + /// Event result if the event has been handled, otherwise . + public static PermissionResult OnPlayerPermission(TSPlayer player, string permission) { if (PlayerPermission == null) - return false; + return PermissionResult.Inconclusive; var args = new PlayerPermissionEventArgs(player, permission); PlayerPermission(args); - return args.Handled; + + if (args.Handled) + return args.Result; + else + return PermissionResult.Inconclusive; } /// /// Fires the event. /// /// The player firing the event. - /// True if the event has been handled. - public static bool OnPlayerItembanPermission(TSPlayer player, ItemBan bannedItem) + /// Event result if the event has been handled, otherwise . + public static PermissionResult OnPlayerItembanPermission(TSPlayer player, ItemBan bannedItem) { if (PlayerItembanPermission == null) - return false; + return PermissionResult.Inconclusive; var args = new PlayerItembanPermissionEventArgs(player, bannedItem); PlayerItembanPermission(args); - return args.Handled; + + if (args.Handled) + return args.Result; + else + return PermissionResult.Inconclusive; } /// /// Fires the event. /// /// The player firing the event. - /// True if the event has been handled. - public static bool OnPlayerProjbanPermission(TSPlayer player, ProjectileBan bannedProj) + /// Event result if the event has been handled, otherwise . + public static PermissionResult OnPlayerProjbanPermission(TSPlayer player, ProjectileBan bannedProj) { if (PlayerProjbanPermission == null) - return false; + return PermissionResult.Inconclusive; var args = new PlayerProjbanPermissionEventArgs(player, bannedProj); PlayerProjbanPermission(args); - return args.Handled; + + if (args.Handled) + return args.Result; + else + return PermissionResult.Inconclusive; } /// /// Fires the event. /// /// The player firing the event. - /// True if the event has been handled. - public static bool OnPlayerTilebanPermission(TSPlayer player, TileBan bannedTile) + /// Event result if the event has been handled, otherwise . + public static PermissionResult OnPlayerTilebanPermission(TSPlayer player, TileBan bannedTile) { if (PlayerTilebanPermission == null) - return false; + return PermissionResult.Inconclusive; var args = new PlayerTilebanPermissionEventArgs(player, bannedTile); PlayerTilebanPermission(args); - return args.Handled; + + if (args.Handled) + return args.Result; + else + return PermissionResult.Inconclusive; } + } + + /// + /// Defines the possible outcomes of handlers. + /// + public enum PermissionResult + { + /// Hook doesn't return a result on the permission check. + Inconclusive, + /// Permission is explicitly denied by a hook. + Denied, + /// Permission is explicitly granted by a hook. + Granted + } + } diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 8d0819bf..930c587b 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1265,8 +1265,10 @@ namespace TShockAPI /// True if the player has that permission. public bool HasPermission(string permission) { - if (PlayerHooks.OnPlayerPermission(this, permission)) - return true; + PermissionResult hookResult = PlayerHooks.OnPlayerPermission(this, permission); + + if (hookResult != PermissionResult.Inconclusive) + return hookResult == PermissionResult.Granted; if (tempGroup != null) return tempGroup.HasPermission(permission);