Second batch of command code cleanups.

This commit is contained in:
UnknownShadow200 2016-03-29 18:20:52 +11:00
parent 2b68b93aba
commit ef8c7b57a1
8 changed files with 66 additions and 74 deletions

View File

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

View File

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

View File

@ -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; }

View File

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

View File

@ -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<string> foundPeople = new List<string>();
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<string> alts = new List<string>();
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 <name> - Finds everyone with the same IP as <name>");
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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) {