From 08295343d7a5c0ff6020c88d510a27dd4e8d5126 Mon Sep 17 00:00:00 2001 From: Deathmax Date: Fri, 16 Dec 2011 17:07:17 +0800 Subject: [PATCH] Re-add prefix name support to /item and /give --- TShockAPI/Commands.cs | 16 ++++++++-------- TShockAPI/Utils.cs | 9 ++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 0d47bacf..35a60fff 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -2497,7 +2497,7 @@ namespace TShockAPI { if (args.Parameters.Count < 1) { - args.Player.SendMessage("Invalid syntax! Proper syntax: /item [item amount] [prefix id]", Color.Red); + args.Player.SendMessage("Invalid syntax! Proper syntax: /item [item amount] [prefix id/name]", Color.Red); return; } if (args.Parameters[0].Length == 0) @@ -2512,9 +2512,9 @@ namespace TShockAPI else if (args.Parameters.Count == 3) { int.TryParse(args.Parameters[1], out itemAmount); - int.TryParse(args.Parameters[2], out prefix); - if (prefix < 0 || prefix > 83) - prefix = 0; + var found = TShock.Utils.GetPrefixByIdOrName(args.Parameters[2]); + if (found.Count == 1) + prefix = found[0]; } var items = TShock.Utils.GetItemByIdOrName(args.Parameters[0]); if (items.Count == 0) @@ -2553,7 +2553,7 @@ namespace TShockAPI { if (args.Parameters.Count < 2) { - args.Player.SendMessage("Invalid syntax! Proper syntax: /give [item amount] [prefix id]", Color.Red); + args.Player.SendMessage("Invalid syntax! Proper syntax: /give [item amount] [prefix id/name]", Color.Red); return; } if (args.Parameters[0].Length == 0) @@ -2577,9 +2577,9 @@ namespace TShockAPI else if (args.Parameters.Count == 2) { int.TryParse(args.Parameters[0], out itemAmount); - int.TryParse(args.Parameters[1], out prefix); - if (prefix < 0 || prefix > 83) - prefix = 0; + var found = TShock.Utils.GetPrefixByIdOrName(args.Parameters[1]); + if (found.Count == 1) + prefix = found[0]; } if (items.Count == 0) diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 1904033c..8833c2f2 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -343,11 +343,11 @@ namespace TShockAPI public List GetPrefixByName(string name) { Item item = new Item(); + item.SetDefaults(0); for (int i = 1; i < 83; i++) { item.prefix = (byte) i; - item.AffixName(); - if (item.name.Trim() == name) + if (item.AffixName().Trim() == name) return new List { i }; } var found = new List(); @@ -356,10 +356,9 @@ namespace TShockAPI try { item.prefix = (byte) i; - item.AffixName(); - if (item.name.Trim().ToLower() == name.ToLower()) + if (item.AffixName().Trim().ToLower() == name.ToLower()) return new List { i }; - if (item.name.Trim().ToLower().StartsWith(name.ToLower())) + if (item.AffixName().Trim().ToLower().StartsWith(name.ToLower())) found.Add(i); } catch { }