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
|
|
@ -67,6 +67,7 @@ namespace TShockAPI
|
|||
GetDataHandlers.MassWireOperation += OnMassWireOperation;
|
||||
GetDataHandlers.PlayerDamage += OnPlayerDamage;
|
||||
GetDataHandlers.KillMe += OnKillMe;
|
||||
GetDataHandlers.FoodPlatterTryPlacing += OnFoodPlatterTryPlacing;
|
||||
}
|
||||
|
||||
internal void OnGetSection(object sender, GetDataHandlers.GetSectionEventArgs args)
|
||||
|
|
@ -2062,6 +2063,54 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a player is trying to place an item into a food plate.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
internal void OnFoodPlatterTryPlacing(object sender, GetDataHandlers.FoodPlatterTryPlacingEventArgs args)
|
||||
{
|
||||
if (args.Player.ItemInHand.type != args.ItemID)
|
||||
{
|
||||
TShock.Log.ConsoleDebug("Bouncer / OnFoodPlatterTryPlacing rejected item not placed by hand from {0}", args.Player.Name);
|
||||
args.Player.SendTileSquare(args.TileX, args.TileY, 1);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
if (args.Player.IsBeingDisabled())
|
||||
{
|
||||
TShock.Log.ConsoleDebug("Bouncer / OnFoodPlatterTryPlacing rejected disabled from {0}", args.Player.Name);
|
||||
Item item = new Item();
|
||||
item.netDefaults(args.ItemID);
|
||||
args.Player.GiveItemCheck(args.ItemID, item.Name, args.Stack, args.Prefix);
|
||||
args.Player.SendTileSquare(args.TileX, args.TileY, 1);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.Player.HasBuildPermission(args.TileX, args.TileY))
|
||||
{
|
||||
TShock.Log.ConsoleDebug("Bouncer / OnFoodPlatterTryPlacing rejected permissions from {0}", args.Player.Name);
|
||||
Item item = new Item();
|
||||
item.netDefaults(args.ItemID);
|
||||
args.Player.GiveItemCheck(args.ItemID, item.Name, args.Stack, args.Prefix);
|
||||
args.Player.SendTileSquare(args.TileX, args.TileY, 1);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.Player.IsInRange(args.TileX, args.TileY))
|
||||
{
|
||||
TShock.Log.ConsoleDebug("Bouncer / OnFoodPlatterTryPlacing rejected range checks from {0}", args.Player.Name);
|
||||
Item item = new Item();
|
||||
item.netDefaults(args.ItemID);
|
||||
args.Player.GiveItemCheck(args.ItemID, item.Name, args.Stack, args.Prefix);
|
||||
args.Player.SendTileSquare(args.TileX, args.TileY, 1);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnSecondUpdate()
|
||||
{
|
||||
Task.Run(() =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue