diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index b75deddc..c04fd2e9 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -3347,8 +3347,14 @@ namespace TShockAPI { if (itemAmount == 0 || itemAmount > item.maxStack) itemAmount = item.maxStack; - args.Player.GiveItem(item.type, item.name, item.width, item.height, itemAmount, prefix); - args.Player.SendMessage(string.Format("Gave {0} {1}(s).", itemAmount, item.name)); + if (args.Player.GiveItem(item.type, item.name, item.width, item.height, itemAmount, prefix)) + { + args.Player.SendMessage(string.Format("Gave {0} {1}(s).", itemAmount, item.name)); + } + else + { + args.Player.SendMessage("The item is banned and the config prevents you from spawning banned items.", Color.Red); + } } else { @@ -3425,9 +3431,16 @@ namespace TShockAPI { if (itemAmount == 0 || itemAmount > item.maxStack) itemAmount = item.maxStack; - plr.GiveItem(item.type, item.name, item.width, item.height, itemAmount, prefix); - args.Player.SendMessage(string.Format("Gave {0} {1} {2}(s).", plr.Name, itemAmount, item.name)); - plr.SendMessage(string.Format("{0} gave you {1} {2}(s).", args.Player.Name, itemAmount, item.name)); + if( plr.GiveItem(item.type, item.name, item.width, item.height, itemAmount, prefix)) + { + args.Player.SendMessage(string.Format("Gave {0} {1} {2}(s).", plr.Name, itemAmount, item.name)); + plr.SendMessage(string.Format("{0} gave you {1} {2}(s).", args.Player.Name, itemAmount, item.name)); + } + else + { + args.Player.SendMessage("The item is banned and the config prevents spawning banned items.", Color.Red); + } + } else { diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 5a5af2e1..794cd277 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -220,14 +220,13 @@ namespace TShockAPI [Description("Allows hallow to spread when a world is hardmode.")] public bool AllowHallowCreep = true; - [Description("How many things a statue can spawn within 200 pixels(?) before it stops spawning. Default = 3")] - public int StatueSpawn200 = 3; + [Description("How many things a statue can spawn within 200 pixels(?) before it stops spawning. Default = 3")] public int StatueSpawn200 = 3; - [Description("How many things a statue can spawn within 600 pixels(?) before it stops spawning. Default = 6")] - public int StatueSpawn600 = 6; + [Description("How many things a statue can spawn within 600 pixels(?) before it stops spawning. Default = 6")] public int StatueSpawn600 = 6; - [Description("How many things a statue spawns can exist in the world before it stops spawning. Default = 10")] - public int StatueSpawnWorld = 10; + [Description("How many things a statue spawns can exist in the world before it stops spawning. Default = 10")] public int StatueSpawnWorld = 10; + + [Description("Prevent banned items from being /i or /give")] public bool PreventBannedItemSpawn = false; public static ConfigFile Read(string path) { diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index e0fbe937..6be973b5 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -359,9 +359,11 @@ namespace TShockAPI return false; } - public virtual void GiveItem(int type, string name, int width, int height, int stack, int prefix = 0) + public virtual bool 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); + if (TShock.Itembans.ItemIsBanned(name) && TShock.Config.PreventBannedItemSpawn) + return false; // This is for special pickaxe/hammers/swords etc Main.item[itemid].SetDefaults(name); // The set default overrides the wet and stack set by NewItem @@ -372,6 +374,7 @@ namespace TShockAPI Main.item[itemid].prefix = (byte) prefix; NetMessage.SendData((int) PacketTypes.ItemDrop, -1, -1, "", itemid, 0f, 0f, 0f); NetMessage.SendData((int) PacketTypes.ItemOwner, -1, -1, "", itemid, 0f, 0f, 0f); + return true; } public virtual void SendMessage(string msg)