mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-29 00:26:15 -04:00
Second batch of command code cleanups.
This commit is contained in:
parent
2b68b93aba
commit
ef8c7b57a1
@ -1,14 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Data;
|
||||||
using System.Data;
|
using System.Linq;
|
||||||
using System.Linq;
|
using MCGalaxy.SQL;
|
||||||
using System.Text;
|
|
||||||
using MCGalaxy.SQL;
|
|
||||||
|
|
||||||
namespace MCGalaxy
|
namespace MCGalaxy {
|
||||||
{
|
public class WhoWas {
|
||||||
public class WhoWas
|
|
||||||
{
|
|
||||||
public string rank { get; set; }
|
public string rank { get; set; }
|
||||||
public int modified_blocks { get; set; }
|
public int modified_blocks { get; set; }
|
||||||
public string time { get; set; }
|
public string time { get; set; }
|
||||||
@ -21,21 +17,17 @@ namespace MCGalaxy
|
|||||||
public string banned_time { get; set; }
|
public string banned_time { get; set; }
|
||||||
public int kicks { get; set; }
|
public int kicks { get; set; }
|
||||||
|
|
||||||
public WhoWas(string p)
|
public WhoWas(string p) {
|
||||||
{
|
|
||||||
Server.s.Log(p);
|
|
||||||
rank = Group.findPlayer(p);
|
rank = Group.findPlayer(p);
|
||||||
ParameterisedQuery query = ParameterisedQuery.Create();
|
OfflinePlayer pl = PlayerInfo.FindOffline(p, true);
|
||||||
query.AddParam("@Name", p.ToLower());
|
if (pl == null) return;
|
||||||
DataTable playerDb = Database.fillData(query, "SELECT * FROM Players WHERE Name=@Name COLLATE NOCASE");
|
|
||||||
if (playerDb.Rows.Count == 0)
|
modified_blocks = int.Parse(pl.blocks);
|
||||||
return;
|
time = pl.totalTime;
|
||||||
modified_blocks = int.Parse(playerDb.Rows[0]["totalBlocks"].ToString());
|
first_login = pl.firstLogin;
|
||||||
time = playerDb.Rows[0]["TimeSpent"].ToString();
|
last_login = pl.lastLogin;
|
||||||
first_login = playerDb.Rows[0]["FirstLogin"].ToString();
|
total_logins = int.Parse(pl.logins);
|
||||||
last_login = playerDb.Rows[0]["LastLogin"].ToString();
|
kicks = int.Parse(pl.kicks);
|
||||||
total_logins = int.Parse(playerDb.Rows[0]["totalLogin"].ToString());
|
|
||||||
kicks = int.Parse(playerDb.Rows[0]["totalKicked"].ToString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,7 +31,6 @@ namespace MCGalaxy.Commands
|
|||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
string[] args = message.Split(' ');
|
string[] args = message.Split(' ');
|
||||||
if (args.Length != 2) { Help(p); return; }
|
if (args.Length != 2) { Help(p); return; }
|
||||||
|
|
||||||
string giver = null, giverRaw = null;
|
string giver = null, giverRaw = null;
|
||||||
if (p == null) { giverRaw = "(console)"; giver = "(console)"; }
|
if (p == null) { giverRaw = "(console)"; giver = "(console)"; }
|
||||||
else { giverRaw = p.color + p.name; giver = p.FullName; }
|
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;
|
Player.SendMessage(p, "Amount must be an integer."); return;
|
||||||
}
|
}
|
||||||
if (amount < 0) { Player.SendMessage(p, "Cannot give negative %3" + Server.moneys); 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; }
|
if (p != null && p == who) { Player.SendMessage(p, "You cannot give yourself %3" + Server.moneys); return; }
|
||||||
Economy.EcoStats ecos;
|
Economy.EcoStats ecos;
|
||||||
|
|
||||||
|
@ -28,22 +28,20 @@ namespace MCGalaxy.Commands
|
|||||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||||
public CmdPay() { }
|
public CmdPay() { }
|
||||||
|
|
||||||
public override void Use(Player p, string message)
|
public override void Use(Player p, string message) {
|
||||||
{
|
|
||||||
string[] args = message.Split(' ');
|
string[] args = message.Split(' ');
|
||||||
if (args.Length != 2) { Help(p); return; }
|
if (args.Length != 2) { Help(p); return; }
|
||||||
Player who = PlayerInfo.Find(args[0]);
|
|
||||||
Economy.EcoStats payer;
|
|
||||||
Economy.EcoStats receiver;
|
|
||||||
|
|
||||||
int amount;
|
int amount;
|
||||||
if (!int.TryParse(args[1], out amount)) {
|
if (!int.TryParse(args[1], out amount)) { Player.SendMessage(p, "Amount must be an integer."); return; }
|
||||||
Player.SendMessage(p, "Amount must be an integer."); return;
|
|
||||||
}
|
|
||||||
if (amount < 0) { Player.SendMessage(p, "Cannot pay negative %3" + Server.moneys); 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; }
|
if (p != null && p == who) { Player.SendMessage(p, "You cannot pay yourself %3" + Server.moneys); return; }
|
||||||
string target = null;
|
string target = null;
|
||||||
|
Economy.EcoStats payer, receiver;
|
||||||
|
|
||||||
if (who == null) {
|
if (who == null) {
|
||||||
OfflinePlayer off = PlayerInfo.FindOffline(args[0]);
|
OfflinePlayer off = PlayerInfo.FindOffline(args[0]);
|
||||||
if (off == null) { Player.SendMessage(p, "The player \"&a" + args[0] + "%S\" was not found at all."); return; }
|
if (off == null) { Player.SendMessage(p, "The player \"&a" + args[0] + "%S\" was not found at all."); return; }
|
||||||
|
@ -42,7 +42,10 @@ namespace MCGalaxy.Commands
|
|||||||
Player.SendMessage(p, "Amount must be an integer."); return;
|
Player.SendMessage(p, "Amount must be an integer."); return;
|
||||||
}
|
}
|
||||||
if (amount < 0) { Player.SendMessage(p, "%cYou can't take negative %3" + Server.moneys); 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; }
|
if (p != null && p == who) { Player.SendMessage(p, "%cYou can't take %3" + Server.moneys + "%c from yourself"); return; }
|
||||||
|
|
||||||
Economy.EcoStats ecos;
|
Economy.EcoStats ecos;
|
||||||
|
@ -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; }
|
if (Clones.Rows.Count == 0) { Player.SendMessage(p, "Could not find any record of the player entered."); return; }
|
||||||
|
|
||||||
List<string> foundPeople = new List<string>();
|
List<string> alts = new List<string>();
|
||||||
for (int i = 0; i < Clones.Rows.Count; ++i)
|
for (int i = 0; i < Clones.Rows.Count; ++i) {
|
||||||
{
|
string name = Clones.Rows[i]["Name"].ToString();
|
||||||
if (!foundPeople.Contains(Clones.Rows[i]["Name"].ToString().ToLower()))
|
if (!alts.Contains(name.ToLower()))
|
||||||
foundPeople.Add(Clones.Rows[i]["Name"].ToString().ToLower());
|
alts.Add(name.ToLower());
|
||||||
}
|
}
|
||||||
|
|
||||||
Clones.Dispose();
|
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, "These players have the same IP address:");
|
||||||
Player.SendMessage(p, string.Join(", ", foundPeople.ToArray()));
|
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>");
|
Player.SendMessage(p, "/clones <name> - Finds everyone with the same IP as <name>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ namespace MCGalaxy.Commands {
|
|||||||
|
|
||||||
Player target = PlayerInfo.FindOrShowMatches(p, message);
|
Player target = PlayerInfo.FindOrShowMatches(p, message);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
if (target.level.name.Contains("cMuseum")) {
|
if (target.level.IsMuseum) {
|
||||||
Player.SendMessage(p, "Player \"" + message + "\" is in a museum!"); return;
|
Player.SendMessage(p, "Player \"" + message + "\" is in a museum!"); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ namespace MCGalaxy.Commands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (who.name == p.currentTpa) { Player.SendMessage(p, "&cError:" + Server.DefaultColor + " You already have a pending request with this player."); 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;
|
Player.SendMessage(p, "Player \"" + who.color + who.DisplayName + "\" is in a museum!"); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,37 +162,35 @@ namespace MCGalaxy {
|
|||||||
p.totalKicked = int.Parse(row["totalKicked"].ToString());
|
p.totalKicked = int.Parse(row["totalKicked"].ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OfflinePlayer FindOffline(string name, bool fullStats = false) {
|
public static OfflinePlayer FindOffline(string name, bool fullStats = false) {
|
||||||
OfflinePlayer pl = new OfflinePlayer();
|
|
||||||
ParameterisedQuery query = ParameterisedQuery.Create();
|
ParameterisedQuery query = ParameterisedQuery.Create();
|
||||||
query.AddParam("@Name", name);
|
query.AddParam("@Name", name);
|
||||||
string syntax = Server.useMySQL ? "SELECT * FROM Players WHERE Name=@Name COLLATE utf8_general_ci" :
|
string syntax = Server.useMySQL ? "SELECT * FROM Players WHERE Name=@Name COLLATE utf8_general_ci" :
|
||||||
"SELECT * FROM Players WHERE Name=@Name COLLATE NOCASE";
|
"SELECT * FROM Players WHERE Name=@Name COLLATE NOCASE";
|
||||||
using (DataTable playerDB = Database.fillData(query, syntax)) {
|
using (DataTable playerDB = Database.fillData(query, syntax)) {
|
||||||
if (playerDB.Rows.Count == 0) {
|
if (playerDB.Rows.Count == 0) return null;
|
||||||
return null;
|
|
||||||
} else {
|
OfflinePlayer pl = new OfflinePlayer();
|
||||||
DataRow row = playerDB.Rows[0];
|
DataRow row = playerDB.Rows[0];
|
||||||
pl.name = row["Name"].ToString().Trim();
|
pl.name = row["Name"].ToString().Trim();
|
||||||
pl.ip = row["IP"].ToString().Trim();
|
pl.ip = row["IP"].ToString().Trim();
|
||||||
|
|
||||||
pl.totalTime = row["TimeSpent"].ToString();
|
pl.totalTime = row["TimeSpent"].ToString();
|
||||||
pl.firstLogin = row["FirstLogin"].ToString();
|
pl.firstLogin = row["FirstLogin"].ToString();
|
||||||
pl.lastLogin = row["LastLogin"].ToString();
|
pl.lastLogin = row["LastLogin"].ToString();
|
||||||
if (!fullStats) return pl;
|
if (!fullStats) return pl;
|
||||||
|
|
||||||
pl.title = row["Title"].ToString().Trim();
|
pl.title = row["Title"].ToString().Trim();
|
||||||
pl.titleColor = Colors.Parse(row["title_color"].ToString().Trim());
|
pl.titleColor = Colors.Parse(row["title_color"].ToString().Trim());
|
||||||
pl.color = Colors.Parse(row["color"].ToString().Trim());
|
pl.color = Colors.Parse(row["color"].ToString().Trim());
|
||||||
|
|
||||||
pl.money = row["Money"].ToString();
|
pl.money = row["Money"].ToString();
|
||||||
pl.deaths = row["TotalDeaths"].ToString();
|
pl.deaths = row["TotalDeaths"].ToString();
|
||||||
pl.blocks = row["totalBlocks"].ToString();
|
pl.blocks = row["totalBlocks"].ToString();
|
||||||
pl.logins = row["totalLogin"].ToString();
|
pl.logins = row["totalLogin"].ToString();
|
||||||
pl.kicks = row["totalKicked"].ToString();
|
pl.kicks = row["totalKicked"].ToString();
|
||||||
}
|
return pl;
|
||||||
}
|
}
|
||||||
return pl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string FindOfflineName(string name) {
|
public static string FindOfflineName(string name) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user