Merge pull request #2642 from Killia0/hook-playerhasbuildpermission
Implement a PlayerHasBuildPermission Hook
This commit is contained in:
commit
2d095650cb
3 changed files with 59 additions and 0 deletions
|
|
@ -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)
|
* 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)
|
* 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 <type>` command line argument (@NotGeri)
|
* Added `-worldevil <type>` command line argument (@NotGeri)
|
||||||
|
* Added PlayerHasBuildPermission hook to PlayerHooks. (@AnzhelikaO, @Killia0)
|
||||||
|
|
||||||
## TShock 4.5.17
|
## 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)
|
* Fixed duplicate characters (twins) after repeatedly logging in as the same character due to connection not being immediately closed during `NetHooks_NameCollision`. (@gohjoseph)
|
||||||
|
|
|
||||||
|
|
@ -272,6 +272,32 @@ namespace TShockAPI.Hooks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// EventArgs used for the <see cref="PlayerHooks.PlayerHasBuildPermission"/> event.
|
||||||
|
/// </summary>
|
||||||
|
public class PlayerHasBuildPermissionEventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The player who fired the event.
|
||||||
|
/// </summary>
|
||||||
|
public TSPlayer Player { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The X coordinate being checked.
|
||||||
|
/// </summary>
|
||||||
|
public int X { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Y coordinate being checked.
|
||||||
|
/// </summary>
|
||||||
|
public int Y { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="PermissionHookResult"/> of the hook.
|
||||||
|
/// </summary>
|
||||||
|
public PermissionHookResult Result { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A collection of events fired by players that can be hooked to.
|
/// A collection of events fired by players that can be hooked to.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -368,6 +394,16 @@ namespace TShockAPI.Hooks
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static event PlayerTilebanPermissionD PlayerTilebanPermission;
|
public static event PlayerTilebanPermissionD PlayerTilebanPermission;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The delegate of the <see cref="PlayerHasBuildPermission"/> event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e">The EventArgs for this event.</param>
|
||||||
|
public delegate void PlayerHasBuildPermissionD(PlayerHasBuildPermissionEventArgs e);
|
||||||
|
/// <summary>
|
||||||
|
/// Fired by players every time a build permission check occurs.
|
||||||
|
/// </summary>
|
||||||
|
public static event PlayerHasBuildPermissionD PlayerHasBuildPermission;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fires the <see cref="PlayerPostLogin"/> event.
|
/// Fires the <see cref="PlayerPostLogin"/> event.
|
||||||
|
|
@ -525,6 +561,22 @@ namespace TShockAPI.Hooks
|
||||||
return args.Result;
|
return args.Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fires the <see cref="PlayerHasBuildPermission"/> event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="player">The player firing the event.</param>
|
||||||
|
/// <returns>Event result if the event has been handled, otherwise <see cref="PermissionHookResult.Unhandled"/>.</returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -651,6 +651,12 @@ namespace TShockAPI
|
||||||
/// <returns>True if the player can build at the given point from build, spawn, and region protection.</returns>
|
/// <returns>True if the player can build at the given point from build, spawn, and region protection.</returns>
|
||||||
public bool HasBuildPermission(int x, int y, bool shouldWarnPlayer = true)
|
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;
|
BuildPermissionFailPoint failure = BuildPermissionFailPoint.GeneralBuild;
|
||||||
// The goal is to short circuit on easy stuff as much as possible.
|
// 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.
|
// Don't compute permissions unless needed, and don't compute taxing stuff unless needed.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue