From c418dda42ce264f3287777aa3fa2cd83373358f3 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Thu, 18 Jun 2020 17:08:14 +0200 Subject: [PATCH] Add RequestTileEntityInteractionHandler. Check Mannequin modif perms. Users can no longer open a Mannequin if they do not have building permissions at the position of the Mannequin. (Mannequins work as a chest since 1.4) --- TShockAPI/Bouncer.cs | 6 ++- .../RequestTileEntityInteractionHandler.cs | 37 +++++++++++++++++++ TShockAPI/TShockAPI.csproj | 1 + 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 TShockAPI/Handlers/RequestTileEntityInteractionHandler.cs diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 0ab38458..6f6959bc 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -39,6 +39,7 @@ namespace TShockAPI internal Handlers.SendTileSquareHandler STSHandler { get; set; } internal Handlers.NetModules.NetModulePacketHandler NetModuleHandler { get; set; } internal Handlers.EmojiHandler EmojiHandler { get; set; } + internal Handlers.RequestTileEntityInteractionHandler RequestTileEntityInteractionHandler { get; set; } internal Handlers.LandGolfBallInCupHandler LandGolfBallInCupHandler { get; set; } internal Handlers.SyncTilePickingHandler SyncTilePickingHandler { get; set; } @@ -54,7 +55,10 @@ namespace TShockAPI EmojiHandler = new Handlers.EmojiHandler(); GetDataHandlers.Emoji += EmojiHandler.OnReceive; - + + RequestTileEntityInteractionHandler = new Handlers.RequestTileEntityInteractionHandler(); + GetDataHandlers.RequestTileEntityInteraction += RequestTileEntityInteractionHandler.OnReceive; + LandGolfBallInCupHandler = new Handlers.LandGolfBallInCupHandler(); GetDataHandlers.LandGolfBallInCup += LandGolfBallInCupHandler.OnReceive; diff --git a/TShockAPI/Handlers/RequestTileEntityInteractionHandler.cs b/TShockAPI/Handlers/RequestTileEntityInteractionHandler.cs new file mode 100644 index 00000000..0cf77823 --- /dev/null +++ b/TShockAPI/Handlers/RequestTileEntityInteractionHandler.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terraria.DataStructures; +using Terraria.GameContent.Tile_Entities; +using static TShockAPI.GetDataHandlers; + +namespace TShockAPI.Handlers +{ + /// + /// + /// + public class RequestTileEntityInteractionHandler : IPacketHandler + { + public void OnReceive(object sender, RequestTileEntityInteractionEventArgs args) + { + if (args.TileEntityID != -1) + { + TileEntity tileEntity; + if (TileEntity.ByID.TryGetValue(args.TileEntityID, out tileEntity)) + { + if (tileEntity is TEDisplayDoll) + { + if (!args.Player.HasBuildPermission(tileEntity.Position.X, tileEntity.Position.Y, false)) + { + args.Player.SendErrorMessage("You have no permission to modify a Mannequin in a protected area!"); + args.Handled = true; + return; + } + } + } + } + } + } +} diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index f9885393..07d9ae8b 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -99,6 +99,7 @@ +