diff --git a/TShockAPI/Hooks/PlayerHooks.cs b/TShockAPI/Hooks/PlayerHooks.cs index 3114020b..7a3e2067 100644 --- a/TShockAPI/Hooks/PlayerHooks.cs +++ b/TShockAPI/Hooks/PlayerHooks.cs @@ -272,6 +272,32 @@ namespace TShockAPI.Hooks } } + /// + /// EventArgs used for the event. + /// + public class PlayerHasBuildPermissionEventArgs + { + /// + /// The player who fired the event. + /// + public TSPlayer Player { get; set; } + + /// + /// The X coordinate being checked. + /// + public int X { get; set; } + + /// + /// The Y coordinate being checked. + /// + public int Y { get; set; } + + /// + /// of the hook. + /// + public PermissionHookResult Result { get; set; } + } + /// /// A collection of events fired by players that can be hooked to. /// @@ -368,6 +394,16 @@ namespace TShockAPI.Hooks /// public static event PlayerTilebanPermissionD PlayerTilebanPermission; + /// + /// The delegate of the event. + /// + /// The EventArgs for this event. + public delegate void PlayerHasBuildPermissionD(PlayerHasBuildPermissionEventArgs e); + /// + /// Fired by players every time a build permission check occurs. + /// + public static event PlayerHasBuildPermissionD PlayerHasBuildPermission; + /// /// Fires the event. @@ -525,6 +561,22 @@ namespace TShockAPI.Hooks return args.Result; } + /// + /// Fires the event. + /// + /// The player firing the event. + /// Event result if the event has been handled, otherwise . + public static PermissionHookResult OnPlayerHasBuildPermission(TSPlayer player, int x, int y) + { + if (PlayerHasBuildPermission == null) + return PermissionHookResult.Unhandled; + + var args = new PlayerHasBuildPermissionEventArgs {Player = player, X = x, Y = y}; + PlayerHasBuildPermission(args); + + return args.Result; + } + } /// diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 93db08bc..1aa7203d 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -651,6 +651,12 @@ namespace TShockAPI /// True if the player can build at the given point from build, spawn, and region protection. public bool HasBuildPermission(int x, int y, bool shouldWarnPlayer = true) { + PermissionHookResult hookResult = PlayerHooks.OnPlayerHasBuildPermission(this, x, y); + if (hookResult != PermissionHookResult.Unhandled) + { + return hookResult == PermissionHookResult.Granted; + } + BuildPermissionFailPoint failure = BuildPermissionFailPoint.GeneralBuild; // The goal is to short circuit on easy stuff as much as possible. // Don't compute permissions unless needed, and don't compute taxing stuff unless needed.