diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs
index bb5dcde1..9b465075 100644
--- a/TShockAPI/Utils.cs
+++ b/TShockAPI/Utils.cs
@@ -299,20 +299,23 @@ namespace TShockAPI
}
///
- /// Gets a list of items by ID or name
+ /// Gets a list of items by ID, Name or Tag.
///
- /// Item ID or name
- /// List of Items
- public List- GetItemByIdOrName(string idOrName)
+ /// Item ID, Name or Tag.
+ /// A list of matching items.
+ public List
- GetItemByIdOrName(string text)
{
int type = -1;
- if (int.TryParse(idOrName, out type))
+ if (Int32.TryParse(text, out type))
{
if (type >= Main.maxItemTypes)
return new List
- ();
return new List
- {GetItemById(type)};
}
- return GetItemByName(idOrName);
+ Item item = GetItemFromTag(text);
+ if (item != null)
+ return new List
- () { item };
+ return GetItemByName(text);
}
///
@@ -340,14 +343,36 @@ namespace TShockAPI
for (int i = -48; i < Main.maxItemTypes; i++)
{
item.netDefaults(i);
+ if (String.IsNullOrWhiteSpace(item.name))
+ continue;
if (item.name.ToLower() == nameLower)
- return new List
- {item};
+ return new List
- { item };
if (item.name.ToLower().StartsWith(nameLower))
- found.Add((Item)item.Clone());
+ found.Add(item.Clone());
}
return found;
}
+ ///
+ /// Gets an item based on a chat item tag.
+ ///
+ /// A tag in the [i/s#/p#:netid] format.
+ /// The item represented by the tag.
+ public Item GetItemFromTag(string tag)
+ {
+ Regex regex = new Regex(@"\[i(tem)?(?:\/s(?\d{1,3}))?(?:\/p(?\d{1,3}))?:(?-?\d{1,4})\]");
+ Match match = regex.Match(tag);
+ if (!match.Success)
+ return null;
+ Item item = new Item();
+ item.netDefaults(Int32.Parse(match.Groups["NetID"].Value));
+ if (!String.IsNullOrWhiteSpace(match.Groups["Stack"].Value))
+ item.stack = Int32.Parse(match.Groups["Stack"].Value);
+ if (!String.IsNullOrWhiteSpace(match.Groups["Prefix"].Value))
+ item.prefix = Byte.Parse(match.Groups["Prefix"].Value);
+ return item;
+ }
+
///
/// Gets an NPC by ID or Name
///