Skip to content
Permalink
Browse files

Use simpler ToPlainString that uses less memory to create, and doesn'…

…t need a regex to parse it
  • Loading branch information...
UnknownShadow200 committed Nov 20, 2017
1 parent 0f1f74e commit 0b5b107d2470ea1237888419c200babfe2605e19
@@ -2801,7 +2801,7 @@ private static void DrawImageCallback(Player player, Vector3I[] marks, object ta
if (player.World != null && player.World.Map != null) {
int blocksDrawn = 0, blocksSkipped = 0;
UndoState undoState = player.DrawBegin(null);
for (int i = 1; i <= length; i++) {
for (int i = 0; i < length; i++) {
Vector3I nextX = pos; nextX.X += dir.Next(0, 2) * 2 - 1;
Vector3I nextY = pos; nextY.Y += dir.Next(0, 2) * 2 - 1;
Vector3I nextZ = pos; nextZ.Z += dir.Next(0, 2) * 2 - 1;
@@ -1605,12 +1605,12 @@ static void UnfreezeHandler(Player player, CommandReader cmd)
player.Message("Teleported to {0}'s last block change", info.Name);
return;
} else {
player.Message("That users last known position is not on this world");
player.Message("User's last block change is not on this world");
player.Message("Please use &H/j {0} &Sto go there", Color.StripColors(info.LastWorld, true));
return;
}
} else {
player.Message("That user does not have a last known position");
player.Message("That user does not have a last known block change position");
return;
}
}
@@ -131,7 +131,7 @@ partial class Player {
if( h == null ) return false;
h( null, e );
e.Player.Info.LastWorld = e.Player.World.ClassyName;
e.Player.Info.LastWorldPos = e.Player.Position.ToString();
e.Player.Info.LastWorldPos = e.Player.Position.ToPlainString();
return e.Cancel;
}

@@ -143,7 +143,7 @@ partial class Player {
handler( null, new PlayerClickedEventArgs( player, coords, action, block ) );
}
player.Info.LastWorld = player.World.ClassyName;
player.Info.LastWorldPos = player.Position.ToString();
player.Info.LastWorldPos = player.Position.ToPlainString();
}

internal static void RaisePlayerPlacedBlockEvent( Player player, Map map, Vector3I coords,
@@ -1132,7 +1132,7 @@ public void Message([NotNull] byte messageType, [NotNull] string message, [NotNu
RaisePlayerClickedEvent( this, coords, e.Action, e.Block );
PlaceBlock( coords, e.Action, e.Block );
Info.LastWorld = this.World.ClassyName;
Info.LastWorldPos = this.Position.ToString();
Info.LastWorldPos = this.Position.ToPlainString();
}
}

@@ -90,14 +90,30 @@ public struct Position : IEquatable<Position> {

#endregion

public override string ToString()
{
public override string ToString() {
return String.Format("&S(X:&f{0}&S Y:&f{1}&S Z:&f{2}&S R:&f{3}&S L:&f{4}&S)", X, Y, Z, R, L);
}

public string ToPlainString() {
return X + "_" + Y + "_" + Z + "_" + R + "_" + L;
}

public static Position FromString(string text) {
Position pos = new Position();

try {
// New ToPlainString format
if (text.IndexOf('_') >= 0) {
string[] bits = text.Split('_');
pos.X = int.Parse(bits[0]);
pos.Y = int.Parse(bits[1]);
pos.Z = int.Parse(bits[2]);
pos.R = byte.Parse(bits[3]);
pos.L = byte.Parse(bits[4]);
return pos;
}

// Backwards compatibility with old format
string pat = @"\(X:(.*)Y:(.*) Z:(.*) R:(.*) L:(.*)\)";
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
text = Color.StripColors(text, true);

0 comments on commit 0b5b107

Please sign in to comment.
You can’t perform that action at this time.