Trim before parse

This commit is contained in:
BruceChen 2022-09-05 22:21:04 +08:00
parent 0eb8d9998c
commit e5c3b914dd
2 changed files with 2 additions and 2 deletions

View file

@ -80,7 +80,7 @@ namespace MinecraftClient
/// <returns>Argument array or empty array if no arguments</returns> /// <returns>Argument array or empty array if no arguments</returns>
public static string[] getArgs(string command) public static string[] getArgs(string command)
{ {
string[] args = getArg(command).Split(' '); string[] args = getArg(command).Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (args.Length == 1 && args[0] == "") if (args.Length == 1 && args[0] == "")
{ {
return new string[] { }; return new string[] { };

View file

@ -91,7 +91,7 @@ namespace MinecraftClient.Commands
try try
{ {
Location current = handler.GetCurrentLocation(), currentCenter = new Location(current).ConvertToCenter(); Location current = handler.GetCurrentLocation(), currentCenter = new Location(current).ConvertToCenter();
double x = args[0].StartsWith('~') ? current.X + (args[0].Length > 1 ? double.Parse(args[0][1..]) : 0) : double.Parse(args[0]); double x = args[0].StartsWith('~') ? current.X + (args[0].Length > 1 ? double.Parse(args[0][1..]) : 0) : double.Parse(args[0]);
double y = args[1].StartsWith('~') ? current.Y + (args[1].Length > 1 ? double.Parse(args[1][1..]) : 0) : double.Parse(args[1]); double y = args[1].StartsWith('~') ? current.Y + (args[1].Length > 1 ? double.Parse(args[1][1..]) : 0) : double.Parse(args[1]);
double z = args[2].StartsWith('~') ? current.Z + (args[2].Length > 1 ? double.Parse(args[2][1..]) : 0) : double.Parse(args[2]); double z = args[2].StartsWith('~') ? current.Z + (args[2].Length > 1 ? double.Parse(args[2][1..]) : 0) : double.Parse(args[2]);