From 60156af877d585906b612c12fb5fc23aa87b623a Mon Sep 17 00:00:00 2001 From: Deathmax Date: Fri, 3 Jun 2011 19:51:43 +0800 Subject: [PATCH] FindPlayer now has partial matches. --- TShockAPI/Commands.cs | 8 ++++++-- TShockAPI/Tools.cs | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 57217799..df697519 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -64,7 +64,7 @@ namespace TShockAPI { string plStr = args.Message.Remove(0, 5).Trim(); int ply = args.PlayerID; - if (!(Tools.FindPlayer(plStr) == -1 || plStr == "")) + if (!(Tools.FindPlayer(plStr) == -1 || Tools.FindPlayer(plStr) == -2 || plStr == "")) { if (!TShock.players[Tools.FindPlayer(plStr)].IsAdmin()) { @@ -74,6 +74,8 @@ namespace TShockAPI else Tools.SendMessage(ply, "You can't kick another admin!", new float[] { 255f, 0f, 0f }); } + else if (Tools.FindPlayer(plStr) == -2) + Tools.SendMessage(ply, "More than one player matched!", new float[] { 255f, 0f, 0f }); else Tools.SendMessage(ply, "Invalid player!", new float[] { 255f, 0f, 0f }); } @@ -82,7 +84,7 @@ namespace TShockAPI { string plStr = args.Message.Remove(0, 4).Trim(); int ply = args.PlayerID; - if (!(Tools.FindPlayer(plStr) == -1 || plStr == "")) + if (!(Tools.FindPlayer(plStr) == -1 || Tools.FindPlayer(plStr) == -2 || plStr == "")) { if (!TShock.players[Tools.FindPlayer(plStr)].IsAdmin()) { @@ -92,6 +94,8 @@ namespace TShockAPI else Tools.SendMessage(ply, "You can't ban another admin!", new float[] { 255f, 0f, 0f }); } + else if (Tools.FindPlayer(plStr) == -2) + Tools.SendMessage(ply, "More than one player matched!", new float[] { 255f, 0f, 0f }); else Tools.SendMessage(ply, "Invalid player!", new float[] { 255f, 0f, 0f }); } diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index 653155c2..d1852618 100644 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -1,6 +1,7 @@ using System; using System.IO; using Terraria; +using System.Collections.Generic; namespace TShockAPI { @@ -116,7 +117,7 @@ namespace TShockAPI /// int player public static int FindPlayer(string ply) { - int pl = -1; + /*int pl = -1; for (int i = 0; i < Main.player.Length; i++) { if ((ply.ToLower()) == Main.player[i].name.ToLower()) @@ -125,7 +126,17 @@ namespace TShockAPI break; } } - return pl; + return pl;*/ + List found = new List(); + for (int i = 0; i < Main.player.Length; i++) + if (Main.player[i].name.ToLower().Contains(ply.ToLower())) + found.Add(i); + if (found.Count == 1) + return found[0]; + else if (found.Count > 1) + return -2; + else + return -1; } ///