diff --git a/Rocket.Unturned/Chat/UnturnedChat.cs b/Rocket.Unturned/Chat/UnturnedChat.cs index 23ac8cf..cda8a3a 100644 --- a/Rocket.Unturned/Chat/UnturnedChat.cs +++ b/Rocket.Unturned/Chat/UnturnedChat.cs @@ -174,17 +174,35 @@ public static void Say(CSteamID CSteamID, string message, Color color) public static List wrapMessage(string text) { - List result = new List(); + if (text.Length == 0) + return new List(); - if (text.Length == 0) + string[] words = text.Split(' '); + List lines = new List(); + string currentLine = ""; + int maxLength = ChatManager.MAX_MESSAGE_LENGTH; + + foreach (var currentWord in words) { - return result; + + if ((currentLine.Length > maxLength) || + ((currentLine.Length + currentWord.Length) > maxLength)) + { + lines.Add(currentLine); + currentLine = ""; + } + + if (currentLine.Length > 0) + currentLine += " " + currentWord; + else + currentLine += currentWord; + } - for (int i = 0; i < text.Length; i += ChatManager.MAX_MESSAGE_LENGTH) - result.Add(text.Substring(i, Math.Min(ChatManager.MAX_MESSAGE_LENGTH, text.Length - i))); + if (currentLine.Length > 0) + lines.Add(currentLine); - return result; + return lines; } } } \ No newline at end of file