diff --git a/CHANGELOG.md b/CHANGELOG.md index f03c092d..318e82b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Only allow using Teleportation Potions, Magic Conch, and Demon Conch whilst holding them. (@drunderscore) * Updated server startup language to be more clear when encountering a fatal startup error. Now, the server gives more context as to what happened so that there's a better chance of people being able to help themselves. (@hakusaro) * Added `-worldevil ` command line argument (@NotGeri) +* Added PlayerHasBuildPermission hook to PlayerHooks. (@AnzhelikaO, @Killia0) ## TShock 4.5.17 * Fixed duplicate characters (twins) after repeatedly logging in as the same character due to connection not being immediately closed during `NetHooks_NameCollision`. (@gohjoseph) 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.