From 4b8805526be3cf209603d66835ea328b84a0868f Mon Sep 17 00:00:00 2001 From: MidnightTokyo <32614585+MidnightTokyo@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:32:30 +0300 Subject: [PATCH] Return original implementation with modified string length variable --- Rocket.Unturned/Chat/UnturnedChat.cs | 30 ++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) 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