Remove netID handling of GiveItem, and provide a smaller overload
This commit is contained in:
parent
983a678ff3
commit
ac8fe2a215
2 changed files with 77 additions and 57 deletions
|
|
@ -5297,7 +5297,7 @@ namespace TShockAPI
|
|||
if (itemAmount == 0 || itemAmount > item.maxStack)
|
||||
itemAmount = item.maxStack;
|
||||
|
||||
if (args.Player.GiveItemCheck(item.type, EnglishLanguage.GetItemNameById(item.type), item.width, item.height, itemAmount, prefixId))
|
||||
if (args.Player.GiveItemCheck(item.type, EnglishLanguage.GetItemNameById(item.type), itemAmount, prefixId))
|
||||
{
|
||||
item.prefix = (byte)prefixId;
|
||||
args.Player.SendSuccessMessage("Gave {0} {1}(s).", itemAmount, item.AffixName());
|
||||
|
|
@ -5436,7 +5436,7 @@ namespace TShockAPI
|
|||
{
|
||||
if (itemAmount == 0 || itemAmount > item.maxStack)
|
||||
itemAmount = item.maxStack;
|
||||
if (plr.GiveItemCheck(item.type, EnglishLanguage.GetItemNameById(item.type), item.width, item.height, itemAmount, prefix))
|
||||
if (plr.GiveItemCheck(item.type, EnglishLanguage.GetItemNameById(item.type), itemAmount, prefix))
|
||||
{
|
||||
args.Player.SendSuccessMessage(string.Format("Gave {0} {1} {2}(s).", plr.Name, itemAmount, item.Name));
|
||||
plr.SendSuccessMessage(string.Format("{0} gave you {1} {2}(s).", args.Player.Name, itemAmount, item.Name));
|
||||
|
|
|
|||
|
|
@ -866,13 +866,32 @@ namespace TShockAPI
|
|||
/// <summary>
|
||||
/// Gives an item to the player. Includes banned item spawn prevention to check if the player can spawn the item.
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="stack"></param>
|
||||
/// <param name="prefix"></param>
|
||||
/// <param name="type">The item ID.</param>
|
||||
/// <param name="name">The item name.</param>
|
||||
/// <param name="stack">The item stack.</param>
|
||||
/// <param name="prefix">The item prefix.</param>
|
||||
/// <returns>True or false, depending if the item passed the check or not.</returns>
|
||||
public bool GiveItemCheck(int type, string name, int stack, int prefix = 0)
|
||||
{
|
||||
if ((TShock.Itembans.ItemIsBanned(name) && TShock.Config.PreventBannedItemSpawn) &&
|
||||
(TShock.Itembans.ItemIsBanned(name, this) || !TShock.Config.AllowAllowedGroupsToSpawnBannedItems))
|
||||
return false;
|
||||
|
||||
GiveItem(type, stack, prefix);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives an item to the player. Includes banned item spawn prevention to check if the player can spawn the item.
|
||||
/// </summary>
|
||||
/// <param name="type">The item ID.</param>
|
||||
/// <param name="name">The item name.</param>
|
||||
/// <param name="width">The width of the receiver.</param>
|
||||
/// <param name="height">The height of the receiver.</param>
|
||||
/// <param name="stack">The item stack.</param>
|
||||
/// <param name="prefix">The item prefix.</param>
|
||||
/// <returns>True or false, depending if the item passed the check or not.</returns>
|
||||
[Obsolete("Use the GiveItemCheck overload with fewer parameters.")]
|
||||
public bool GiveItemCheck(int type, string name, int width, int height, int stack, int prefix = 0)
|
||||
{
|
||||
if ((TShock.Itembans.ItemIsBanned(name) && TShock.Config.PreventBannedItemSpawn) &&
|
||||
|
|
@ -886,28 +905,29 @@ namespace TShockAPI
|
|||
/// <summary>
|
||||
/// Gives an item to the player.
|
||||
/// </summary>
|
||||
/// <param name="type">The item's netID.</param>
|
||||
/// <param name="name">The tiem's name.</param>
|
||||
/// <param name="width">The item's width.</param>
|
||||
/// <param name="height">The item's height.</param>
|
||||
/// <param name="stack">The item's stack.</param>
|
||||
/// <param name="prefix">The item's prefix.</param>
|
||||
/// <param name="type">The item ID.</param>
|
||||
/// <param name="stack">The item stack.</param>
|
||||
/// <param name="prefix">The item prefix.</param>
|
||||
public virtual void GiveItem(int type, int stack, int prefix = 0)
|
||||
{
|
||||
int itemIndex = Item.NewItem((int)X, (int)Y, TPlayer.width, TPlayer.height, type, stack, true, prefix, true);
|
||||
SendData(PacketTypes.ItemDrop, "", itemIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives an item to the player.
|
||||
/// </summary>
|
||||
/// <param name="type">The item ID.</param>
|
||||
/// <param name="name">The item name. This parameter is unused.</param>
|
||||
/// <param name="width">The width of the receiver.</param>
|
||||
/// <param name="height">The height of the receiver.</param>
|
||||
/// <param name="stack">The item stack.</param>
|
||||
/// <param name="prefix">The item prefix.</param>
|
||||
[Obsolete("Use the GiveItem overload with fewer parameters.")]
|
||||
public virtual void GiveItem(int type, string name, int width, int height, int stack, int prefix = 0)
|
||||
{
|
||||
int itemid = Item.NewItem((int) X, (int) Y, width, height, type, stack, true, prefix, true);
|
||||
|
||||
// This is for special pickaxe/hammers/swords etc
|
||||
Main.item[itemid].netDefaults(type);
|
||||
// The set default overrides the wet and stack set by NewItem
|
||||
Main.item[itemid].wet = Collision.WetCollision(Main.item[itemid].position, Main.item[itemid].width,
|
||||
Main.item[itemid].height);
|
||||
Main.item[itemid].stack = stack;
|
||||
Main.item[itemid].owner = Index;
|
||||
Main.item[itemid].prefix = (byte) prefix;
|
||||
Main.item[itemid].noGrabDelay = 1;
|
||||
Main.item[itemid].velocity = Main.player[this.Index].velocity;
|
||||
NetMessage.SendData((int)PacketTypes.ItemDrop, -1, -1, NetworkText.Empty, itemid, 0f, 0f, 0f);
|
||||
NetMessage.SendData((int)PacketTypes.ItemOwner, -1, -1, NetworkText.Empty, itemid, 0f, 0f, 0f);
|
||||
int itemIndex = Item.NewItem((int)X, (int)Y, width, height, type, stack, true, prefix, true);
|
||||
SendData(PacketTypes.ItemDrop, "", itemIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue