From d2c1082c5990266b776263b5e21675f6b87a9c21 Mon Sep 17 00:00:00 2001 From: Twitchy Date: Wed, 22 Jun 2011 19:51:10 +1200 Subject: [PATCH] Adds banned items. Delete groups.txt and run server once. --- TShockAPI/Commands.cs | 1 + TShockAPI/FileTools.cs | 2 + TShockAPI/ItemManager.cs | 76 +++++++++++++++++++++++++++++++++ TShockAPI/Resources.Designer.cs | 18 ++++++-- TShockAPI/Resources.resx | 20 ++------- TShockAPI/TShock.cs | 14 ++++++ TShockAPI/TShockAPI.csproj | 6 ++- TShockAPI/config/groups.txt | 3 +- TShockAPI/config/itembans.txt | 2 + 9 files changed, 119 insertions(+), 23 deletions(-) create mode 100644 TShockAPI/ItemManager.cs create mode 100644 TShockAPI/config/itembans.txt diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 2e329415..69504bf5 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1383,6 +1383,7 @@ namespace TShockAPI } var items = Tools.GetItemByIdOrName(args.Parameters[0]); + if (items.Count == 0) { args.Player.SendMessage("Invalid item type!", Color.Red); diff --git a/TShockAPI/FileTools.cs b/TShockAPI/FileTools.cs index a87f94af..3998b8b3 100644 --- a/TShockAPI/FileTools.cs +++ b/TShockAPI/FileTools.cs @@ -29,6 +29,7 @@ namespace TShockAPI public static readonly string WhitelistPath = Path.Combine(TShock.SavePath, "whitelist.txt"); public static readonly string GroupsPath = Path.Combine(TShock.SavePath, "groups.txt"); public static readonly string UsersPath = Path.Combine(TShock.SavePath, "users.txt"); + public static readonly string ItemBansPath = Path.Combine(TShock.SavePath, "itembans.txt"); public static readonly string ConfigPath = Path.Combine(TShock.SavePath, "config.json"); public static void CreateFile(string file) @@ -60,6 +61,7 @@ namespace TShockAPI CreateIfNot(WhitelistPath); CreateIfNot(GroupsPath, Resources.groups); CreateIfNot(UsersPath, Resources.users); + CreateIfNot(ItemBansPath, Resources.itembans); try { diff --git a/TShockAPI/ItemManager.cs b/TShockAPI/ItemManager.cs new file mode 100644 index 00000000..1a139ee0 --- /dev/null +++ b/TShockAPI/ItemManager.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using Terraria; + +namespace TShockAPI +{ + class ItemManager + { + public static List BannedItems = new List(); + + public static void LoadBans() + { + try + { + if (!File.Exists(FileTools.ItemBansPath)) + return; + + BannedItems.Clear(); + + foreach (var line in File.ReadAllLines(FileTools.ItemBansPath)) + { + int ID = -1; + if (Int32.TryParse(line, out ID)) + { + if (ID <= Main.item.Length) + { + var item = Tools.GetItemById(ID); + BannedItems.Add(new ItemBan(ID, item.name)); + Log.Info("Item: " + item.name + " is banned"); + } + else + { + Log.Warn("Invalid ID " + ID); + } + } + } + } + catch (Exception e) + { + Log.Error(e.ToString()); + } + } + + public static bool ItemIsBanned(string ID) + { + foreach (ItemBan item in BannedItems) + { + if (ID == item.Name) + return true; + } + return false; + } + } + + public class ItemBan + { + public int ID { get; set; } + + public string Name { get; set; } + + public ItemBan(int id, string name) + { + ID = id; + Name = name; + } + + public ItemBan() + { + ID = -1; + Name = string.Empty; + } + } +} diff --git a/TShockAPI/Resources.Designer.cs b/TShockAPI/Resources.Designer.cs index 24f858b6..69d5beef 100644 --- a/TShockAPI/Resources.Designer.cs +++ b/TShockAPI/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.225 +// Runtime Version:4.0.30319.1 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -71,9 +71,9 @@ namespace TShockAPI { ///#ALWAYS DECLARE A GROUP'S PARENT BEFORE YOU DECLARE THE GROUP /// ///#currently avaliable permissions: - ///#kick ban ignorecheatdetection - ///#maintenance cfg causeevents spawnboss tp - ///#spawnmob che [rest of string was truncated]";. + ///#reservedslot - reserved slot for player + ///#canwater - allow players to use water + ///#canlav [rest of string was truncated]";. /// internal static string groups { get { @@ -81,6 +81,16 @@ namespace TShockAPI { } } + /// + /// Looks up a localized string similar to #see https://github.com/TShock/TShock/wiki/Item-List for a list of groups + ///#List each banned item below this with spaces. + /// + internal static string itembans { + get { + return ResourceManager.GetString("itembans", resourceCulture); + } + } + /// /// Looks up a localized string similar to #format ///#ip group diff --git a/TShockAPI/Resources.resx b/TShockAPI/Resources.resx index e260f5f5..21b8b3ab 100644 --- a/TShockAPI/Resources.resx +++ b/TShockAPI/Resources.resx @@ -1,21 +1,4 @@  -