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
|
public class RequestTileEntityInteractionEventArgs : GetDataHandledEventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ID of the TileEntity that the player is requesting interaction with.
|
/// The TileEntity object that the player is requesting interaction with.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int TileEntityID { get; set; }
|
public TileEntity TileEntity { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The player index in the packet who requests interaction with the TileEntity.
|
/// The player index in the packet who requests interaction with the TileEntity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -1921,7 +1921,7 @@ namespace TShockAPI
|
||||||
/// Called when a player requests interaction with a TileEntity.
|
/// Called when a player requests interaction with a TileEntity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static HandlerList<RequestTileEntityInteractionEventArgs> RequestTileEntityInteraction = new HandlerList<RequestTileEntityInteractionEventArgs>();
|
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)
|
if (RequestTileEntityInteraction == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1931,7 +1931,7 @@ namespace TShockAPI
|
||||||
Player = player,
|
Player = player,
|
||||||
Data = data,
|
Data = data,
|
||||||
PlayerIndex = playerIndex,
|
PlayerIndex = playerIndex,
|
||||||
TileEntityID = tileEntityID
|
TileEntity = tileEntity
|
||||||
};
|
};
|
||||||
RequestTileEntityInteraction.Invoke(null, args);
|
RequestTileEntityInteraction.Invoke(null, args);
|
||||||
return args.Handled;
|
return args.Handled;
|
||||||
|
|
@ -3741,7 +3741,10 @@ namespace TShockAPI
|
||||||
int tileEntityID = args.Data.ReadInt32();
|
int tileEntityID = args.Data.ReadInt32();
|
||||||
byte playerIndex = args.Data.ReadInt8();
|
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 true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -17,31 +17,24 @@ namespace TShockAPI.Handlers
|
||||||
{
|
{
|
||||||
public void OnReceive(object sender, RequestTileEntityInteractionEventArgs args)
|
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;
|
args.Player.SendErrorMessage("You do not have permission to modify a Hat Rack in a protected area!");
|
||||||
if (TileEntity.ByID.TryGetValue(args.TileEntityID, out tileEntity))
|
args.Handled = true;
|
||||||
{
|
return;
|
||||||
if (tileEntity is TEHatRack && !args.Player.HasBuildPermission(tileEntity.Position.X, tileEntity.Position.Y, false))
|
}
|
||||||
{
|
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 Hat Rack in a protected area!");
|
{
|
||||||
args.Handled = true;
|
args.Player.SendErrorMessage("You do not have permission to modify a Mannequin in a protected area!");
|
||||||
return;
|
args.Handled = true;
|
||||||
}
|
return;
|
||||||
else if (tileEntity is TEDisplayDoll && !args.Player.HasBuildPermission(tileEntity.Position.X, tileEntity.Position.Y, false))
|
}
|
||||||
{
|
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 Mannequin in a protected area!");
|
{
|
||||||
args.Handled = true;
|
args.Player.SendErrorMessage("You do not have permission to modify a TileEntity in a protected area!");
|
||||||
return;
|
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;
|
||||||
else if (!args.Player.HasBuildPermission(tileEntity.Position.X, tileEntity.Position.Y, false))
|
return;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue