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.
This commit is contained in:
Patrikkk 2020-06-18 17:32:08 +02:00
parent 2a0e1de285
commit bb20626203

View file

@ -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;
}
}
}