From bb206262033c51f6415ef53b12b442e7e6912c07 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Thu, 18 Jun 2020 17:32:08 +0200 Subject: [PATCH] Add building permission checks for Hat Rack modification. Keeping this code format to have the code be friendly with us in future updates, as well as display proper rejection message to the players. --- .../RequestTileEntityInteractionHandler.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/TShockAPI/Handlers/RequestTileEntityInteractionHandler.cs b/TShockAPI/Handlers/RequestTileEntityInteractionHandler.cs index 0cf77823..386a31e6 100644 --- a/TShockAPI/Handlers/RequestTileEntityInteractionHandler.cs +++ b/TShockAPI/Handlers/RequestTileEntityInteractionHandler.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Terraria; using Terraria.DataStructures; using Terraria.GameContent.Tile_Entities; using static TShockAPI.GetDataHandlers; @@ -21,14 +22,24 @@ namespace TShockAPI.Handlers TileEntity tileEntity; if (TileEntity.ByID.TryGetValue(args.TileEntityID, out tileEntity)) { - if (tileEntity is TEDisplayDoll) + if (tileEntity is TEHatRack && !args.Player.HasBuildPermission(tileEntity.Position.X, tileEntity.Position.Y, false)) { - 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; - } + args.Player.SendErrorMessage("You do not have permission to modify a Hat Rack in a protected area!"); + args.Handled = true; + return; + } + else if (tileEntity is TEDisplayDoll && !args.Player.HasBuildPermission(tileEntity.Position.X, tileEntity.Position.Y, false)) + { + args.Player.SendErrorMessage("You do not have permission to modify a Mannequin in a protected area!"); + args.Handled = true; + return; + } + else if (!args.Player.HasBuildPermission(tileEntity.Position.X, tileEntity.Position.Y, false)) + { + args.Player.SendErrorMessage("You do not have permission to modify a TileEntity in a protected area!"); + TShock.Log.ConsoleDebug($"RequestTileEntityInteractionHandler: Rejected packet due to lack of building permissions! - From {args.Player.Name} | Position X:{tileEntity.Position.X} Y:{tileEntity.Position.Y}, TileEntity type: {tileEntity.type}, Tile type: {Main.tile[tileEntity.Position.X, tileEntity.Position.Y].type}"); + args.Handled = true; + return; } } }