GetDataHandlers - Add RequestTileEntityInteraction hook.

This commit is contained in:
Patrikkk 2020-06-18 16:48:22 +02:00
parent 11a2a3e21b
commit 3012c92370

View file

@ -152,6 +152,7 @@ namespace TShockAPI
{ PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 },
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 },
{ PacketTypes.Emoji, HandleEmoji },
{ PacketTypes.RequestTileEntityInteraction, HandleRequestTileEntityInteraction },
{ PacketTypes.SyncTilePicking, HandleSyncTilePicking },
{ PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker },
{ PacketTypes.LandGolfBallInCup, HandleLandGolfBallInCup },
@ -1903,6 +1904,39 @@ namespace TShockAPI
return args.Handled;
}
/// For use in an OnRequestTileEntityInteraction event.
/// </summary>
public class RequestTileEntityInteractionEventArgs : GetDataHandledEventArgs
{
/// <summary>
/// The ID of the TileEntity that the player is requesting interaction with.
/// </summary>
public int TileEntityID { get; set; }
/// <summary>
/// The player index in the packet who requests interaction with the TileEntity.
/// </summary>
public byte PlayerIndex { get; set; }
}
/// <summary>
/// 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)
{
if (RequestTileEntityInteraction == null)
return false;
var args = new RequestTileEntityInteractionEventArgs
{
Player = player,
Data = data,
PlayerIndex = playerIndex,
TileEntityID = tileEntityID
};
RequestTileEntityInteraction.Invoke(null, args);
return args.Handled;
}
/// <summary>
/// For use in a SyncTilePicking event.
/// </summary>
@ -3702,6 +3736,17 @@ namespace TShockAPI
return false;
}
private static bool HandleRequestTileEntityInteraction(GetDataHandlerArgs args)
{
int tileEntityID = args.Data.ReadInt32();
byte playerIndex = args.Data.ReadInt8();
if (OnRequestTileEntityInteraction(args.Player, args.Data, tileEntityID, playerIndex))
return true;
return false;
}
private static bool HandleSyncTilePicking(GetDataHandlerArgs args)
{
byte playerIndex = args.Data.ReadInt8();