Skip to content

Commit

Permalink
Make LineWrapper same spacing as rest of code
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jun 2, 2020
1 parent 5c18fe9 commit 824fa08
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
39 changes: 19 additions & 20 deletions MCGalaxy/Chat/LineWrapper.cs
Expand Up @@ -28,36 +28,35 @@ public static class LineWrapper {
message = Regex.Replace(message, @"(&[0-9a-f])+$", "");

int limit = NetUtils.StringSize; string color = "";
while ( message.Length > 0 ) {
//if (Regex.IsMatch(message, "&a")) break;
while (message.Length > 0) {

if ( lines.Count > 0 ) {
if ( message[0] == '&' )
if (lines.Count > 0 ) {
if (message[0] == '&')
message = "> " + message.Trim();
else
message = "> " + color + message.Trim();
}

if ( message.IndexOf("&") == message.IndexOf("&", message.IndexOf("&") + 1) - 2 )
if (message.IndexOf("&") == message.IndexOf("&", message.IndexOf("&") + 1) - 2)
message = message.Remove(message.IndexOf("&"), 2);

if ( message.Length <= limit ) { lines.Add(message); break; }
for ( int i = limit - 1; i > limit - 20; --i )
if ( message[i] == ' ' ) {
if (message.Length <= limit) { lines.Add(message); break; }
for (int i = limit - 1; i > limit - 20; i--)
if (message[i] == ' ') {
lines.Add(message.Substring(0, i));
goto Next;
}

retry:
if ( message.Length == 0 || limit == 0 ) { return lines; }
if (message.Length == 0 || limit == 0) { return lines; }

try {
if ( message.Substring(limit - 2, 1) == "&" || message.Substring(limit - 1, 1) == "&" ) {
if (message.Substring(limit - 2, 1) == "&" || message.Substring(limit - 1, 1) == "&") {
message = message.Remove(limit - 2, 1);
limit -= 2;
goto retry;
}
else if ( message[limit - 1] < 32 || message[limit - 1] > 127 ) {
else if (message[limit - 1] < 32 || message[limit - 1] > 127) {
message = message.Remove(limit - 1, 1);
limit -= 1;
//goto retry;
Expand All @@ -67,29 +66,29 @@ public static class LineWrapper {
lines.Add(message.Substring(0, limit));

Next: message = message.Substring(lines[lines.Count - 1].Length);
if ( lines.Count == 1 ) limit = 60;
if (lines.Count == 1) limit = 60;

int index = lines[lines.Count - 1].LastIndexOf('&');
if ( index != -1 ) {
if ( index < lines[lines.Count - 1].Length - 1 ) {
if (index != -1) {
if (index < lines[lines.Count - 1].Length - 1) {
char next = lines[lines.Count - 1][index + 1];
if ( Colors.Map(ref next) ) color = "&" + next;
if ( index == lines[lines.Count - 1].Length - 1 ) {
if (Colors.Map(ref next)) color = "&" + next;
if (index == lines[lines.Count - 1].Length - 1) {
lines[lines.Count - 1] = lines[lines.Count - 1].Substring(0, lines[lines.Count - 1].Length - 2);
}
}
else if ( message.Length != 0 ) {
else if (message.Length != 0) {
char next = message[0];
if ( Colors.Map(ref next) ) color = "&" + next;
if (Colors.Map(ref next)) color = "&" + next;
lines[lines.Count - 1] = lines[lines.Count - 1].Substring(0, lines[lines.Count - 1].Length - 1);
message = message.Substring(1);
}
}
}
for ( int i = 0; i < lines.Count; i++ ) // Gotta do it the old fashioned way...
for (int i = 0; i < lines.Count; i++) // Gotta do it the old fashioned way...
{
char[] temp = lines[i].ToCharArray();
if ( temp[temp.Length - 2] == '&' ) {
if (temp[temp.Length - 2] == '&') {
temp[temp.Length - 1] = ' ';
temp[temp.Length - 2] = ' ';
}
Expand Down
1 change: 0 additions & 1 deletion MCGalaxy/Commands/Chat/CmdSend.cs
Expand Up @@ -16,7 +16,6 @@
permissions and limitations under the Licenses.
*/
using System;
using System.Text.RegularExpressions;
using MCGalaxy.SQL;

namespace MCGalaxy.Commands.Chatting {
Expand Down
1 change: 0 additions & 1 deletion MCGalaxy/Player/Player.Handlers.cs
Expand Up @@ -28,7 +28,6 @@
using MCGalaxy.SQL;
using MCGalaxy.Util;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;

namespace MCGalaxy {
public partial class Player : IDisposable {
Expand Down
7 changes: 2 additions & 5 deletions MCGalaxy/Player/Player.cs
Expand Up @@ -15,19 +15,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using MCGalaxy.Blocks;
using MCGalaxy.DB;
using MCGalaxy.Drawing;
using MCGalaxy.Events.EconomyEvents;
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Games;
using MCGalaxy.SQL;
using MCGalaxy.Network;
using MCGalaxy.Tasks;
using MCGalaxy.Maths;
using MCGalaxy.Network;
using MCGalaxy.SQL;
using BlockID = System.UInt16;

namespace MCGalaxy {
Expand Down

0 comments on commit 824fa08

Please sign in to comment.