Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions EssentialsPlugin/ChatHandlers/Admin/HandleAdminTurrets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public override bool AllowedInConsole()

public override bool HandleCommand(ulong userId, string[] words)
{
string[] splits = General.SplitString(string.Join(" ", words));
if (splits.Length != 1)
if (words.Length != 1)
{
Communication.SendPrivateInformation(userId, GetHelp());
return true;
Expand Down Expand Up @@ -82,7 +81,7 @@ public override bool HandleCommand(ulong userId, string[] words)
IMyEntity turret = block.FatBlock;
bool state = FunctionalBlockEntity.GetState(turret);

if(splits[0].ToLower() == "toggle")
if (words[0].ToLower() == "toggle")
FunctionalBlockEntity.SetState(turret, !state);

count++;
Expand All @@ -92,7 +91,7 @@ public override bool HandleCommand(ulong userId, string[] words)
else
disabled++;

if (splits[0].ToLower() == "test" && state)
if (words[0].ToLower() == "test" && state)
{
BoundingSphereD sphere = new BoundingSphereD(grid.GetPosition(), 2000);
List<IMyEntity> testEntities = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
Expand Down
5 changes: 2 additions & 3 deletions EssentialsPlugin/ChatHandlers/HandleLastSeen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ public override bool AllowedInConsole()

public override bool HandleCommand(ulong userId, string[] words)
{
string[] splits = General.SplitString(string.Join(" ", words));
if (splits.Count() != 1)
if (words.Count() != 1)
{
Communication.SendPrivateInformation(userId, GetHelp());
return true;
}

string userName = splits[0];
string userName = words[0];
ulong steamId = PlayerMap.Instance.GetSteamIdFromPlayerName(userName, true);
if (steamId == 0)
{
Expand Down
41 changes: 19 additions & 22 deletions EssentialsPlugin/ChatHandlers/Waypoints/HandleWaypointAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ public override bool IsClientOnly()
public override bool HandleCommand(ulong userId, string[] words)
{
if (!PluginSettings.Instance.WaypointsEnabled)
if (!PluginSettings.Instance.WaypointsEnabled)
return false;

string[] splits = General.SplitString(string.Join(" ", words));

if (splits.Length != 6 && splits.Length != 7 && splits.Length != 5 && splits.Length != 1)
if (words.Length != 1 && words.Length != 5 && words.Length != 6 && words.Length != 7)
{
Communication.SendPrivateInformation(userId, GetHelp());
return true;
Expand All @@ -60,7 +57,7 @@ public override bool HandleCommand(ulong userId, string[] words)
return true;
}

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

Vector3D pos = playerEntity.GetPosition();
string name = splits[0];
string name = words[0];

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)));
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)));

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

Communication.SendPrivateInformation(userId, string.Format("Waypoint added: {0} at {1}", item.Name, General.Vector3DToString(item.Position)));
Communication.SendPrivateInformation(userId, string.Format("Waypoint added: '{0}' at {1}", item.Name, General.Vector3DToString(item.Position)));
}
else
{
int len = 5;
if (splits.Length > 5)
if (words.Length > 5)
len = 6;

for (int r = len - 3; r < len; r++)
{
double test = 0d;
if (!double.TryParse(splits[r], out test))
if (!double.TryParse(words[r], out test))
{
Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", splits[r]));
Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", words[r]));
return true;
}
}

string add = "";
foreach (string split in splits)
foreach (string word in words)
{
if (add == "")
add += split.ToLower();
add += word.ToLower();
else
add += " " + split;
add += " " + word;
}

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

string group = "";
if (splits.Length == 7)
group = splits[7];
if (words.Length == 7)
group = words[7];

WaypointItem item = new WaypointItem();
item.SteamId = userId;
item.Name = splits[0];
item.Name = words[0];

int diff = splits.Length > 5 ? 1 : 0;
item.Text = splits[diff];
int diff = words.Length > 5 ? 1 : 0;
item.Text = words[diff];
WaypointTypes type = WaypointTypes.Neutral;
Enum.TryParse<WaypointTypes>(splits[diff + 1], true, out type);
Enum.TryParse<WaypointTypes>(words[diff + 1], true, out type);
item.WaypointType = type;
item.Position = new Vector3D(double.Parse(splits[diff + 2]), double.Parse(splits[diff + 3]), double.Parse(splits[diff + 4]));
item.Position = new Vector3D(double.Parse(words[diff + 2]), double.Parse(words[diff + 3]), double.Parse(words[diff + 4]));
item.Group = group;
Waypoints.Instance.Add(item);

Communication.SendPrivateInformation(userId, string.Format("Waypoint added: {0} at {1}", item.Name, General.Vector3DToString(item.Position)));
Communication.SendPrivateInformation(userId, string.Format("Waypoint added: '{0}' at {1}", item.Name, General.Vector3DToString(item.Position)));
}
return true;
}
Expand Down
33 changes: 15 additions & 18 deletions EssentialsPlugin/ChatHandlers/Waypoints/HandleWaypointFactionAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ public override bool IsClientOnly()
public override bool HandleCommand(ulong userId, string[] words)
{
if (!PluginSettings.Instance.WaypointsEnabled)
if (!PluginSettings.Instance.WaypointsEnabled)
return false;

string[] splits = General.SplitString(string.Join(" ", words));

if (splits.Length != 6 && splits.Length != 7 && splits.Length != 1)
if (words.Length != 6 && words.Length != 7 && words.Length != 1)
{
Communication.SendPrivateInformation(userId, GetHelp());
return true;
Expand All @@ -70,7 +67,7 @@ public override bool HandleCommand(ulong userId, string[] words)
return true;
}

if (splits.Length == 1)
if (words.Length == 1)
{
IMyEntity playerEntity = Player.FindControlledEntity(playerId);
if(playerEntity == null)
Expand All @@ -80,13 +77,13 @@ public override bool HandleCommand(ulong userId, string[] words)
}

Vector3D pos = playerEntity.GetPosition();
string name = splits[0];
string name = words[0];

foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers)
{
if (Player.CheckPlayerSameFaction(userId, steamId))
{
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)));
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)));
}
}

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

Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: {0} at {1} by {2}", item.Name, General.Vector3DToString(item.Position), playerName));
Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: '{0}' at {1} by '{2}'", item.Name, General.Vector3DToString(item.Position), playerName));
}
else
{
for (int r = 3; r < 6; r++)
{
double test;
if (!double.TryParse(splits[r], out test))
if (!double.TryParse(words[r], out test))
{
Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", splits[r]));
Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", words[r]));
return true;
}
}

string add = string.Join( " ", splits.Select( s => s.ToLowerInvariant( ) ) );
string add = string.Join(" ", words.Select(s => s.ToLowerInvariant()));

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

string group = "";
if (splits.Length == 7)
group = splits[7];
if (words.Length == 7)
group = words[7];

WaypointItem item = new WaypointItem
{
SteamId = (ulong) faction.FactionId,
Name = splits[ 0 ],
Text = splits[ 1 ]
Name = words[0],
Text = words[1]
};
WaypointTypes type;
Enum.TryParse(splits[2], true, out type);
Enum.TryParse(words[2], true, out type);
item.WaypointType = type;
item.Position = new Vector3D(double.Parse(splits[3]), double.Parse(splits[4]), double.Parse(splits[5]));
item.Position = new Vector3D(double.Parse(words[3]), double.Parse(words[4]), double.Parse(words[5]));
item.Group = group;
item.Leader = faction.IsLeader(playerId);
Waypoints.Instance.Add(item);

Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: {0} at {1} by {2}", item.Name, General.Vector3DToString(item.Position), playerName));
Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: '{0}' at {1} by '{2}'", item.Name, General.Vector3DToString(item.Position), playerName));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public override bool HandleCommand(ulong userId, string[] words)
if (!PluginSettings.Instance.WaypointsEnabled)
return false;

string[] splits = General.SplitString(string.Join(" ", words));

if (splits.Count() != 1)
if (words.Count() != 1)
{
Communication.SendPrivateInformation(userId, GetHelp());
return true;
Expand All @@ -61,39 +59,29 @@ public override bool HandleCommand(ulong userId, string[] words)
}

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

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

Waypoints.Instance.Remove((ulong)faction.FactionId, splits[0]);

string remove = "";
foreach (string split in splits)
{
if (remove == "")
remove += split.ToLower();
else
remove += " " + split;
}

Waypoints.Instance.Remove((ulong)faction.FactionId, words[0]);
foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers)
{
if (Player.CheckPlayerSameFaction(userId, steamId))
{
Communication.SendClientMessage(steamId, string.Format("/waypoint remove {0}", remove));
Communication.SendClientMessage(steamId, string.Format("/waypoint remove '{0}'", words[0]));
}
}

Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} has removed the waypoint: {1}", playerName, remove));
Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} has removed the waypoint: '{1}'", playerName, words[0]));
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,21 @@ public override bool HandleCommand(ulong userId, string[] words)
{
if (!PluginSettings.Instance.WaypointsEnabled)
return false;

string[] splits = General.SplitString(string.Join(" ", words));

if (splits.Length != 2)
if (words.Length != 2)
{
Communication.SendPrivateInformation(userId, GetHelp());
return true;
}

string name = splits[0];
string group = splits[1];
string name = words[0];
string group = words[1];

List<WaypointItem> items = Waypoints.Instance.Get(userId);
WaypointItem item = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);
WaypointItem item = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);
if (item != null)
{
if (Waypoints.Instance.GroupAdd(userId, splits[0], splits[1]))
if (Waypoints.Instance.GroupAdd(userId, words[0], words[1]))
Communication.SendPrivateInformation(userId, string.Format("Waypoint '{0}' added to the group '{1}'", name, group));
else
Communication.SendPrivateInformation(userId, string.Format("Failed to add waypoint '{0}' to the group '{1}'", name, group));
Expand All @@ -72,7 +70,7 @@ public override bool HandleCommand(ulong userId, string[] words)
if (faction != null)
{
items = Waypoints.Instance.Get((ulong)faction.FactionId);
item = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);
item = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);

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

if (Waypoints.Instance.GroupAdd((ulong)faction.FactionId, splits[0], splits[1]))
if (Waypoints.Instance.GroupAdd((ulong)faction.FactionId, words[0], words[1]))
Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} added the waypoint '{1}' to the group '{2}'", playerName, name, group));
else
Communication.SendPrivateInformation(userId, string.Format("Failed to add faction waypoint '{0}' to the group '{1}'", name, group));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@ public override bool HandleCommand(ulong userId, string[] words)
{
if (!PluginSettings.Instance.WaypointsEnabled)
return false;

string[] splits = General.SplitString(string.Join(" ", words));

if (splits.Length != 1)
if (words.Length != 1)
{
Communication.SendPrivateInformation(userId, GetHelp());
return true;
}

string name = splits[0];
string name = words[0];

List<WaypointItem> items = Waypoints.Instance.Get(userId);
WaypointItem item = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);
WaypointItem item = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);
if (item != null)
{
if (Waypoints.Instance.GroupRemove(userId, name))
Expand All @@ -71,7 +69,7 @@ public override bool HandleCommand(ulong userId, string[] words)
if (faction != null)
{
items = Waypoints.Instance.Get((ulong)faction.FactionId);
item = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);
item = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);

if (item != null)
{
Expand Down
Loading