Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 3f214cb

Browse files
committed
Merge pull request #15 from LeShred/master
New commands parser implications.
2 parents 6fccb2a + 55af2f8 commit 3f214cb

13 files changed

+78
-126
lines changed

EssentialsPlugin/ChatHandlers/Admin/HandleAdminTurrets.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public override bool AllowedInConsole()
3838

3939
public override bool HandleCommand(ulong userId, string[] words)
4040
{
41-
string[] splits = General.SplitString(string.Join(" ", words));
42-
if (splits.Length != 1)
41+
if (words.Length != 1)
4342
{
4443
Communication.SendPrivateInformation(userId, GetHelp());
4544
return true;
@@ -82,7 +81,7 @@ public override bool HandleCommand(ulong userId, string[] words)
8281
IMyEntity turret = block.FatBlock;
8382
bool state = FunctionalBlockEntity.GetState(turret);
8483

85-
if(splits[0].ToLower() == "toggle")
84+
if (words[0].ToLower() == "toggle")
8685
FunctionalBlockEntity.SetState(turret, !state);
8786

8887
count++;
@@ -92,7 +91,7 @@ public override bool HandleCommand(ulong userId, string[] words)
9291
else
9392
disabled++;
9493

95-
if (splits[0].ToLower() == "test" && state)
94+
if (words[0].ToLower() == "test" && state)
9695
{
9796
BoundingSphereD sphere = new BoundingSphereD(grid.GetPosition(), 2000);
9897
List<IMyEntity> testEntities = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);

EssentialsPlugin/ChatHandlers/HandleLastSeen.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ public override bool AllowedInConsole()
3838

3939
public override bool HandleCommand(ulong userId, string[] words)
4040
{
41-
string[] splits = General.SplitString(string.Join(" ", words));
42-
if (splits.Count() != 1)
41+
if (words.Count() != 1)
4342
{
4443
Communication.SendPrivateInformation(userId, GetHelp());
4544
return true;
4645
}
4746

48-
string userName = splits[0];
47+
string userName = words[0];
4948
ulong steamId = PlayerMap.Instance.GetSteamIdFromPlayerName(userName, true);
5049
if (steamId == 0)
5150
{

EssentialsPlugin/ChatHandlers/Waypoints/HandleWaypointAdd.cs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,9 @@ public override bool IsClientOnly()
4242
public override bool HandleCommand(ulong userId, string[] words)
4343
{
4444
if (!PluginSettings.Instance.WaypointsEnabled)
45-
if (!PluginSettings.Instance.WaypointsEnabled)
4645
return false;
47-
48-
string[] splits = General.SplitString(string.Join(" ", words));
4946

50-
if (splits.Length != 6 && splits.Length != 7 && splits.Length != 5 && splits.Length != 1)
47+
if (words.Length != 1 && words.Length != 5 && words.Length != 6 && words.Length != 7)
5148
{
5249
Communication.SendPrivateInformation(userId, GetHelp());
5350
return true;
@@ -60,7 +57,7 @@ public override bool HandleCommand(ulong userId, string[] words)
6057
return true;
6158
}
6259

63-
if (splits.Length == 1)
60+
if (words.Length == 1)
6461
{
6562
long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId);
6663
IMyEntity playerEntity = Player.FindControlledEntity(playerId);
@@ -71,9 +68,9 @@ public override bool HandleCommand(ulong userId, string[] words)
7168
}
7269

7370
Vector3D pos = playerEntity.GetPosition();
74-
string name = splits[0];
71+
string name = words[0];
7572

76-
Communication.SendClientMessage(userId, string.Format("/waypoint add \"{0}\" \"{0}\" Neutral {1} {2} {3}", name, Math.Floor(pos.X), Math.Floor(pos.Y), Math.Floor(pos.Z)));
73+
Communication.SendClientMessage(userId, string.Format("/waypoint add '{0}' '{0}' Neutral {1} {2} {3}", name, Math.Floor(pos.X), Math.Floor(pos.Y), Math.Floor(pos.Z)));
7774

7875
WaypointItem item = new WaypointItem();
7976
item.SteamId = userId;
@@ -83,53 +80,53 @@ public override bool HandleCommand(ulong userId, string[] words)
8380
item.WaypointType = WaypointTypes.Neutral;
8481
Waypoints.Instance.Add(item);
8582

86-
Communication.SendPrivateInformation(userId, string.Format("Waypoint added: {0} at {1}", item.Name, General.Vector3DToString(item.Position)));
83+
Communication.SendPrivateInformation(userId, string.Format("Waypoint added: '{0}' at {1}", item.Name, General.Vector3DToString(item.Position)));
8784
}
8885
else
8986
{
9087
int len = 5;
91-
if (splits.Length > 5)
88+
if (words.Length > 5)
9289
len = 6;
9390

9491
for (int r = len - 3; r < len; r++)
9592
{
9693
double test = 0d;
97-
if (!double.TryParse(splits[r], out test))
94+
if (!double.TryParse(words[r], out test))
9895
{
99-
Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", splits[r]));
96+
Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", words[r]));
10097
return true;
10198
}
10299
}
103100

104101
string add = "";
105-
foreach (string split in splits)
102+
foreach (string word in words)
106103
{
107104
if (add == "")
108-
add += split.ToLower();
105+
add += word.ToLower();
109106
else
110-
add += " " + split;
107+
add += " " + word;
111108
}
112109

113110
Communication.SendClientMessage(userId, string.Format("/waypoint add {0}", add));
114111

115112
string group = "";
116-
if (splits.Length == 7)
117-
group = splits[7];
113+
if (words.Length == 7)
114+
group = words[7];
118115

119116
WaypointItem item = new WaypointItem();
120117
item.SteamId = userId;
121-
item.Name = splits[0];
118+
item.Name = words[0];
122119

123-
int diff = splits.Length > 5 ? 1 : 0;
124-
item.Text = splits[diff];
120+
int diff = words.Length > 5 ? 1 : 0;
121+
item.Text = words[diff];
125122
WaypointTypes type = WaypointTypes.Neutral;
126-
Enum.TryParse<WaypointTypes>(splits[diff + 1], true, out type);
123+
Enum.TryParse<WaypointTypes>(words[diff + 1], true, out type);
127124
item.WaypointType = type;
128-
item.Position = new Vector3D(double.Parse(splits[diff + 2]), double.Parse(splits[diff + 3]), double.Parse(splits[diff + 4]));
125+
item.Position = new Vector3D(double.Parse(words[diff + 2]), double.Parse(words[diff + 3]), double.Parse(words[diff + 4]));
129126
item.Group = group;
130127
Waypoints.Instance.Add(item);
131128

132-
Communication.SendPrivateInformation(userId, string.Format("Waypoint added: {0} at {1}", item.Name, General.Vector3DToString(item.Position)));
129+
Communication.SendPrivateInformation(userId, string.Format("Waypoint added: '{0}' at {1}", item.Name, General.Vector3DToString(item.Position)));
133130
}
134131
return true;
135132
}

EssentialsPlugin/ChatHandlers/Waypoints/HandleWaypointFactionAdd.cs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,9 @@ public override bool IsClientOnly()
4343
public override bool HandleCommand(ulong userId, string[] words)
4444
{
4545
if (!PluginSettings.Instance.WaypointsEnabled)
46-
if (!PluginSettings.Instance.WaypointsEnabled)
4746
return false;
48-
49-
string[] splits = General.SplitString(string.Join(" ", words));
5047

51-
if (splits.Length != 6 && splits.Length != 7 && splits.Length != 1)
48+
if (words.Length != 6 && words.Length != 7 && words.Length != 1)
5249
{
5350
Communication.SendPrivateInformation(userId, GetHelp());
5451
return true;
@@ -70,7 +67,7 @@ public override bool HandleCommand(ulong userId, string[] words)
7067
return true;
7168
}
7269

73-
if (splits.Length == 1)
70+
if (words.Length == 1)
7471
{
7572
IMyEntity playerEntity = Player.FindControlledEntity(playerId);
7673
if(playerEntity == null)
@@ -80,13 +77,13 @@ public override bool HandleCommand(ulong userId, string[] words)
8077
}
8178

8279
Vector3D pos = playerEntity.GetPosition();
83-
string name = splits[0];
80+
string name = words[0];
8481

8582
foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers)
8683
{
8784
if (Player.CheckPlayerSameFaction(userId, steamId))
8885
{
89-
Communication.SendClientMessage(steamId, string.Format("/waypoint add \"{0}\" \"{0}\" Neutral {1} {2} {3}", name, Math.Floor(pos.X), Math.Floor(pos.Y), Math.Floor(pos.Z)));
86+
Communication.SendClientMessage(steamId, string.Format("/waypoint add '{0}' '{0}' Neutral {1} {2} {3}", name, Math.Floor(pos.X), Math.Floor(pos.Y), Math.Floor(pos.Z)));
9087
}
9188
}
9289

@@ -101,21 +98,21 @@ public override bool HandleCommand(ulong userId, string[] words)
10198
};
10299
Waypoints.Instance.Add(item);
103100

104-
Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: {0} at {1} by {2}", item.Name, General.Vector3DToString(item.Position), playerName));
101+
Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: '{0}' at {1} by '{2}'", item.Name, General.Vector3DToString(item.Position), playerName));
105102
}
106103
else
107104
{
108105
for (int r = 3; r < 6; r++)
109106
{
110107
double test;
111-
if (!double.TryParse(splits[r], out test))
108+
if (!double.TryParse(words[r], out test))
112109
{
113-
Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", splits[r]));
110+
Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", words[r]));
114111
return true;
115112
}
116113
}
117114

118-
string add = string.Join( " ", splits.Select( s => s.ToLowerInvariant( ) ) );
115+
string add = string.Join(" ", words.Select(s => s.ToLowerInvariant()));
119116

120117
foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers)
121118
{
@@ -126,24 +123,24 @@ public override bool HandleCommand(ulong userId, string[] words)
126123
}
127124

128125
string group = "";
129-
if (splits.Length == 7)
130-
group = splits[7];
126+
if (words.Length == 7)
127+
group = words[7];
131128

132129
WaypointItem item = new WaypointItem
133130
{
134131
SteamId = (ulong) faction.FactionId,
135-
Name = splits[ 0 ],
136-
Text = splits[ 1 ]
132+
Name = words[0],
133+
Text = words[1]
137134
};
138135
WaypointTypes type;
139-
Enum.TryParse(splits[2], true, out type);
136+
Enum.TryParse(words[2], true, out type);
140137
item.WaypointType = type;
141-
item.Position = new Vector3D(double.Parse(splits[3]), double.Parse(splits[4]), double.Parse(splits[5]));
138+
item.Position = new Vector3D(double.Parse(words[3]), double.Parse(words[4]), double.Parse(words[5]));
142139
item.Group = group;
143140
item.Leader = faction.IsLeader(playerId);
144141
Waypoints.Instance.Add(item);
145142

146-
Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: {0} at {1} by {2}", item.Name, General.Vector3DToString(item.Position), playerName));
143+
Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: '{0}' at {1} by '{2}'", item.Name, General.Vector3DToString(item.Position), playerName));
147144
}
148145
return true;
149146
}

EssentialsPlugin/ChatHandlers/Waypoints/HandleWaypointFactionRemove.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ public override bool HandleCommand(ulong userId, string[] words)
4343
if (!PluginSettings.Instance.WaypointsEnabled)
4444
return false;
4545

46-
string[] splits = General.SplitString(string.Join(" ", words));
47-
48-
if (splits.Count() != 1)
46+
if (words.Count() != 1)
4947
{
5048
Communication.SendPrivateInformation(userId, GetHelp());
5149
return true;
@@ -61,39 +59,29 @@ public override bool HandleCommand(ulong userId, string[] words)
6159
}
6260

6361
List<WaypointItem> items = Waypoints.Instance.Get((ulong)faction.FactionId);
64-
WaypointItem item = items.FirstOrDefault(x => x.Name.ToLower() == splits[0].ToLower());
62+
WaypointItem item = items.FirstOrDefault(x => x.Name.ToLower() == words[0].ToLower());
6563
if (item == null)
6664
{
67-
Communication.SendPrivateInformation(userId, string.Format("You do not have a faction waypoint with the name: {0}", splits[0]));
65+
Communication.SendPrivateInformation(userId, string.Format("You do not have a faction waypoint with the name: {0}", words[0]));
6866
return true;
6967
}
7068

7169
if (item.Leader && !faction.IsLeader(playerId))
7270
{
73-
Communication.SendPrivateInformation(userId, string.Format("You must be a faction leader to remove the waypoint: {0}", splits[0]));
71+
Communication.SendPrivateInformation(userId, string.Format("You must be a faction leader to remove the waypoint: {0}", words[0]));
7472
return true;
7573
}
7674

77-
Waypoints.Instance.Remove((ulong)faction.FactionId, splits[0]);
78-
79-
string remove = "";
80-
foreach (string split in splits)
81-
{
82-
if (remove == "")
83-
remove += split.ToLower();
84-
else
85-
remove += " " + split;
86-
}
87-
75+
Waypoints.Instance.Remove((ulong)faction.FactionId, words[0]);
8876
foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers)
8977
{
9078
if (Player.CheckPlayerSameFaction(userId, steamId))
9179
{
92-
Communication.SendClientMessage(steamId, string.Format("/waypoint remove {0}", remove));
80+
Communication.SendClientMessage(steamId, string.Format("/waypoint remove '{0}'", words[0]));
9381
}
9482
}
9583

96-
Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} has removed the waypoint: {1}", playerName, remove));
84+
Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} has removed the waypoint: '{1}'", playerName, words[0]));
9785
return true;
9886
}
9987
}

EssentialsPlugin/ChatHandlers/Waypoints/HandleWaypointGroupAdd.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,21 @@ public override bool HandleCommand(ulong userId, string[] words)
4242
{
4343
if (!PluginSettings.Instance.WaypointsEnabled)
4444
return false;
45-
46-
string[] splits = General.SplitString(string.Join(" ", words));
4745

48-
if (splits.Length != 2)
46+
if (words.Length != 2)
4947
{
5048
Communication.SendPrivateInformation(userId, GetHelp());
5149
return true;
5250
}
5351

54-
string name = splits[0];
55-
string group = splits[1];
52+
string name = words[0];
53+
string group = words[1];
5654

5755
List<WaypointItem> items = Waypoints.Instance.Get(userId);
58-
WaypointItem item = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);
56+
WaypointItem item = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);
5957
if (item != null)
6058
{
61-
if (Waypoints.Instance.GroupAdd(userId, splits[0], splits[1]))
59+
if (Waypoints.Instance.GroupAdd(userId, words[0], words[1]))
6260
Communication.SendPrivateInformation(userId, string.Format("Waypoint '{0}' added to the group '{1}'", name, group));
6361
else
6462
Communication.SendPrivateInformation(userId, string.Format("Failed to add waypoint '{0}' to the group '{1}'", name, group));
@@ -72,7 +70,7 @@ public override bool HandleCommand(ulong userId, string[] words)
7270
if (faction != null)
7371
{
7472
items = Waypoints.Instance.Get((ulong)faction.FactionId);
75-
item = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);
73+
item = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);
7674

7775
if (item != null)
7876
{
@@ -82,7 +80,7 @@ public override bool HandleCommand(ulong userId, string[] words)
8280
return true;
8381
}
8482

85-
if (Waypoints.Instance.GroupAdd((ulong)faction.FactionId, splits[0], splits[1]))
83+
if (Waypoints.Instance.GroupAdd((ulong)faction.FactionId, words[0], words[1]))
8684
Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} added the waypoint '{1}' to the group '{2}'", playerName, name, group));
8785
else
8886
Communication.SendPrivateInformation(userId, string.Format("Failed to add faction waypoint '{0}' to the group '{1}'", name, group));

EssentialsPlugin/ChatHandlers/Waypoints/HandleWaypointGroupRemove.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,17 @@ public override bool HandleCommand(ulong userId, string[] words)
4242
{
4343
if (!PluginSettings.Instance.WaypointsEnabled)
4444
return false;
45-
46-
string[] splits = General.SplitString(string.Join(" ", words));
4745

48-
if (splits.Length != 1)
46+
if (words.Length != 1)
4947
{
5048
Communication.SendPrivateInformation(userId, GetHelp());
5149
return true;
5250
}
5351

54-
string name = splits[0];
52+
string name = words[0];
5553

5654
List<WaypointItem> items = Waypoints.Instance.Get(userId);
57-
WaypointItem item = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);
55+
WaypointItem item = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);
5856
if (item != null)
5957
{
6058
if (Waypoints.Instance.GroupRemove(userId, name))
@@ -71,7 +69,7 @@ public override bool HandleCommand(ulong userId, string[] words)
7169
if (faction != null)
7270
{
7371
items = Waypoints.Instance.Get((ulong)faction.FactionId);
74-
item = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);
72+
item = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);
7573

7674
if (item != null)
7775
{

0 commit comments

Comments
 (0)