Skip to content

Commit 0b5b107

Browse files
Use simpler ToPlainString that uses less memory to create, and doesn't need a regex to parse it
1 parent 0f1f74e commit 0b5b107

5 files changed

Lines changed: 24 additions & 8 deletions

File tree

fCraft/Commands/BuildingCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2801,7 +2801,7 @@ private static void SnakeHandler(Player player, CommandReader cmd) {
28012801
if (player.World != null && player.World.Map != null) {
28022802
int blocksDrawn = 0, blocksSkipped = 0;
28032803
UndoState undoState = player.DrawBegin(null);
2804-
for (int i = 1; i <= length; i++) {
2804+
for (int i = 0; i < length; i++) {
28052805
Vector3I nextX = pos; nextX.X += dir.Next(0, 2) * 2 - 1;
28062806
Vector3I nextY = pos; nextY.Y += dir.Next(0, 2) * 2 - 1;
28072807
Vector3I nextZ = pos; nextZ.Z += dir.Next(0, 2) * 2 - 1;

fCraft/Commands/ModerationCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,12 +1605,12 @@ static void TeleportPHandler(Player player, CommandReader cmd) {
16051605
player.Message("Teleported to {0}'s last block change", info.Name);
16061606
return;
16071607
} else {
1608-
player.Message("That users last known position is not on this world");
1608+
player.Message("User's last block change is not on this world");
16091609
player.Message("Please use &H/j {0} &Sto go there", Color.StripColors(info.LastWorld, true));
16101610
return;
16111611
}
16121612
} else {
1613-
player.Message("That user does not have a last known position");
1613+
player.Message("That user does not have a last known block change position");
16141614
return;
16151615
}
16161616
}

fCraft/Player/Player.Events.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static bool RaisePlayerClickingEvent( [NotNull] PlayerClickingEventArgs e ) {
131131
if( h == null ) return false;
132132
h( null, e );
133133
e.Player.Info.LastWorld = e.Player.World.ClassyName;
134-
e.Player.Info.LastWorldPos = e.Player.Position.ToString();
134+
e.Player.Info.LastWorldPos = e.Player.Position.ToPlainString();
135135
return e.Cancel;
136136
}
137137

@@ -143,7 +143,7 @@ static void RaisePlayerClickedEvent( Player player, Vector3I coords,
143143
handler( null, new PlayerClickedEventArgs( player, coords, action, block ) );
144144
}
145145
player.Info.LastWorld = player.World.ClassyName;
146-
player.Info.LastWorldPos = player.Position.ToString();
146+
player.Info.LastWorldPos = player.Position.ToPlainString();
147147
}
148148

149149
internal static void RaisePlayerPlacedBlockEvent( Player player, Map map, Vector3I coords,

fCraft/Player/Player.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ public void PlaceBlockWithEvents( Vector3I coords, ClickAction action, Block typ
11321132
RaisePlayerClickedEvent( this, coords, e.Action, e.Block );
11331133
PlaceBlock( coords, e.Action, e.Block );
11341134
Info.LastWorld = this.World.ClassyName;
1135-
Info.LastWorldPos = this.Position.ToString();
1135+
Info.LastWorldPos = this.Position.ToPlainString();
11361136
}
11371137
}
11381138

fCraft/Player/Position.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,30 @@ public override int GetHashCode() {
9090

9191
#endregion
9292

93-
public override string ToString()
94-
{
93+
public override string ToString() {
9594
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);
9695
}
9796

97+
public string ToPlainString() {
98+
return X + "_" + Y + "_" + Z + "_" + R + "_" + L;
99+
}
100+
98101
public static Position FromString(string text) {
99102
Position pos = new Position();
103+
100104
try {
105+
// New ToPlainString format
106+
if (text.IndexOf('_') >= 0) {
107+
string[] bits = text.Split('_');
108+
pos.X = int.Parse(bits[0]);
109+
pos.Y = int.Parse(bits[1]);
110+
pos.Z = int.Parse(bits[2]);
111+
pos.R = byte.Parse(bits[3]);
112+
pos.L = byte.Parse(bits[4]);
113+
return pos;
114+
}
115+
116+
// Backwards compatibility with old format
101117
string pat = @"\(X:(.*)Y:(.*) Z:(.*) R:(.*) L:(.*)\)";
102118
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
103119
text = Color.StripColors(text, true);

0 commit comments

Comments
 (0)