Implement FoodPlatter placing event.
This is called when a player is placing a fruit (item) in a plate. Adding checks to see if they have permission to place or replace a fruit in the item. Checks if they are within range. And a check to see if they are legitimately placing the item from their hand, and not by sending a raw packet.
This commit is contained in:
parent
814801d894
commit
0fa8ae13d7
3 changed files with 111 additions and 3 deletions
|
|
@ -150,7 +150,8 @@ namespace TShockAPI
|
|||
{ PacketTypes.ToggleParty, HandleToggleParty },
|
||||
{ PacketTypes.CrystalInvasionStart, HandleOldOnesArmy },
|
||||
{ PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 },
|
||||
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 }
|
||||
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 },
|
||||
{ PacketTypes.FoodPlatterTryPlacing, HandleFoodPlatterTryPlacing }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -1863,6 +1864,52 @@ namespace TShockAPI
|
|||
return args.Handled;
|
||||
}
|
||||
|
||||
public class FoodPlatterTryPlacingEventArgs : GetDataHandledEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The X tile position of the placement action.
|
||||
/// </summary>
|
||||
public short TileX { get; set; }
|
||||
/// <summary>
|
||||
/// The Y tile position of the placement action.
|
||||
/// </summary>
|
||||
public short TileY { get; set; }
|
||||
/// <summary>
|
||||
/// The Item ID that is being placed in the plate.
|
||||
/// </summary>
|
||||
public short ItemID { get; set; }
|
||||
/// <summary>
|
||||
/// The prefix of the item that is being placed in the plate.
|
||||
/// </summary>
|
||||
public byte Prefix { get; set; }
|
||||
/// <summary>
|
||||
/// The stack of the item that is being placed in the plate.
|
||||
/// </summary>
|
||||
public short Stack { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Called when a player is placing an item in a food plate.
|
||||
/// </summary>
|
||||
public static HandlerList<FoodPlatterTryPlacingEventArgs> FoodPlatterTryPlacing = new HandlerList<FoodPlatterTryPlacingEventArgs>();
|
||||
private static bool OnFoodPlatterTryPlacing(TSPlayer player, MemoryStream data, short tileX, short tileY, short itemID, byte prefix, short stack)
|
||||
{
|
||||
if (FoodPlatterTryPlacing == null)
|
||||
return false;
|
||||
|
||||
var args = new FoodPlatterTryPlacingEventArgs
|
||||
{
|
||||
Player = player,
|
||||
Data = data,
|
||||
TileX = tileX,
|
||||
TileY = tileY,
|
||||
ItemID = itemID,
|
||||
Prefix = prefix,
|
||||
Stack = stack,
|
||||
};
|
||||
FoodPlatterTryPlacing.Invoke(null, args);
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static bool HandlePlayerInfo(GetDataHandlerArgs args)
|
||||
|
|
@ -3559,7 +3606,19 @@ namespace TShockAPI
|
|||
|
||||
return false;
|
||||
}
|
||||
private static bool HandleFoodPlatterTryPlacing(GetDataHandlerArgs args)
|
||||
{
|
||||
short tileX = args.Data.ReadInt16();
|
||||
short tileY = args.Data.ReadInt16();
|
||||
short itemID = args.Data.ReadInt16();
|
||||
byte prefix = args.Data.ReadInt8();
|
||||
short stack = args.Data.ReadInt16();
|
||||
|
||||
if (OnFoodPlatterTryPlacing(args.Player, args.Data, tileX, tileY, itemID, prefix, stack))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum EditAction
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue