From eca0c03189604ba1858190e636f38dcd67fd9f97 Mon Sep 17 00:00:00 2001 From: Enerdy Date: Mon, 6 Jul 2015 00:46:56 +0100 Subject: [PATCH] Add ColorTag() and ItemTag() to Utils.cs, to make those easier to use across plugins and possibly TShock in the future. --- TShockAPI/Utils.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 8cf79f9b..d0c32fca 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -1027,5 +1027,30 @@ namespace TShockAPI return resp; } } + + /// + /// Colors the given text by correctly applying the color chat tag. + /// + /// The text to color. + /// The color to apply. + /// The , surrounded by the color tag with the appropriated hex code. + public string ColorTag(string text, Color color) + { + return String.Format("[c/{0}:{1}]", color.Hex3(), text); + } + + /// + /// Converts an item into its text representation using the item chat tag. + /// + /// The item to convert. + /// The NetID surrounded by the item tag with proper stack/prefix data. + public string ItemTag(Item item) + { + int netID = item.netID; + int stack = item.stack; + int prefix = item.prefix; + string options = stack > 1 ? "/s" + stack : prefix != 0 ? "/p" + prefix : ""; + return String.Format("[i{0}:{1}]", options, netID); + } } }