diff --git a/API/WhoWas.cs b/API/WhoWas.cs index 004a7db29..a9b1d4d06 100644 --- a/API/WhoWas.cs +++ b/API/WhoWas.cs @@ -1,14 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Text; -using MCGalaxy.SQL; +using System; +using System.Data; +using System.Linq; +using MCGalaxy.SQL; -namespace MCGalaxy -{ - public class WhoWas - { +namespace MCGalaxy { + public class WhoWas { public string rank { get; set; } public int modified_blocks { get; set; } public string time { get; set; } @@ -21,21 +17,17 @@ namespace MCGalaxy public string banned_time { get; set; } public int kicks { get; set; } - public WhoWas(string p) - { - Server.s.Log(p); + public WhoWas(string p) { rank = Group.findPlayer(p); - ParameterisedQuery query = ParameterisedQuery.Create(); - query.AddParam("@Name", p.ToLower()); - DataTable playerDb = Database.fillData(query, "SELECT * FROM Players WHERE Name=@Name COLLATE NOCASE"); - if (playerDb.Rows.Count == 0) - return; - modified_blocks = int.Parse(playerDb.Rows[0]["totalBlocks"].ToString()); - time = playerDb.Rows[0]["TimeSpent"].ToString(); - first_login = playerDb.Rows[0]["FirstLogin"].ToString(); - last_login = playerDb.Rows[0]["LastLogin"].ToString(); - total_logins = int.Parse(playerDb.Rows[0]["totalLogin"].ToString()); - kicks = int.Parse(playerDb.Rows[0]["totalKicked"].ToString()); + OfflinePlayer pl = PlayerInfo.FindOffline(p, true); + if (pl == null) return; + + modified_blocks = int.Parse(pl.blocks); + time = pl.totalTime; + first_login = pl.firstLogin; + last_login = pl.lastLogin; + total_logins = int.Parse(pl.logins); + kicks = int.Parse(pl.kicks); } } } \ No newline at end of file diff --git a/Commands/Economy/CmdGive.cs b/Commands/Economy/CmdGive.cs index 78a8c68a2..77e01cb98 100644 --- a/Commands/Economy/CmdGive.cs +++ b/Commands/Economy/CmdGive.cs @@ -31,7 +31,6 @@ namespace MCGalaxy.Commands public override void Use(Player p, string message) { string[] args = message.Split(' '); if (args.Length != 2) { Help(p); return; } - string giver = null, giverRaw = null; if (p == null) { giverRaw = "(console)"; giver = "(console)"; } else { giverRaw = p.color + p.name; giver = p.FullName; } @@ -41,7 +40,10 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "Amount must be an integer."); return; } if (amount < 0) { Player.SendMessage(p, "Cannot give negative %3" + Server.moneys); return; } - Player who = PlayerInfo.Find(args[0]); + + int matches = 1; + Player who = PlayerInfo.FindOrShowMatches(p, args[0], out matches); + if (matches > 1) return; if (p != null && p == who) { Player.SendMessage(p, "You cannot give yourself %3" + Server.moneys); return; } Economy.EcoStats ecos; diff --git a/Commands/Economy/CmdPay.cs b/Commands/Economy/CmdPay.cs index 64932dfa5..d0fca8eb2 100644 --- a/Commands/Economy/CmdPay.cs +++ b/Commands/Economy/CmdPay.cs @@ -28,22 +28,20 @@ namespace MCGalaxy.Commands public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } public CmdPay() { } - public override void Use(Player p, string message) - { + public override void Use(Player p, string message) { string[] args = message.Split(' '); if (args.Length != 2) { Help(p); return; } - Player who = PlayerInfo.Find(args[0]); - Economy.EcoStats payer; - Economy.EcoStats receiver; - int amount; - if (!int.TryParse(args[1], out amount)) { - Player.SendMessage(p, "Amount must be an integer."); return; - } + if (!int.TryParse(args[1], out amount)) { Player.SendMessage(p, "Amount must be an integer."); return; } if (amount < 0) { Player.SendMessage(p, "Cannot pay negative %3" + Server.moneys); return; } + + int matches = 1; + Player who = PlayerInfo.FindOrShowMatches(p, args[0], out matches); + if (matches > 1) return; if (p != null && p == who) { Player.SendMessage(p, "You cannot pay yourself %3" + Server.moneys); return; } string target = null; - + Economy.EcoStats payer, receiver; + if (who == null) { OfflinePlayer off = PlayerInfo.FindOffline(args[0]); if (off == null) { Player.SendMessage(p, "The player \"&a" + args[0] + "%S\" was not found at all."); return; } diff --git a/Commands/Economy/CmdTake.cs b/Commands/Economy/CmdTake.cs index fd9e5e253..fffb23e52 100644 --- a/Commands/Economy/CmdTake.cs +++ b/Commands/Economy/CmdTake.cs @@ -42,7 +42,10 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "Amount must be an integer."); return; } if (amount < 0) { Player.SendMessage(p, "%cYou can't take negative %3" + Server.moneys); return; } - Player who = PlayerInfo.Find(args[0]); + + int matches = 1; + Player who = PlayerInfo.FindOrShowMatches(p, args[0], out matches); + if (matches > 1) return; if (p != null && p == who) { Player.SendMessage(p, "%cYou can't take %3" + Server.moneys + "%c from yourself"); return; } Economy.EcoStats ecos; diff --git a/Commands/Information/CmdClones.cs b/Commands/Information/CmdClones.cs index bc0e0de85..3141df101 100644 --- a/Commands/Information/CmdClones.cs +++ b/Commands/Information/CmdClones.cs @@ -55,22 +55,21 @@ namespace MCGalaxy.Commands if (Clones.Rows.Count == 0) { Player.SendMessage(p, "Could not find any record of the player entered."); return; } - List foundPeople = new List(); - for (int i = 0; i < Clones.Rows.Count; ++i) - { - if (!foundPeople.Contains(Clones.Rows[i]["Name"].ToString().ToLower())) - foundPeople.Add(Clones.Rows[i]["Name"].ToString().ToLower()); + List alts = new List(); + for (int i = 0; i < Clones.Rows.Count; ++i) { + string name = Clones.Rows[i]["Name"].ToString(); + if (!alts.Contains(name.ToLower())) + alts.Add(name.ToLower()); } Clones.Dispose(); - if (foundPeople.Count <= 1) { Player.SendMessage(p, originalName + " has no clones."); return; } + if (alts.Count <= 1) { Player.SendMessage(p, originalName + " has no clones."); return; } - Player.SendMessage(p, "These people have the same IP address:"); - Player.SendMessage(p, string.Join(", ", foundPeople.ToArray())); + Player.SendMessage(p, "These players have the same IP address:"); + Player.SendMessage(p, string.Join(", ", alts.ToArray())); } - public override void Help(Player p) - { + public override void Help(Player p) { Player.SendMessage(p, "/clones - Finds everyone with the same IP as "); } } diff --git a/Commands/other/CmdTp.cs b/Commands/other/CmdTp.cs index 68d7a8eba..5914bd534 100644 --- a/Commands/other/CmdTp.cs +++ b/Commands/other/CmdTp.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands { Player target = PlayerInfo.FindOrShowMatches(p, message); if (target == null) return; - if (target.level.name.Contains("cMuseum")) { + if (target.level.IsMuseum) { Player.SendMessage(p, "Player \"" + message + "\" is in a museum!"); return; } diff --git a/Commands/other/CmdTpA.cs b/Commands/other/CmdTpA.cs index d6a395795..ea58633ad 100644 --- a/Commands/other/CmdTpA.cs +++ b/Commands/other/CmdTpA.cs @@ -32,7 +32,7 @@ namespace MCGalaxy.Commands { return; } if (who.name == p.currentTpa) { Player.SendMessage(p, "&cError:" + Server.DefaultColor + " You already have a pending request with this player."); return; } - if (p.level != who.level && who.level.name.Contains("cMuseum")) { + if (p.level != who.level && who.level.IsMuseum) { Player.SendMessage(p, "Player \"" + who.color + who.DisplayName + "\" is in a museum!"); return; } diff --git a/Player/PlayerInfo.cs b/Player/PlayerInfo.cs index 2c0cbdc3d..3e02d7208 100644 --- a/Player/PlayerInfo.cs +++ b/Player/PlayerInfo.cs @@ -162,37 +162,35 @@ namespace MCGalaxy { p.totalKicked = int.Parse(row["totalKicked"].ToString()); } - public static OfflinePlayer FindOffline(string name, bool fullStats = false) { - OfflinePlayer pl = new OfflinePlayer(); + public static OfflinePlayer FindOffline(string name, bool fullStats = false) { ParameterisedQuery query = ParameterisedQuery.Create(); query.AddParam("@Name", name); string syntax = Server.useMySQL ? "SELECT * FROM Players WHERE Name=@Name COLLATE utf8_general_ci" : "SELECT * FROM Players WHERE Name=@Name COLLATE NOCASE"; using (DataTable playerDB = Database.fillData(query, syntax)) { - if (playerDB.Rows.Count == 0) { - return null; - } else { - DataRow row = playerDB.Rows[0]; - pl.name = row["Name"].ToString().Trim(); - pl.ip = row["IP"].ToString().Trim(); - - pl.totalTime = row["TimeSpent"].ToString(); - pl.firstLogin = row["FirstLogin"].ToString(); - pl.lastLogin = row["LastLogin"].ToString(); - if (!fullStats) return pl; - - pl.title = row["Title"].ToString().Trim(); - pl.titleColor = Colors.Parse(row["title_color"].ToString().Trim()); - pl.color = Colors.Parse(row["color"].ToString().Trim()); - - pl.money = row["Money"].ToString(); - pl.deaths = row["TotalDeaths"].ToString(); - pl.blocks = row["totalBlocks"].ToString(); - pl.logins = row["totalLogin"].ToString(); - pl.kicks = row["totalKicked"].ToString(); - } + if (playerDB.Rows.Count == 0) return null; + + OfflinePlayer pl = new OfflinePlayer(); + DataRow row = playerDB.Rows[0]; + pl.name = row["Name"].ToString().Trim(); + pl.ip = row["IP"].ToString().Trim(); + + pl.totalTime = row["TimeSpent"].ToString(); + pl.firstLogin = row["FirstLogin"].ToString(); + pl.lastLogin = row["LastLogin"].ToString(); + if (!fullStats) return pl; + + pl.title = row["Title"].ToString().Trim(); + pl.titleColor = Colors.Parse(row["title_color"].ToString().Trim()); + pl.color = Colors.Parse(row["color"].ToString().Trim()); + + pl.money = row["Money"].ToString(); + pl.deaths = row["TotalDeaths"].ToString(); + pl.blocks = row["totalBlocks"].ToString(); + pl.logins = row["totalLogin"].ToString(); + pl.kicks = row["totalKicked"].ToString(); + return pl; } - return pl; } public static string FindOfflineName(string name) {