From c841a86cdf7987a079f5665aa7608ca02f12ef99 Mon Sep 17 00:00:00 2001 From: Ruby Rose Date: Wed, 7 Jun 2017 10:46:46 +0300 Subject: [PATCH 1/3] hooks added --- TShockAPI/Hooks/PlayerHooks.cs | 158 +++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/TShockAPI/Hooks/PlayerHooks.cs b/TShockAPI/Hooks/PlayerHooks.cs index 43684387..062a78b8 100644 --- a/TShockAPI/Hooks/PlayerHooks.cs +++ b/TShockAPI/Hooks/PlayerHooks.cs @@ -18,6 +18,7 @@ along with this program. If not, see . using System.Collections.Generic; using System.ComponentModel; +using TShockAPI.DB; namespace TShockAPI.Hooks { @@ -166,6 +167,87 @@ namespace TShockAPI.Hooks } } + /// + /// EventArgs used for the event. + /// + public class PlayerItembanPermissionEventArgs : HandledEventArgs + { + /// + /// The player who fired the event. + /// + public TSPlayer Player { get; set; } + + /// + /// The banned item being checked. + /// + public ItemBan BannedItem { get; set; } + + /// + /// Initializes a new instance of the PlayerItembanPermissionEventArgs class. + /// + /// The player who fired the event. + /// The permission being checked. + public PlayerItembanPermissionEventArgs(TSPlayer player, ItemBan bannedItem) + { + Player = player; + BannedItem = bannedItem; + } + } + + /// + /// EventArgs used for the event. + /// + public class PlayerProjbanPermissionEventArgs : HandledEventArgs + { + /// + /// The player who fired the event. + /// + public TSPlayer Player { get; set; } + + /// + /// The banned projectile being checked. + /// + public ProjectileBan BannedProjectile { get; set; } + + /// + /// Initializes a new instance of the PlayerProjbanPermissionEventArgs class. + /// + /// The player who fired the event. + /// The banned projectile being checked. + public PlayerProjbanPermissionEventArgs(TSPlayer player, ProjectileBan checkedProjectile) + { + Player = player; + BannedProjectile = checkedProjectile; + } + } + + /// + /// EventArgs used for the event. + /// + public class PlayerTilebanPermissionEventArgs : HandledEventArgs + { + /// + /// The player who fired the event. + /// + public TSPlayer Player { get; set; } + + /// + /// The banned tile being checked. + /// + public TileBan BannedTile { get; set; } + + /// + /// Initializes a new instance of the PlayerTilebanPermissionEventArgs class. + /// + /// The player who fired the event. + /// The banned tile being checked. + public PlayerTilebanPermissionEventArgs(TSPlayer player, TileBan checkedTile) + { + Player = player; + BannedTile = checkedTile; + } + } + /// /// A collection of events fired by players that can be hooked to. /// @@ -232,6 +314,37 @@ namespace TShockAPI.Hooks /// public static event PlayerPermissionD PlayerPermission; + /// + /// The delegate of the event. + /// + /// The EventArgs for this event. + public delegate void PlayerItembanPermissionD(PlayerItembanPermissionEventArgs e); + /// + /// Fired by players every time a permission check on banned items involving them occurs. + /// + public static event PlayerItembanPermissionD PlayerItembanPermission; + + /// + /// The delegate of the event. + /// + /// The EventArgs for this event. + public delegate void PlayerProjbanPermissionD(PlayerProjbanPermissionEventArgs e); + /// + /// Fired by players every time a permission check on banned projectiles involving them occurs. + /// + public static event PlayerProjbanPermissionD PlayerProjbanPermission; + + /// + /// The delegate of the event. + /// + /// The EventArgs for this event. + public delegate void PlayerTilebanPermissionD(PlayerTilebanPermissionEventArgs e); + /// + /// Fired by players every time a permission check on banned tiles involving them occurs. + /// + public static event PlayerTilebanPermissionD PlayerTilebanPermission; + + /// /// Fires the event. /// @@ -336,5 +449,50 @@ namespace TShockAPI.Hooks PlayerPermission(args); return args.Handled; } + + /// + /// Fires the event. + /// + /// The player firing the event. + /// True if the event has been handled. + public static bool OnPlayerItembanPermission(TSPlayer player, ItemBan bannedItem) + { + if (PlayerItembanPermission == null) + return false; + + var args = new PlayerItembanPermissionEventArgs(player, bannedItem); + PlayerItembanPermission(args); + return args.Handled; + } + + /// + /// Fires the event. + /// + /// The player firing the event. + /// True if the event has been handled. + public static bool OnPlayerProjbanPermission(TSPlayer player, ProjectileBan bannedProj) + { + if (PlayerProjbanPermission == null) + return false; + + var args = new PlayerProjbanPermissionEventArgs(player, bannedProj); + PlayerProjbanPermission(args); + return args.Handled; + } + + /// + /// Fires the event. + /// + /// The player firing the event. + /// True if the event has been handled. + public static bool OnPlayerTilebanPermission(TSPlayer player, TileBan bannedTile) + { + if (PlayerTilebanPermission == null) + return false; + + var args = new PlayerTilebanPermissionEventArgs(player, bannedTile); + PlayerTilebanPermission(args); + return args.Handled; + } } } From 81cb1381b44fdc16882da43ddb2df1f294277ba7 Mon Sep 17 00:00:00 2001 From: Ruby Rose Date: Wed, 7 Jun 2017 15:32:40 +0300 Subject: [PATCH 2/3] Add hooks for item/projectile/tile bans --- TShockAPI/DB/ItemManager.cs | 4 ++++ TShockAPI/DB/ProjectileManager.cs | 4 ++++ TShockAPI/DB/TileManager.cs | 4 ++++ TShockAPI/TSPlayer.cs | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/TShockAPI/DB/ItemManager.cs b/TShockAPI/DB/ItemManager.cs index 4ce43066..0ff89b40 100644 --- a/TShockAPI/DB/ItemManager.cs +++ b/TShockAPI/DB/ItemManager.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; using MySql.Data.MySqlClient; +using TShockAPI.Hooks; namespace TShockAPI.DB { @@ -200,6 +201,9 @@ namespace TShockAPI.DB if (ply.HasPermission(Permissions.usebanneditem)) return true; + if (PlayerHooks.OnPlayerItembanPermission(ply, this)) + return true; + var cur = ply.Group; var traversed = new List(); while (cur != null) diff --git a/TShockAPI/DB/ProjectileManager.cs b/TShockAPI/DB/ProjectileManager.cs index 3f736c9b..79bf9a37 100644 --- a/TShockAPI/DB/ProjectileManager.cs +++ b/TShockAPI/DB/ProjectileManager.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; using MySql.Data.MySqlClient; +using TShockAPI.Hooks; namespace TShockAPI.DB { @@ -205,6 +206,9 @@ namespace TShockAPI.DB if (ply.HasPermission(Permissions.canusebannedprojectiles)) return true; + if (PlayerHooks.OnPlayerProjbanPermission(ply, this)) + return true; + var cur = ply.Group; var traversed = new List(); while (cur != null) diff --git a/TShockAPI/DB/TileManager.cs b/TShockAPI/DB/TileManager.cs index 911bf27b..90a235f8 100644 --- a/TShockAPI/DB/TileManager.cs +++ b/TShockAPI/DB/TileManager.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; using MySql.Data.MySqlClient; +using TShockAPI.Hooks; namespace TShockAPI.DB { @@ -205,6 +206,9 @@ namespace TShockAPI.DB if (ply.HasPermission(Permissions.canusebannedtiles)) return true; + if (PlayerHooks.OnPlayerTilebanPermission(ply, this)) + return true; + var cur = ply.Group; var traversed = new List(); while (cur != null) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 43f7fe18..9b42d7b4 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1253,6 +1253,24 @@ namespace TShockAPI else return Group.HasPermission(permission); } + + /// + public bool HasPermission(ItemBan bannedItem) + { + return TShock.Itembans.ItemIsBanned(bannedItem.Name, this); + } + + /// + public bool HasPermission(ProjectileBan bannedProj) + { + return TShock.ProjectileBans.ProjectileIsBanned(bannedProj.ID, this); + } + + /// + public bool HasPermission(TileBan bannedTile) + { + return TShock.TileBans.TileIsBanned(bannedTile.ID, this); + } } public class TSRestPlayer : TSPlayer From 8ae0a3b5a6518a573f1287356f23d7a03398678a Mon Sep 17 00:00:00 2001 From: Ruby Rose Date: Thu, 8 Jun 2017 17:18:38 +0300 Subject: [PATCH 3/3] Write proper docs --- TShockAPI/TSPlayer.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 9b42d7b4..42d1b157 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1254,19 +1254,33 @@ namespace TShockAPI return Group.HasPermission(permission); } - /// + /// + /// Checks to see if a player has permission to use the specific banned item. + /// Fires the hook which may be handled to override item ban permission checks. + /// + /// The to check. + /// True if the player has permission to use the banned item. public bool HasPermission(ItemBan bannedItem) { return TShock.Itembans.ItemIsBanned(bannedItem.Name, this); } - /// + /// + /// Checks to see if a player has permission to use the specific banned projectile. + /// Fires the hook which may be handled to override projectile ban permission checks. + /// + /// The to check. + /// True if the player has permission to use the banned projectile. public bool HasPermission(ProjectileBan bannedProj) { return TShock.ProjectileBans.ProjectileIsBanned(bannedProj.ID, this); } - - /// + /// + /// Checks to see if a player has permission to use the specific banned tile. + /// Fires the hook which may be handled to override tile ban permission checks. + /// + /// The to check. + /// True if the player has permission to use the banned tile. public bool HasPermission(TileBan bannedTile) { return TShock.TileBans.TileIsBanned(bannedTile.ID, this);