TileEntityInteraction - Pass TileEntity object instead of ID in args.
This commit is contained in:
parent
972483340a
commit
89ab7be0f8
2 changed files with 25 additions and 29 deletions
|
|
@ -1909,9 +1909,9 @@ namespace TShockAPI
|
|||
public class RequestTileEntityInteractionEventArgs : GetDataHandledEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The ID of the TileEntity that the player is requesting interaction with.
|
||||
/// The TileEntity object that the player is requesting interaction with.
|
||||
/// </summary>
|
||||
public int TileEntityID { get; set; }
|
||||
public TileEntity TileEntity { get; set; }
|
||||
/// <summary>
|
||||
/// The player index in the packet who requests interaction with the TileEntity.
|
||||
/// </summary>
|
||||
|
|
@ -1921,7 +1921,7 @@ namespace TShockAPI
|
|||
/// Called when a player requests interaction with a TileEntity.
|
||||
/// </summary>
|
||||
public static HandlerList<RequestTileEntityInteractionEventArgs> RequestTileEntityInteraction = new HandlerList<RequestTileEntityInteractionEventArgs>();
|
||||
private static bool OnRequestTileEntityInteraction(TSPlayer player, MemoryStream data, int tileEntityID, byte playerIndex)
|
||||
private static bool OnRequestTileEntityInteraction(TSPlayer player, MemoryStream data, TileEntity tileEntity, byte playerIndex)
|
||||
{
|
||||
if (RequestTileEntityInteraction == null)
|
||||
return false;
|
||||
|
|
@ -1931,7 +1931,7 @@ namespace TShockAPI
|
|||
Player = player,
|
||||
Data = data,
|
||||
PlayerIndex = playerIndex,
|
||||
TileEntityID = tileEntityID
|
||||
TileEntity = tileEntity
|
||||
};
|
||||
RequestTileEntityInteraction.Invoke(null, args);
|
||||
return args.Handled;
|
||||
|
|
@ -3741,7 +3741,10 @@ namespace TShockAPI
|
|||
int tileEntityID = args.Data.ReadInt32();
|
||||
byte playerIndex = args.Data.ReadInt8();
|
||||
|
||||
if (OnRequestTileEntityInteraction(args.Player, args.Data, tileEntityID, playerIndex))
|
||||
if (!TileEntity.ByID.TryGetValue(tileEntityID, out TileEntity tileEntity))
|
||||
return false;
|
||||
|
||||
if (OnRequestTileEntityInteraction(args.Player, args.Data, tileEntity, playerIndex))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -17,31 +17,24 @@ namespace TShockAPI.Handlers
|
|||
{
|
||||
public void OnReceive(object sender, RequestTileEntityInteractionEventArgs args)
|
||||
{
|
||||
if (args.TileEntityID != -1)
|
||||
if (args.TileEntity is TEHatRack && !args.Player.HasBuildPermission(args.TileEntity.Position.X, args.TileEntity.Position.Y, false))
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
if (TileEntity.ByID.TryGetValue(args.TileEntityID, out tileEntity))
|
||||
{
|
||||
if (tileEntity is TEHatRack && !args.Player.HasBuildPermission(tileEntity.Position.X, tileEntity.Position.Y, false))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
args.Player.SendErrorMessage("You do not have permission to modify a Hat Rack in a protected area!");
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
else if (args.TileEntity is TEDisplayDoll && !args.Player.HasBuildPermission(args.TileEntity.Position.X, args.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(args.TileEntity.Position.X, args.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:{args.TileEntity.Position.X} Y:{args.TileEntity.Position.Y}, TileEntity type: {args.TileEntity.type}, Tile type: {Main.tile[args.TileEntity.Position.X, args.TileEntity.Position.Y].type}");
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue